Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

400 'function' is not allowed role. The allowed roles are ['developer', 'system', 'user', 'assistant', 'tool'] #493

Open
jonwi-semler opened this issue Feb 18, 2025 · 4 comments

Comments

@jonwi-semler
Copy link

Started to receive this error every now and then, when I have been using the chat a bit. Cant seem to find a consistent trigger for it, so it just happens every now and then.

400 'function' is not allowed role. The allowed roles are ['developer', 'system', 'user', 'assistant', 'tool']

Cant seem to find a proper solution for it. Can anybody point me in the right direction?

Best Regards,

Jonathan

@davidxw
Copy link
Member

davidxw commented Feb 18, 2025

Hi @jonwi-semler, are you getting this error when trying a general chat, or are you using the Extensions feature?

Can you also let us know if you see this error just in the console output, or are you getting a UI error message?

@olafwrieden
Copy link
Collaborator

In later API versions (i.e. 2024-10-21) and for the newer o-series reasoning models, the body payload is slightly different. This is why Azure Chat doesn't yet officially or fully support reasoning models. More specifically, the role: "function" (which denotes a function call in the messages array passed as context or tool to the model) has been deprecated in favour for role: "tool" (check the docs here). Therefore, when a request to the o-series model is made, the role "function" is not available and throws the error you see.

Documentation

You can try to search for "function" (with quotation marks) throughout the project and replace those instances with "tool". Here is one of those example from the /src/features/chat-page/chat-services/chat-api/open-ai-stream.ts file... there are more instances:

await CreateChatMessage({
  name: functionCall.name,
  content: functionCall.arguments,
  role: "function", // <== try replacing this with "tool" when using supported o-series models
  chatThreadId: chatThread.id,
});

I haven't tested it but perhaps that gets you started.

@jonwi-semler
Copy link
Author

Hi @jonwi-semler, are you getting this error when trying a general chat, or are you using the Extensions feature?

Can you also let us know if you see this error just in the console output, or are you getting a UI error message?

Hi David,

Its when using an Extension feature and it shows as a UI notification.

@jonwi-semler
Copy link
Author

In later API versions (i.e. 2024-10-21) and for the newer o-series reasoning models, the body payload is slightly different. This is why Azure Chat doesn't yet officially or fully support reasoning models. More specifically, the role: "function" (which denotes a function call in the messages array passed as context or tool to the model) has been deprecated in favour for role: "tool" (check the docs here). Therefore, when a request to the o-series model is made, the role "function" is not available and throws the error you see.

Documentation

You can try to search for "function" (with quotation marks) throughout the project and replace those instances with "tool". Here is one of those example from the /src/features/chat-page/chat-services/chat-api/open-ai-stream.ts file... there are more instances:

await CreateChatMessage({
name: functionCall.name,
content: functionCall.arguments,
role: "function", // <== try replacing this with "tool" when using supported o-series models
chatThreadId: chatThread.id,
});
I haven't tested it but perhaps that gets you started.

Hi Olaf,

I have actually already tried that and did'nt do a difference.
Will try to test out some different things, to see if i can make it work tho.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants