mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #13898] [CLOSED] feat: Add OpenAI-Compliant /v1/embeddings Endpoints #62181
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?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/13898
Author: @pranitl
Created: 5/15/2025
Status: ❌ Closed
Base:
dev← Head:feature/openai-embeddings-schema📝 Commits (1)
512cef2Add OpenAI embeddings schema support and update routers📊 Changes
6 files changed (+450 additions, -264 deletions)
View changed files
📝
backend/open_webui/main.py(+93 -25)➕
backend/open_webui/models/embeddings.py(+25 -0)➕
backend/open_webui/routers/local.py(+99 -0)📝
backend/open_webui/routers/ollama.py(+132 -225)📝
backend/open_webui/routers/openai.py(+66 -2)📝
backend/open_webui/utils/models.py(+35 -12)📄 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:
devbranch.Changelog Entry
Description
This pull request introduces standardized, OpenAI-compliant embedding generation capabilities through new API endpoints. It adds
POST /openai/v1/embeddingsto interface with various configured OpenAI-compatible services andPOST /ollama/v1/embeddingsto provide an OpenAI-compliant interface for Ollama's embedding models. This enhancement aims to provide a consistent API for embedding generation, regardless of the backend service.The implementation includes:
OpenAIEmbeddingsRequest,OpenAIEmbeddingsResponse, etc.) inbackend/open_webui/models/openai_schemas.pyfor consistent OpenAI-compliant request/response handling across the new endpoints.estimate_embedding_tokens) inbackend/open_webui/utils/misc.pyfor use by the Ollama endpoint to populate usage statistics./ollama/v1/embeddingsendpoint performs translation of OpenAI-formatted requests to Ollama's native embedding request format and translates Ollama's responses back to the OpenAI schema./openai/v1/embeddingsendpoint routes requests to the appropriate configured OpenAI-compatible backend (e.g., official OpenAI, Azure OpenAI, other generic providers).Added
POST /openai/v1/embeddingsinbackend/open_webui/routers/openai.pyfor generating embeddings using configured OpenAI-compatible services.POST /ollama/v1/embeddingsinbackend/open_webui/routers/ollama.pyfor generating embeddings via Ollama, using an OpenAI-compliant interface.OpenAIEmbeddingsRequest,OpenAIEmbeddingData,OpenAIUsage,OpenAIEmbeddingsResponse) inbackend/open_webui/models/openai_schemas.py.estimate_embedding_tokensinbackend/open_webui/utils/misc.pyto help estimate token counts for embedding inputs, primarily for Ollama._generate_ollama_embeddings_native(or similar) withinbackend/open_webui/routers/ollama.pyto centralize Ollama's native embedding call logic.)*Changed
backend/open_webui/routers/ollama.pyto utilize a new internal helper function. This improves code structure and reusability for calls to Ollama's/api/embedor/api/embeddings.)*Deprecated
/ollama/api/embedis already marked as deprecated in the codebase prior to this work).Removed
Fixed
Security
Breaking Changes
/ollama/api/embedand/ollama/api/embeddings) remain functional and unaffected.Additional Information
Screenshots or Videos
curlcommands for testing have been successfully executed against a local development instance.Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.