alenkvakic / angular-chatgpt

An interactive Angular application that serves as a starting point for Angular developers looking to integrate with OpenAI's ChatGPT API
MIT License
8 stars 4 forks source link

Role "error" is not accepted by OpenAI, etc. #1

Open michaelwechner opened 1 month ago

michaelwechner commented 1 month ago

When an error occurs, then a message is pushed using the role "error".

When the user then sends another message, then for example OpenAI will throw an error, because it does not know the role "error":

Object { message: "Invalid value: 'error'. Supported values are: 'system', 'assistant', 'user', 'function', and 'tool'.", type: "invalid_request_error", param: "messages[2].role", … }

I think error messages should be handled differently in the conversation history, such that this problem does not occur.

What do you think?

michaelwechner commented 1 month ago

I have implemented a quick fix inside src/app/chat-gpt.service.ts ... before sending I replace the role "error" by "assistant"

body['messages'] = this.replaceRoleError(messages);

+

alenkvakic commented 3 weeks ago

Thanks for your input! I created this project back then when ChatGPT was quite new so I assume some things have changed in their API and the request/responses. As soon as I have time I will update this project to the latest angular version (with the new control flow syntax as well), and then will take a look at how its handled today.

Please feel free to create pull requests if you have fixes in the meantime (like this), as I can add those quicker.