File size: 2,846 Bytes
d21bdd3 | 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | from llmConnect import managerAgent, vectorDBAgent, searchAgent, sqlAgent, answerAgent
from json import loads
def generateAnswer(question:str) -> str:
managerResponse: list= managerAgent(question)
managerResponse.sort(key=lambda x: x['agent'])
#print(managerResponse)
context = ""
agentsResponseCummalative =[{"Question to be answered":question}]
for i in managerResponse:
if i['agent'] == 'vectorDBAgent':
if len(context) == 0:
context = "No context Required"
prompt = f"""
context -> {context}
question -> {i['question']}
"""
agentResponse = vectorDBAgent(prompt)
context += " " + str(agentResponse)
agentsResponseCummalative.append({"agent":"vectorDBAgent","prompt":prompt,"answer":agentResponse})
elif i['agent'] == 'searchAgent':
prompt = f"""
context -> {context}
question -> {i['question']}
"""
agentResponse = searchAgent(prompt)
context += " " + str(agentResponse)
agentsResponseCummalative.append({"agent":"searchAgent","prompt":prompt,"answer":agentResponse})
elif i['agent'] == 'sqlAgent':
prompt = f"""{i['question']}
"""
agentResponse: dict = sqlAgent(prompt)
context += " " + str(agentResponse)
agentsResponseCummalative.append({"agent":"sqlAgent","prompt":prompt,"answer":agentResponse})
else:
agentsResponseCummalative.append(i)
for i in agentsResponseCummalative:
print(i)
print("\n")
print("."*100)
print("\n")
return answerAgent(str(agentsResponseCummalative))
if __name__ == "__main__":
question = "What is the highest score of MS Dhoni in the IPL"
print(generateAnswer(question))
#if "requestingAgent" in agentResponse.keys():
#if agentResponse["requestingAgent"] == "searchAgent":
#ans = vectorDBAgent(agentResponse["question"])
#newPrompt = f"""
#context -> {agentResponse["question"]} + " " + {ans}
#question -> {question}
#"""
#agentResponse = loads(sqlAgent(newPrompt))
#print(agentResponse)
#if "requestingAgent" in agentResponse.keys():
#if agentResponse["requestingAgent"] == "searchAgent":
#ans = vectorDBAgent(agentResponse["question"])
#newPrompt = f"""
#context -> {agentResponse["question"]} + " " + {ans}
#question -> {question}
#"""
#agentResponse = loads(sqlAgent(newPrompt))
#print(agentResponse)
|