[PR #4621] [MERGED] feat: Set content-type header in Ollama backend #21525

Closed
opened 2026-04-20 03:34:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/4621
Author: @nthe
Created: 8/15/2024
Status: Merged
Merged: 8/15/2024
Merged by: @tjbck

Base: devHead: main


📝 Commits (3)

  • 13b0e7d Merge pull request #4434 from open-webui/dev
  • f73a60d fix: set content-type header in ollama backend
  • 439cb66 refac: fuzzy search threshold

📊 Changes

2 files changed (+13 additions, -3 deletions)

View changed files

📝 backend/apps/ollama/main.py (+11 -2)
📝 src/lib/components/chat/ModelSelector/Selector.svelte (+2 -1)

📄 Description

Pull Request Checklist

Note to first-time contributors: Please open a discussion post in Discussions and describe your changes before submitting a pull request.

Before submitting, make sure you've checked the following:

  • Target branch: Please verify that the pull request targets the dev branch.
  • Description: Provide a concise description of the changes made in this pull request.
  • Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
  • Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
  • Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
  • Testing: Have you written and run sufficient tests for validating the changes?
  • Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
  • Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
    • BREAKING CHANGE: Significant changes that may affect compatibility
    • build: Changes that affect the build system or external dependencies
    • ci: Changes to our continuous integration processes or workflows
    • chore: Refactor, cleanup, or other non-functional code changes
    • docs: Documentation update or addition
    • feat: Introduces a new feature or enhancement to the codebase
    • fix: Bug fix or error correction
    • i18n: Internationalization or localization changes
    • perf: Performance improvement
    • refactor: Code restructuring for better maintainability, readability, or scalability
    • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
    • test: Adding missing tests or correcting existing tests
    • WIP: Work in progress, a temporary label for incomplete or ongoing work

Changelog Entry

Description

The Ollama backend code doesn't work with custom Ollama compatible APIs made with FastAPI. The issue comes from missing (or incorrect) Content-Type HTTP header, which now defaults to text/plain. Without proper header, the FastAPI (or maybe Pydantic) raises and 422 Unprocessable Entity exception even with valid JSON. This issue affects POST requests only.

Added

  • Set Content-Type: application/json header for POST requests in the Ollama backend code.

Screenshots or Videos

UI and custom Ollama API without header set
The 422 exception get propagated to the UI.
1-no-header-1 Large
1-no-header-2 Large

UI and custom Ollama API with header set
No exceptions raised this time.
2-header-1 Large
2-header-2 Large

UI with Ollama still working
As it should be.
3-ollama Large


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/4621 **Author:** [@nthe](https://github.com/nthe) **Created:** 8/15/2024 **Status:** ✅ Merged **Merged:** 8/15/2024 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `main` --- ### 📝 Commits (3) - [`13b0e7d`](https://github.com/open-webui/open-webui/commit/13b0e7d64a708f69c5ce58cf0897d9951d0d16ad) Merge pull request #4434 from open-webui/dev - [`f73a60d`](https://github.com/open-webui/open-webui/commit/f73a60d96c0018d9cb57e3e2382ca52a5316eb71) fix: set content-type header in ollama backend - [`439cb66`](https://github.com/open-webui/open-webui/commit/439cb66672aac1490a8e16ed5a99159dddcefd85) refac: fuzzy search threshold ### 📊 Changes **2 files changed** (+13 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/apps/ollama/main.py` (+11 -2) 📝 `src/lib/components/chat/ModelSelector/Selector.svelte` (+2 -1) </details> ### 📄 Description # Pull Request Checklist ### Note to first-time contributors: Please open a discussion post in [Discussions](https://github.com/open-webui/open-webui/discussions) and describe your changes before submitting a pull request. **Before submitting, make sure you've checked the following:** - [x] **Target branch:** Please verify that the pull request targets the `dev` branch. - [x] **Description:** Provide a concise description of the changes made in this pull request. - [x] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description. - [x] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources? - [x] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation? - [x] **Testing:** Have you written and run sufficient tests for validating the changes? - [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards? - [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following: - **BREAKING CHANGE**: Significant changes that may affect compatibility - **build**: Changes that affect the build system or external dependencies - **ci**: Changes to our continuous integration processes or workflows - **chore**: Refactor, cleanup, or other non-functional code changes - **docs**: Documentation update or addition - **feat**: Introduces a new feature or enhancement to the codebase - **fix**: Bug fix or error correction - **i18n**: Internationalization or localization changes - **perf**: Performance improvement - **refactor**: Code restructuring for better maintainability, readability, or scalability - **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.) - **test**: Adding missing tests or correcting existing tests - **WIP**: Work in progress, a temporary label for incomplete or ongoing work # Changelog Entry ### Description The Ollama backend code doesn't work with custom Ollama compatible APIs made with FastAPI. The issue comes from missing (or incorrect) `Content-Type` HTTP header, which now defaults to `text/plain`. Without proper header, the FastAPI (or maybe Pydantic) raises and `422 Unprocessable Entity` exception even with valid JSON. This issue affects POST requests only. ### Added - Set `Content-Type: application/json` header for POST requests in the Ollama backend code. --- ### Screenshots or Videos **UI and custom Ollama API without header set** The `422` exception get propagated to the UI. <img width="640" alt="1-no-header-1 Large" src="https://github.com/user-attachments/assets/dcbc8306-01f4-40a4-8b27-dc8e0fdbbf52"> <img width="640" alt="1-no-header-2 Large" src="https://github.com/user-attachments/assets/60f65224-2199-434f-b2ba-77753434adf7"> **UI and custom Ollama API with header set** No exceptions raised this time. <img width="640" alt="2-header-1 Large" src="https://github.com/user-attachments/assets/86fb50e6-06f9-4579-9a97-136adfdd3602"> <img width="640" alt="2-header-2 Large" src="https://github.com/user-attachments/assets/bffda367-e92f-4b17-b91a-4fcd7a49607d"> **UI with Ollama still working** As it should be. <img width="640" alt="3-ollama Large" src="https://github.com/user-attachments/assets/aa612d11-7659-4afc-a0f3-1ef3c85f0334"> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 03:34:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#21525