Views
No views yet

1# GPU llama-cpp-python
2!CMAKE_ARGS="-DLLAMA_CUBLAS=on" FORCE_CMAKE=1 pip install llama-cpp-python --force-reinstall --upgrade --no-cache-dir --verbose1%%capture
2!pip install huggingface-hub hf-transfer1import os
2os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
3!huggingface-cli download \
4 ruslanmv/Medical-Llama3-8B-GGUF \
5 medical-llama3-8b.Q5_K_M.gguf \
6 --local-dir . \
7 --local-dir-use-symlinks False
8
9MODEL_PATH="/content/medical-llama3-8b.Q5_K_M.gguf"1from llama_cpp import Llama
2import json
3B_INST, E_INST = "<s>[INST]", "[/INST]"
4B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
5DEFAULT_SYSTEM_PROMPT = """\
6You are an AI Medical Chatbot Assistant, I'm equipped with a wealth of medical knowledge derived from extensive datasets. I aim to provide comprehensive and informative responses to your inquiries. However, please note that while I strive for accuracy, my responses should not replace professional medical advice and short answers.
7If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information."""
8SYSTEM_PROMPT = B_SYS + DEFAULT_SYSTEM_PROMPT + E_SYS
9def create_prompt(user_query):
10 instruction = f"User asks: {user_query}\n"
11 prompt = B_INST + SYSTEM_PROMPT + instruction + E_INST
12 return prompt.strip()
13
14
15user_query = "I'm a 35-year-old male experiencing symptoms like fatigue, increased sensitivity to cold, and dry, itchy skin. Could these be indicative of hypothyroidism?"
16prompt = create_prompt(user_query)
17print(prompt)
18
19llm = Llama(model_path=MODEL_PATH, n_gpu_layers=-1)
20result = llm(
21 prompt=prompt,
22 max_tokens=100,
23 echo=False
24)
25print(result['choices'][0]['text'])1Hi, thank you for your query.
2Hypothyroidism is characterized by fatigue, sensitivity to cold, weight gain, depression, hair loss and mental dullness. I would suggest that you get a complete blood count with thyroid profile including TSH (thyroid stimulating hormone), free thyroxine level, and anti-thyroglobulin antibodies. These tests will help in establishing the diagnosis of hypothyroidism.
3If there is no family history of autoimmune disorders, then it might be due