I use a json format instead of openaiobject, but now i got:
openai.BadRequestError: Error code: 400 - {‘error’: {‘message’: “Additional properties are not allowed (‘arguments’ was unexpected) - ‘messages.2’”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}
I trying to make work this deprecated code:
sample_response2 = openai.openai_object.OpenAIObject()
sample_response2["role"] = "assistant"
sample_response2["content"] = None
sample_response2["function_call"] = {
"name": "story_meta_data",
"arguments": json.dumps(
{
"title": title,
"story_text": story,
"word_count": 153,
"top_5_words": [
{"word": "magnificent", "definition":"very good, beautiful, or deserving to be admired", "sample_use":["This is a magnificent story.", "What a magnificent oak tree!"]},
{"word": "Tyrannosaurus Rex", "definition":"the largest species (= type) of tyrannosaurus (= a very large, meat-eating dinosaur with large, powerful back legs, small front legs and a long tail)", "sample_use":["Tyrannosaurus Rex is a large dinosaur.", "I'm scared of the Tyrannosaurus Rex."]},
{"word": "Brachiosaurus", "definition":"a very large plant-eating dinosaur with four legs, a very long neck and tail, and a small head. Its front legs were longer than its back legs.", "sample_use":["The Brachiosaurus is a vegetarian.", "The Brachiosaurus has long front legs."]},
{"word": "destruction", "definition":" the act of destroying something, or the fact of being destroyed", "sample_use":["The fire caused massive distruction.", "The war resulted in the distruction of cities."]},
{"word": "dinosaurs", "definition":"a type of reptile that became extinct about 65,000,000 years ago. There were many different types of dinosaur, some of which were extremely large", "sample_use":["Children love dinosaurs.", "Dinosaurs became extinct millions of years ago."]}
]
},
indent=2,
ensure_ascii=False,
),
}
messages = [
{"role": "system", "content": "You are a story writer, please write a 200 word children's story about the theme specified and then extract the relevant data to use as arguments to pass into the given function provided" },
{'role': 'user', 'content': "Please produce a story about the following theme:\"\"\""+theme2+"\"\"\""}]
messages2 = [
{"role": "system", "content": "You are a story writer, please write a 200 word children's story about the theme specified and then extract the relevant data to use as arguments to pass into the given function provided" },
{'role': 'user', 'content': "Please produce a story about the following theme:\"\"\""+theme1+"\"\"\""},
sample_response2,
{'role': 'user', 'content': "Please produce a story about the following theme:\"\"\""+theme2+"\"\"\""}]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=messages2,
functions=[function],
function_call={"name": "story_meta_data"}, # this forces calling `function`
)
#print(json.loads(json.dumps((response)))["choices"][0]["message"]["function_call"]["arguments"])
content = response["choices"][0]["message"]["function_call"]["arguments"]
content_json = json.loads(content)
print(content)