Reda-b commited on
Commit
a5c7544
·
verified ·
1 Parent(s): 40e598d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -132,7 +132,7 @@ If the user is engaging in discussion, try to steer them towards getting in touc
132
 
133
  done = False
134
  final_response = ""
135
-
136
  while not done:
137
  response = self.groq.chat.completions.create(
138
  model="openai/gpt-oss-120b",
@@ -140,30 +140,37 @@ If the user is engaging in discussion, try to steer them towards getting in touc
140
  tools=tools,
141
  tool_choice="auto"
142
  )
143
-
144
- msg = response.choices[0].message
145
-
146
- # Tool call?
147
- if msg.finish_reason == "tool_calls":
 
148
  tool_calls = msg.tool_calls
149
-
150
- # model says: "use tool"
151
- messages.append({"role": "assistant", "content": msg.content or ""})
152
-
153
- # run python functions
 
 
 
 
154
  results = self.handle_tool_call(tool_calls)
155
-
156
- # return results to model
157
- messages.extend(results)
158
-
 
159
  else:
160
- # normal final answer
161
  final_response = msg.content or ""
162
  done = True
163
-
164
  return final_response
165
 
166
 
 
167
  if __name__ == "__main__":
168
  me = Me()
169
  gr.ChatInterface(me.chat, type="messages").launch()
 
132
 
133
  done = False
134
  final_response = ""
135
+
136
  while not done:
137
  response = self.groq.chat.completions.create(
138
  model="openai/gpt-oss-120b",
 
140
  tools=tools,
141
  tool_choice="auto"
142
  )
143
+
144
+ choice = response.choices[0]
145
+ msg = choice.message
146
+
147
+ # TOOL CALL?
148
+ if choice.finish_reason == "tool_calls":
149
  tool_calls = msg.tool_calls
150
+
151
+ # Add assistant call message (even if empty)
152
+ messages.append({
153
+ "role": "assistant",
154
+ "content": msg.content or "",
155
+ "tool_calls": [tc.model_dump() for tc in tool_calls]
156
+ })
157
+
158
+ # Execute tools
159
  results = self.handle_tool_call(tool_calls)
160
+
161
+ # Return tool results back to the model
162
+ for r in results:
163
+ messages.append(r)
164
+
165
  else:
166
+ # FINAL MESSAGE
167
  final_response = msg.content or ""
168
  done = True
169
+
170
  return final_response
171
 
172
 
173
+
174
  if __name__ == "__main__":
175
  me = Me()
176
  gr.ChatInterface(me.chat, type="messages").launch()