Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -111,20 +111,45 @@ If the user is engaging in discussion, try to steer them towards getting in touc
|
|
| 111 |
return system_prompt
|
| 112 |
|
| 113 |
def chat(self, message, history):
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
done = False
|
|
|
|
|
|
|
| 116 |
while not done:
|
| 117 |
-
response = self.groq.chat.completions.create(
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
results = self.handle_tool_call(tool_calls)
|
| 122 |
-
|
|
|
|
| 123 |
messages.extend(results)
|
|
|
|
| 124 |
else:
|
|
|
|
|
|
|
| 125 |
done = True
|
| 126 |
-
return response.choices[0].message.content
|
| 127 |
|
|
|
|
|
|
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
me = Me()
|
|
|
|
| 111 |
return system_prompt
|
| 112 |
|
| 113 |
def chat(self, message, history):
|
| 114 |
+
history_clean = normalize_history(history)
|
| 115 |
+
|
| 116 |
+
messages = [{"role": "system", "content": self.system_prompt()}]
|
| 117 |
+
messages.extend(history_clean)
|
| 118 |
+
messages.append({"role": "user", "content": message})
|
| 119 |
+
|
| 120 |
done = False
|
| 121 |
+
final_response = ""
|
| 122 |
+
|
| 123 |
while not done:
|
| 124 |
+
response = self.groq.chat.completions.create(
|
| 125 |
+
model="openai/gpt-oss-120b",
|
| 126 |
+
messages=messages,
|
| 127 |
+
tools=tools,
|
| 128 |
+
tool_choice="auto"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
msg = response.choices[0].message
|
| 132 |
+
|
| 133 |
+
# Tool call?
|
| 134 |
+
if msg.finish_reason == "tool_calls":
|
| 135 |
+
tool_calls = msg.tool_calls
|
| 136 |
+
|
| 137 |
+
# model says: "use tool"
|
| 138 |
+
messages.append({"role": "assistant", "content": msg.content or ""})
|
| 139 |
+
|
| 140 |
+
# run python functions
|
| 141 |
results = self.handle_tool_call(tool_calls)
|
| 142 |
+
|
| 143 |
+
# return results to model
|
| 144 |
messages.extend(results)
|
| 145 |
+
|
| 146 |
else:
|
| 147 |
+
# normal final answer
|
| 148 |
+
final_response = msg.content or ""
|
| 149 |
done = True
|
|
|
|
| 150 |
|
| 151 |
+
return final_response
|
| 152 |
+
|
| 153 |
|
| 154 |
if __name__ == "__main__":
|
| 155 |
me = Me()
|