Text Generation
llama-cpp-python
GGUF
English
rag
healthcare
clinical-decision-support
medical
merck-manual
retrieval-augmented-generation
mistral
Instructions to use jeremygracey-ai/FetchMerck_AI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use jeremygracey-ai/FetchMerck_AI with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="jeremygracey-ai/FetchMerck_AI", filename="mistral-7b-instruct-v0.1.Q4_K_M.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- llama-cpp-python
How to use jeremygracey-ai/FetchMerck_AI with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="jeremygracey-ai/FetchMerck_AI", filename="mistral-7b-instruct-v0.1.Q4_K_M.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use jeremygracey-ai/FetchMerck_AI with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M # Run inference directly in the terminal: llama-cli -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M # Run inference directly in the terminal: llama-cli -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf jeremygracey-ai/FetchMerck_AI:Q4_K_M
Use Docker
docker model run hf.co/jeremygracey-ai/FetchMerck_AI:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use jeremygracey-ai/FetchMerck_AI with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jeremygracey-ai/FetchMerck_AI" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jeremygracey-ai/FetchMerck_AI", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/jeremygracey-ai/FetchMerck_AI:Q4_K_M
- Ollama
How to use jeremygracey-ai/FetchMerck_AI with Ollama:
ollama run hf.co/jeremygracey-ai/FetchMerck_AI:Q4_K_M
- Unsloth Studio new
How to use jeremygracey-ai/FetchMerck_AI with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for jeremygracey-ai/FetchMerck_AI to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for jeremygracey-ai/FetchMerck_AI to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for jeremygracey-ai/FetchMerck_AI to start chatting
- Docker Model Runner
How to use jeremygracey-ai/FetchMerck_AI with Docker Model Runner:
docker model run hf.co/jeremygracey-ai/FetchMerck_AI:Q4_K_M
- Lemonade
How to use jeremygracey-ai/FetchMerck_AI with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull jeremygracey-ai/FetchMerck_AI:Q4_K_M
Run and chat with the model
lemonade run user.FetchMerck_AI-Q4_K_M
List all available models
lemonade list
Initial upload of app_logic.py
Browse files- app_logic.py +54 -0
app_logic.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from llama_cpp import Llama
|
| 3 |
+
from langchain_community.vectorstores import Chroma
|
| 4 |
+
from langchain_community.embeddings.sentence_transformer import SentenceTransformerEmbeddings
|
| 5 |
+
|
| 6 |
+
def load_embeddings():
|
| 7 |
+
"""Initializes and returns the sentence transformer embedding model."""
|
| 8 |
+
return SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
|
| 9 |
+
|
| 10 |
+
def initialize_vector_db(persist_directory):
|
| 11 |
+
"""Loads the existing Chroma database and returns a retriever object."""
|
| 12 |
+
embedding_function = load_embeddings()
|
| 13 |
+
db = Chroma(persist_directory=persist_directory, embedding_function=embedding_function)
|
| 14 |
+
return db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|
| 15 |
+
|
| 16 |
+
def load_llm_model(model_path):
|
| 17 |
+
"""Initializes and returns the Llama LLM object."""
|
| 18 |
+
return Llama(
|
| 19 |
+
model_path=model_path,
|
| 20 |
+
n_ctx=2048,
|
| 21 |
+
n_threads=4,
|
| 22 |
+
n_gpu_layers=-1
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
def get_rag_response(query, llm, retriever):
|
| 26 |
+
"""Encapsulates retrieval and generation logic to provide a grounded response."""
|
| 27 |
+
# 1. Retrieve relevant context
|
| 28 |
+
relevant_docs = retriever.get_relevant_documents(query)
|
| 29 |
+
context = ". ".join([doc.page_content for doc in relevant_docs])
|
| 30 |
+
|
| 31 |
+
# 2. Define prompt templates
|
| 32 |
+
system_message = """[INST] You are a helpful medical assistant that answers questions based on the provided context from the Merck Manual of Diagnosis and Therapy.
|
| 33 |
+
Your responses should be accurate, well-structured, and based strictly on the provided context. [/INST]"""
|
| 34 |
+
|
| 35 |
+
user_message = f"""Context:
|
| 36 |
+
{context}
|
| 37 |
+
|
| 38 |
+
Question:
|
| 39 |
+
{query}
|
| 40 |
+
|
| 41 |
+
Please provide a detailed and accurate answer based on the context above. [/INST]"""
|
| 42 |
+
|
| 43 |
+
full_prompt = f"{system_message}\n{user_message}"
|
| 44 |
+
|
| 45 |
+
# 3. Generate response
|
| 46 |
+
output = llm(
|
| 47 |
+
prompt=full_prompt,
|
| 48 |
+
max_tokens=512,
|
| 49 |
+
temperature=0,
|
| 50 |
+
top_p=0.95,
|
| 51 |
+
top_k=50
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
return output['choices'][0]['text'].strip()
|