fixed upenai
This commit is contained in:
@@ -16,8 +16,7 @@ class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
response = self.client.chat.completions.create(
|
||||
model=self.model,
|
||||
messages=[{"role": "system", "content": self.system_prompt}] + messages,
|
||||
functions=self.functions,
|
||||
function_call="auto",
|
||||
tools=self.functions,
|
||||
max_tokens=self.max_tokens
|
||||
)
|
||||
return response
|
||||
@@ -30,26 +29,35 @@ class ChatGPTTelegramInferenceBot(BaseTelegramInferenceBot):
|
||||
messages = self.conversation_history[user_id]
|
||||
|
||||
response = self.get_chat_response(messages)
|
||||
assistant_message = response.choices[0].message
|
||||
|
||||
tool_calls = []
|
||||
if hasattr(assistant_message, 'function_call') and assistant_message.function_call is not None:
|
||||
tool_calls.append(assistant_message.function_call)
|
||||
assistant_message = {}
|
||||
|
||||
for message_part in response.choices:
|
||||
if message_part.finish_reason == "function_call":
|
||||
tool_calls.append(message_part.message.function_call)
|
||||
else:
|
||||
assistant_message = response.choices[0].message
|
||||
|
||||
tool_use_count = 0
|
||||
while len(tool_calls) > 0 and tool_use_count < 50:
|
||||
tool_use_results = []
|
||||
for tool_call in tool_calls:
|
||||
tool_response = self.call_tool(tool_call)
|
||||
|
||||
while len(tool_calls) > 0:
|
||||
tool_call = tool_calls.pop(0)
|
||||
tool_response = self.call_tool(tool_call.name, tool_call.arguments)
|
||||
tool_use_results.append({"role": "function", "name": tool_call.name, "content": json.dumps(tool_response)})
|
||||
|
||||
messages.extend(tool_use_results)
|
||||
|
||||
response = self.get_chat_response(messages)
|
||||
assistant_message = response.choices[0].message
|
||||
messages.append({"role": "assistant", "content": assistant_message.content})
|
||||
tool_calls = []
|
||||
if hasattr(assistant_message, 'function_call') and assistant_message.function_call is not None:
|
||||
tool_calls.append(assistant_message.function_call)
|
||||
response = self.get_chat_response(messages)
|
||||
|
||||
for message_part in response.choices:
|
||||
if message_part.finish_reason == "function_call":
|
||||
tool_calls.append(message_part.message.function_call)
|
||||
else:
|
||||
assistant_message = response.choices[0].message
|
||||
messages.append({"role": "assistant", "content": assistant_message.content})
|
||||
|
||||
tool_use_count += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user