Hello,
I hope that the question belongs here, if not, please let me know and I will delete.
I am trying to create an agent that would provide code as output when asked.
I have an agent that I can communicate with, now I am trying to include functions that would produce code.
I have an agent that returns code for me.
However, it often gets error messages about wrong data type, like this:
openai.error.InvalidRequestError: {‘role’: ‘assistant’, ‘content’: ‘Sure, here is the Python code to print “Hello, World!”\n\npython\nprint("Hello, World!")\n\n\nIf you want to run this code and see the output here, please let me know.’} is not of type ‘string’ - ‘messages.2.content’
Hello, yes your question belongs here you can find more information on your error here the article also goes over some common fixes. Here is an example of how a role is created not in a string. Let me know if it helps.
It took a bit of convincing gpt-4 to make it provide your answer, so sorry if a bot didn’t catch the problem for you:
In JSON, strings must be enclosed in double quotes " ". Single quotes ' ' are not valid for enclosing strings in JSON. This could be the reason why your JSON schema validator is throwing an error.
The JSON you provided uses single quotes, which is likely causing the issue. Here’s the corrected version of your JSON:
{
"role": "assistant",
"content": "Sure, here is the Python code to print “Hello, World!”\n\n`python\nprint(\"Hello, World!\")\n`\n\nIf you want to run this code and see the output here, please let me know."
}
Please try replacing the single quotes with double quotes in your JSON and see if the error persists.
Hello, thanks a lot!
I went through the article and other sources.
However, I am still getting this error. I think the problem is not in the “role”, but rather within the “response”. The model tries to return something that is not string, still not sure how to fix it.