Hello
I’m trying to implement tool calling for my ReAct agent. I want it to be able to get the response from the tool and then make descision on whether to call another tool or provide an output. I have the code for claude but can’t seem to implement it using openAI.
PS: I’m using the “gpt-4-turbo” model.
The code for claude:
# Generate Chat completion
messages = []
messages.append({'role': 'user', 'content': user_prompt})
messages.append(chat_completion.choices[0].message)
tool_calls = chat_completion.choices[0].message.tool_calls
if tool_calls:
for tool_call in tool_calls:
tool_call_id = tool_call.id
tool_function_name = tool_call.function.name
tool_function_args = eval(tool_call.function.arguments)
# Execute the tool function and get result
messages.append({
"role": "tool",
"tool_call_id": tool_call_id,
"name": tool_function_name,
"content": str(result)
})
# Generate a new chat completion