You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm making a call to openai and getting an error on this line:
if message.get("content", None) is not None:
To reproduce
It happens when I make call that combines multiple tools usage.
This is from open-ai documentation:
response = client.chat.completions.create(
model="gpt-3.5-turbo-0125",
messages=messages,
tools=tools,
tool_choice="auto", # auto is default, but we'll be explicit
)
response_message = response.choices[0].message
tool_calls = response_message.tool_calls
# Step 2: check if the model wanted to call a function
if tool_calls:
# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors
available_functions = {
"get_current_weather": get_current_weather,
} # only one function in this example, but you can have multiple
-> -> messages.append(response_message) # extend conversation with assistant's reply
# Step 4: send the info for each function call and function response to the model
for tool_call in tool_calls:
function_name = tool_call.function.name
As you can see you append the response message to the message array (-> -> location)
In your code you have:
def_filter_image_data(messages: List[dict]):
"""https://platform.openai.com/docs/guides/vision?lang=python The messages array remains the same, but the 'image_url' is removed from the 'content' array. It should only be removed if the value starts with 'data:image/jpeg;base64,' """output_messages=copy.deepcopy(messages)
formessageinoutput_messages:
ifmessage.get("content", None) isnotNone:
content=message["content"]
forindex, iteminenumerate(content):
ifisinstance(item, dict) anditem.get("image_url", None) isnotNone:
url=item["image_url"]["url"]
ifurl.startswith("data:image/"):
delcontent[index]["image_url"]
returnoutput_messages
And since the appended message if of type ChatCompletionMessage you get the error
when trying to access the content value of that message.
SDK and container versions
No response
Additional information
No response
Are you interested to contribute a fix for this bug?
No
The text was updated successfully, but these errors were encountered:
Describe the bug
I'm making a call to openai and getting an error on this line:
if message.get("content", None) is not None:
To reproduce
It happens when I make call that combines multiple tools usage.
This is from open-ai documentation:
As you can see you append the response message to the message array (-> -> location)
In your code you have:
And since the appended message if of type ChatCompletionMessage you get the error
when trying to access the content value of that message.
SDK and container versions
No response
Additional information
No response
Are you interested to contribute a fix for this bug?
No
The text was updated successfully, but these errors were encountered: