Spaces:
Sleeping
Sleeping
File size: 883 Bytes
80f71e5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# src/alternatives_generator.py
from langchain.chains import RetrievalQA
from custom_llm import HuggingFaceLLMWrapper
from rag_application import load_embeddings_db
def setup_alternatives_generator():
db = load_embeddings_db()
llm = HuggingFaceLLMWrapper(model_name="meta-llama/Llama-3.2-3B", device='cuda') # Change to 'cpu' if necessary
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=db.as_retriever()
)
def suggest_alternatives(medication):
query = f"Suggest alternative medications to {medication}."
response = qa.run(query)
return response
return suggest_alternatives
if __name__ == "__main__":
generator = setup_alternatives_generator()
medication = "Paracetamol"
alternatives = generator(medication)
print(f"Alternatives to {medication}: {alternatives}") |