OpenAI-API-dotnet icon indicating copy to clipboard operation
OpenAI-API-dotnet copied to clipboard

Unity - 'role' is a required property - 'messages.0'

Open ecsplendid opened this issue 1 year ago • 2 comments

Sender:System.Threading.Tasks.Task`1[System.Threading.Tasks.VoidTaskResult] Exception:System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Error at chat/completions (https://api.openai.com/v1/chat/completions) with HTTP status code: BadRequest. Content: {
"error": {
"message": "'role' is a required property - 'messages.0'",
"type": "invalid_request_error",
"param": null,
"code": null
}
}

Get this error when running on Unity with the ILCPP transcompilation. Runs OK in the editor. Assume its related to JSON packages. Anyone else seen this?

ecsplendid avatar Jul 05 '23 10:07 ecsplendid

Chat models (GPT3.5 and GPT34) need roles to be passed, which are

  • "system" for general instructions passed to the model ("You are a helpful bot that talks in rhymes")
  • "user" for messages coming from a human ("What time it is?")
  • "assistant" for messages coming from a machine, or the model itself ("As a model, i have no access to the current time")

This allows you to pass history of communication more easily. I usually do not utilize the "system" message - i generate only one "user" with a prompt i manually filled with history and context.

SOLUTION: just add the role "user" to the message that you pass to the chat/completion method

antonioKriz avatar Sep 26 '23 08:09 antonioKriz

https://github.com/RageAgainstThePixel/com.openai.unity

StephenHodgson avatar Nov 10 '23 15:11 StephenHodgson