LLM / agents.py
anaghanagesh's picture
Update agents.py
93e0707 verified
from llm import generate_response
from pubmed import search_pubmed
from rag import retrieve_context
from whisper_api import transcribe_audio
from molecules import generate_molecules
def run_pipeline(symptoms, audio_path=None):
try:
# Audio transcription
if audio_path:
transcription = transcribe_audio(
audio_path
)
print(
"TRANSCRIBED:",
transcription
)
if not symptoms.strip():
symptoms = transcription
else:
symptoms += (
" " + transcription
)
# Fallback
if not symptoms.strip():
symptoms = "general symptoms"
# PubMed retrieval
pubmed_papers = search_pubmed(
symptoms
)
# REAL RAG retrieval
context = retrieve_context(
symptoms,
pubmed_papers
)
# LLM reasoning
response = generate_response(
symptoms,
context
)
# Drug generation
molecules = generate_molecules(
symptoms
)
return {
"response": response,
"pubmed": [
p["id"]
for p in pubmed_papers
],
"molecules": molecules
}
except Exception as e:
print(
"PIPELINE ERROR:",
e
)
return {
"response":
f"Pipeline Error: {str(e)}",
"pubmed": [],
"molecules": []
}