zohaibterminator commited on
Commit
fca6da0
·
verified ·
1 Parent(s): d757347

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -36,9 +36,8 @@ search = TavilySearchResults(
36
  max_results=2,
37
  )
38
  tools = [search]
39
- memory = MemorySaver()
40
 
41
- agent_executor = create_react_agent(llm, tools, checkpointer=memory)
42
 
43
  # Initialize the wav2vec2 model for Urdu speech-to-text
44
  pipe = pipeline("automatic-speech-recognition", model="kingabzpro/wav2vec2-large-xls-r-300m-Urdu")
@@ -69,6 +68,7 @@ def translate(target, text):
69
  res = response.json()
70
  return res[0]["translations"][0]["text"]
71
 
 
72
  def infer(user_input: str):
73
  '''
74
  Returns the translated response from the LLM in response to a user query.
@@ -78,7 +78,7 @@ def infer(user_input: str):
78
  user_input (string): User query.
79
 
80
  Returns:
81
- JSON Response (Dictionary): Returns a translated response from the LLM.
82
  '''
83
 
84
  user_input = translate("en", user_input) # translate user query to english
@@ -87,17 +87,20 @@ def infer(user_input: str):
87
  [
88
  (
89
  "system",
90
- "You're a compassionate AI virtual Assistant"
91
  ),
92
  ("human", "{user_input}")
93
  ]
94
  )
95
 
 
96
 
 
 
 
97
 
98
- response = agent_executor.invoke( # invoke the chain by giving the user input and the chat history
99
- {"messages": [HumanMessage(content=user_input)]},
100
- config={"configurable": {"thread_id":user_id}}
101
  )
102
 
103
  res = translate("ur", response["messages"][-1].content) # translate the response to Urdu
 
36
  max_results=2,
37
  )
38
  tools = [search]
 
39
 
40
+ agent_executor = create_react_agent(llm, tools)
41
 
42
  # Initialize the wav2vec2 model for Urdu speech-to-text
43
  pipe = pipeline("automatic-speech-recognition", model="kingabzpro/wav2vec2-large-xls-r-300m-Urdu")
 
68
  res = response.json()
69
  return res[0]["translations"][0]["text"]
70
 
71
+
72
  def infer(user_input: str):
73
  '''
74
  Returns the translated response from the LLM in response to a user query.
 
78
  user_input (string): User query.
79
 
80
  Returns:
81
+ res (string): Returns a translated response from the LLM.
82
  '''
83
 
84
  user_input = translate("en", user_input) # translate user query to english
 
87
  [
88
  (
89
  "system",
90
+ "You are a compassionate and friendly AI virtual assistant. You will provide helpful answers to user queries using the provided tool to ensure the accuracy and relevance of your responses. Please validate the information before providing answers that are not verified."
91
  ),
92
  ("human", "{user_input}")
93
  ]
94
  )
95
 
96
+ runnable = prompt | agent_executor # define a chain
97
 
98
+ conversation = RunnableSequence( # wrap the chain along with chat history and user input
99
+ runnable,
100
+ )
101
 
102
+ response = conversation.invoke( # invoke the chain by giving the user input and the chat history
103
+ {"user_input": user_input},
 
104
  )
105
 
106
  res = translate("ur", response["messages"][-1].content) # translate the response to Urdu