ParsedChatCompletionMessage is not JSON serializable

I’m using client.beta.chat.completions.parse from openAI. The response can either be a parsed type, or tool_calls. What I do to continue the conversation with the AI is simply to extend my conversation history like so:

conversation_history.append(completions.choices[0].message)

the problem with this approach is that my conversation_history, which was so far a nice python dictionary, is now a mix of types and cannot be serialized to JSON easily.

wrote the answer here: openAI API · GitHub

basically you need some code to handle it, but since everything’s a BaseModel you can just dump right in!