mou3az commited on
Commit
bc17c1b
·
verified ·
1 Parent(s): 27307fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -46,22 +46,28 @@ def handle_message(message: str, mode: str):
46
  return "Select a valid mode."
47
 
48
  def chat_message(message: str):
 
49
  global messages
50
  prompt = HumanMessage(content=message)
51
  messages.append(prompt)
 
52
  response = chat_model.invoke(messages)
53
  messages.append(response.content)
 
54
  if len(messages) >= 6:
55
  messages = messages[-6:]
 
56
  return f"IT-Assistant: {response.content}"
57
 
58
  def web_search(message: str):
 
59
  global messages
60
  similar_docs = db.similarity_search(message, k=3)
61
  if similar_docs:
62
  source_knowledge = "\n".join([x.page_content for x in similar_docs])
63
  else:
64
  source_knowledge = ""
 
65
  augmented_prompt = f"""
66
  If the answer to the next query is not contained in the Web Search, say 'No Answer Is Available' and then just give guidance for the query.
67
 
@@ -70,40 +76,37 @@ def web_search(message: str):
70
  Web Search:
71
  {source_knowledge}
72
  """
 
73
  prompt = HumanMessage(content=augmented_prompt)
74
  messages.append(prompt)
 
75
  response = chat_model.invoke(messages)
76
  messages.append(response.content)
 
77
  if len(messages) >= 6:
78
  messages = messages[-6:]
 
79
  return f"IT-Assistant: {response.content}"
80
 
81
  def chart_generator(message: str):
82
- # Construct the full chart URL
83
- chart_url = f"https://quickchart.io/natural/{message}"
84
 
85
- # Send a GET request to the chart URL
86
  response = requests.get(chart_url)
87
 
88
- # Check if the request was successful (status code 200)
89
  if response.status_code == 200:
90
- # Add a description to the message
91
  message_with_description = f"Describe and analyse the content of this chart: {message}"
92
 
93
- # Create a HumanMessage object with the message including the description
94
  prompt = HumanMessage(content=message_with_description)
95
  messages.append(prompt)
96
 
97
- # Invoke the chat model with the updated messages
98
  response = chat_model.invoke(messages)
99
  messages.append(response.content)
 
100
  if len(messages) >= 6:
101
  messages = messages[-6:]
102
 
103
- # Display the chart image with a smaller size
104
  display(Image(url=chart_url, width=500, height=300))
105
 
106
- # Return the message and response
107
  return f"IT-Assistant: {response.content}"
108
  else:
109
  return f"Can't generate this image. Please provide valid chart details."
 
46
  return "Select a valid mode."
47
 
48
  def chat_message(message: str):
49
+
50
  global messages
51
  prompt = HumanMessage(content=message)
52
  messages.append(prompt)
53
+
54
  response = chat_model.invoke(messages)
55
  messages.append(response.content)
56
+
57
  if len(messages) >= 6:
58
  messages = messages[-6:]
59
+
60
  return f"IT-Assistant: {response.content}"
61
 
62
  def web_search(message: str):
63
+
64
  global messages
65
  similar_docs = db.similarity_search(message, k=3)
66
  if similar_docs:
67
  source_knowledge = "\n".join([x.page_content for x in similar_docs])
68
  else:
69
  source_knowledge = ""
70
+
71
  augmented_prompt = f"""
72
  If the answer to the next query is not contained in the Web Search, say 'No Answer Is Available' and then just give guidance for the query.
73
 
 
76
  Web Search:
77
  {source_knowledge}
78
  """
79
+
80
  prompt = HumanMessage(content=augmented_prompt)
81
  messages.append(prompt)
82
+
83
  response = chat_model.invoke(messages)
84
  messages.append(response.content)
85
+
86
  if len(messages) >= 6:
87
  messages = messages[-6:]
88
+
89
  return f"IT-Assistant: {response.content}"
90
 
91
  def chart_generator(message: str):
 
 
92
 
93
+ chart_url = f"https://quickchart.io/natural/{message}"
94
  response = requests.get(chart_url)
95
 
 
96
  if response.status_code == 200:
 
97
  message_with_description = f"Describe and analyse the content of this chart: {message}"
98
 
 
99
  prompt = HumanMessage(content=message_with_description)
100
  messages.append(prompt)
101
 
 
102
  response = chat_model.invoke(messages)
103
  messages.append(response.content)
104
+
105
  if len(messages) >= 6:
106
  messages = messages[-6:]
107
 
 
108
  display(Image(url=chart_url, width=500, height=300))
109
 
 
110
  return f"IT-Assistant: {response.content}"
111
  else:
112
  return f"Can't generate this image. Please provide valid chart details."