mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-16 06:03:26 -05:00
[GH-ISSUE #6514] OpenAI-compatible API: content as array causes crash (error 500) #14392
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dguembel-itomig on GitHub (Oct 28, 2024).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/6514
Installation Method
Docker
Environment
Open WebUI Version: v0.3.35
Ollama (if applicable): 0.3.14
Operating System: Ubuntu 22.04.5 LTS
Browser (if applicable): (does not matter here)
Confirmation:
Expected Behavior:
The follwing JSON is a valid request to the OpenAI API, with the `content" being an array. This is valid as per the OpenAI API doc: https://platform.openai.com/docs/api-reference/chat/create and even supported according to ollama: https://github.com/ollama/ollama/blob/main/docs/openai.md ("Supported request fields": "Array of content parts")
{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": [ { "type": "text", "text": "Wer ist Emmanuel Macron" } ] } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }Changing the request to
contentbeing plain text (not an array) as follows returns a valid response from the server:{ "top_p": 1, "frequency_penalty": 0, "messages": [ { "role": "system", "content": "Du bist ein hilfreicher Assistent." }, { "role": "user", "content": "Wer ist Emmanuel Macron" } ], "temperature": 1, "presence_penalty": 0, "stream": false, "model": "llama3.2:latest" }Actual Behavior:
Crash with error 500.
Description
The OpenAI API allows for the "content" element to be either a string/text or an array[1]. If the latter is used, it crashes open-webui.
[1] https://platform.openai.com/docs/api-reference/chat/create
Reproduction Details
Steps to Reproduce:
Send HTTP request to
https://<your-webui-instance>/v1/chat/completionsas detailed before. Observe error 500.Logs and Screenshots
Browser Console Logs:
N/A
Docker Container Logs:
Open-WebUI docker container log entry:
INFO: 172.19.0.1:49182 - "POST /ollama/v1/chat/completions HTTP/1.0" 500 Internal Server ErrorOllama docker image logs show nothing, request seems not to reach it.
Screenshots/Screen Recordings (if applicable):
N/A
Additional Information
Happy to provide whatever might be desired, but I think the issue is clearly described :)
@tjbck commented on GitHub (Oct 28, 2024):
PR welcome!
@dguembel-itomig commented on GitHub (Oct 29, 2024):
I had a look at the code. I think all is missing would be
In Line 108 of
/backend/open_webui/utils/payload.pyThat should ensure the code is always working with a list even if the
contenthas only one element (one-element list).Does that sound about right?-)
@tjbck commented on GitHub (Nov 3, 2024):
Fixed on dev!