Update app.py
Browse files
app.py
CHANGED
|
@@ -124,24 +124,24 @@ If the user is engaging in discussion, try to steer them towards getting in touc
|
|
| 124 |
messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
|
| 125 |
done = False
|
| 126 |
while not done:
|
| 127 |
-
#response = self.client.chat.completions.create(model="meta-llama/llama-3.3-8b-instruct:free", messages=messages, tools=tools)
|
| 128 |
try:
|
| 129 |
response = self.openai.chat.completions.create(
|
| 130 |
model="meta-llama/llama-3.3-8b-instruct:free",
|
| 131 |
messages=messages,
|
| 132 |
tools=tools
|
| 133 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
except Exception as e:
|
| 135 |
print(f"Error during OpenAI API call: {e}")
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
message = response.choices[0].message
|
| 139 |
-
tool_calls = message.tool_calls
|
| 140 |
-
results = self.handle_tool_call(tool_calls)
|
| 141 |
-
messages.append(message)
|
| 142 |
-
messages.extend(results)
|
| 143 |
-
else:
|
| 144 |
-
done = True
|
| 145 |
return response.choices[0].message.content
|
| 146 |
|
| 147 |
|
|
|
|
| 124 |
messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
|
| 125 |
done = False
|
| 126 |
while not done:
|
|
|
|
| 127 |
try:
|
| 128 |
response = self.openai.chat.completions.create(
|
| 129 |
model="meta-llama/llama-3.3-8b-instruct:free",
|
| 130 |
messages=messages,
|
| 131 |
tools=tools
|
| 132 |
)
|
| 133 |
+
if response.choices[0].finish_reason == "tool_calls":
|
| 134 |
+
message = response.choices[0].message
|
| 135 |
+
tool_calls = message.tool_calls
|
| 136 |
+
results = self.handle_tool_call(tool_calls)
|
| 137 |
+
messages.append(message)
|
| 138 |
+
messages.extend(results)
|
| 139 |
+
else:
|
| 140 |
+
done = True
|
| 141 |
except Exception as e:
|
| 142 |
print(f"Error during OpenAI API call: {e}")
|
| 143 |
+
return "Sorry, there was an error processing your request. Please check your API key and try again."
|
| 144 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
return response.choices[0].message.content
|
| 146 |
|
| 147 |
|