LohithGummi commited on
Commit
2e01f89
·
verified ·
1 Parent(s): fe0d0d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -18
app.py CHANGED
@@ -121,6 +121,7 @@ sqlite_agent = create_sql_agent(
121
  verbose=True
122
  )
123
  #### Let's convert the sql agent into a tool that our fin agent can use.
 
124
  @tool
125
  def sql_tool(user_input):
126
  """
@@ -210,7 +211,21 @@ client = AzureOpenAI(
210
  api_version=os.environ["AZURE_OPENAI_APIVERSION_mini"]
211
  )
212
 
 
 
213
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  @tool
215
  def rag(user_input: str) -> str:
216
 
@@ -231,25 +246,16 @@ def rag(user_input: str) -> str:
231
  context_for_query = ". ".join(context_list)
232
 
233
  prompt = [
234
- {'role':'system', 'content': qna_system_message},
235
- {'role': 'user', 'content': qna_user_message_template.format(
236
- context=context_for_query,
237
- question=user_input
238
- )
239
- }
240
- ]
241
-
242
- try:
243
- response = client.chat.completions.create(
244
- model="gpt-4o-mini",
245
- messages=prompt
246
  )
 
 
247
 
248
- prediction = response.choices[0].message.content
249
- except Exception as e:
250
- prediction = f'Sorry, I encountered the following error: \n {e}'
251
-
252
- return prediction
253
 
254
 
255
  #=================================== Other TOOLS======================================#
@@ -489,6 +495,11 @@ def fetch_details(email):
489
  connection.close()
490
 
491
  # Function to process user input and generate a chatbot response
 
 
 
 
 
492
  def chatbot_interface():
493
  st.title("E-Commerce Chatbot")
494
 
@@ -532,7 +543,7 @@ def chatbot_interface():
532
 
533
  try:
534
  # Pass the history to the agent
535
- response = agent_executor.invoke({"input": conversation_input})
536
 
537
  # Add the chatbot's response to the history
538
  chatbot_response = response['output']
 
121
  verbose=True
122
  )
123
  #### Let's convert the sql agent into a tool that our fin agent can use.
124
+ @weave.op()
125
  @tool
126
  def sql_tool(user_input):
127
  """
 
211
  api_version=os.environ["AZURE_OPENAI_APIVERSION_mini"]
212
  )
213
 
214
+ @weave.op()
215
+ def get_rag_response(prompt):
216
 
217
+
218
+ try:
219
+ response = client.chat.completions.create(
220
+ model="gpt-4o-mini",
221
+ messages=prompt
222
+ )
223
+
224
+ prediction = response.choices[0].message.content
225
+ except Exception as e:
226
+ prediction = f'Sorry, I encountered the following error: \n {e}'
227
+
228
+
229
  @tool
230
  def rag(user_input: str) -> str:
231
 
 
246
  context_for_query = ". ".join(context_list)
247
 
248
  prompt = [
249
+ {'role':'system', 'content': qna_system_message},
250
+ {'role': 'user', 'content': qna_user_message_template.format(
251
+ context=context_for_query,
252
+ question=user_input
 
 
 
 
 
 
 
 
253
  )
254
+ }
255
+ ]
256
 
257
+
258
+ return get_rag_response(prompt)
 
 
 
259
 
260
 
261
  #=================================== Other TOOLS======================================#
 
495
  connection.close()
496
 
497
  # Function to process user input and generate a chatbot response
498
+ @weave.op()
499
+ def get_response(conversation_input):
500
+ return agent_executor.invoke({"input": conversation_input})
501
+
502
+
503
  def chatbot_interface():
504
  st.title("E-Commerce Chatbot")
505
 
 
543
 
544
  try:
545
  # Pass the history to the agent
546
+ response = get_response(conversation_input)
547
 
548
  # Add the chatbot's response to the history
549
  chatbot_response = response['output']