juanmartip95 commited on
Commit
4efdaca
1 Parent(s): 4865dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -27,6 +27,7 @@ def res(prompt, historial):
27
 
28
  return respuesta, historial
29
 
 
30
  def respond(message, chat_history, history):
31
  response = res(message, history)
32
  bot_message = response[0]
@@ -35,19 +36,30 @@ def respond(message, chat_history, history):
35
 
36
  # Check if the conversation is over
37
  if "vista" in bot_message.lower(): # Check if "vista" is in the bot's response
38
- chat_history.append(("System", "The word 'vista' was found in the bot's response."))
39
  # Get the assistant's last message
40
  last_message = response[1][-1]['content'] # assuming the last message is from the assistant
41
- #chat_history.append(("System", last_message))
42
- # Pass the JSON output to the extract_info function
43
- # info = extract_info(last_message)
44
- # Use the extracted info
45
- #WA(info)
46
- #print(last_message)
 
 
 
 
 
 
 
 
 
47
 
48
  return "", chat_history, response[1]
49
 
50
 
 
 
51
  def WA(history):
52
  sendWA("491771675218",history)
53
  return "✅ Validado"
 
27
 
28
  return respuesta, historial
29
 
30
+
31
  def respond(message, chat_history, history):
32
  response = res(message, history)
33
  bot_message = response[0]
 
36
 
37
  # Check if the conversation is over
38
  if "vista" in bot_message.lower(): # Check if "vista" is in the bot's response
39
+ #chat_history.append(("System", "The word 'vista' was found in the bot's response."))
40
  # Get the assistant's last message
41
  last_message = response[1][-1]['content'] # assuming the last message is from the assistant
42
+
43
+ # Split the last message by "vista."
44
+ parts = last_message.split("vista.")
45
+
46
+ # If there are two parts (text + JSON), process the JSON part
47
+ if len(parts) == 2:
48
+ json_part = parts[1].strip() # Extract the JSON part and remove leading/trailing spaces
49
+ # Now you can pass the JSON output to the extract_info function
50
+ info = extract_info(json_part)
51
+ # Use the extracted info or append it to chat_history, etc.
52
+ chat_history.append(("System", json_part)) # Example: append the extracted JSON to chat history
53
+ # WA(info)
54
+ #print(info) # Example: print the extracted info
55
+
56
+ chat_history.append(("System", parts[0])) # Append the text part to chat history
57
 
58
  return "", chat_history, response[1]
59
 
60
 
61
+
62
+
63
  def WA(history):
64
  sendWA("491771675218",history)
65
  return "✅ Validado"