feat: Add OpenAI-Compliant /v1/embeddings Endpoints#13898
Closed
pranitl wants to merge 1 commit intoopen-webui:devfrom
Closed
feat: Add OpenAI-Compliant /v1/embeddings Endpoints#13898pranitl wants to merge 1 commit intoopen-webui:devfrom
pranitl wants to merge 1 commit intoopen-webui:devfrom
Conversation
gaby
reviewed
May 16, 2025
|
|
||
| from open_webui.config import ( | ||
| LICENSE_KEY, | ||
| # Ollama |
| CODE_INTERPRETER_JUPYTER_AUTH_TOKEN, | ||
| CODE_INTERPRETER_JUPYTER_AUTH_PASSWORD, | ||
| CODE_INTERPRETER_JUPYTER_TIMEOUT, | ||
| # Image |
Contributor
There was a problem hiding this comment.
Same here, and all over this file
| f"Frontend build directory not found at '{FRONTEND_BUILD_DIR}'. Serving API only." | ||
| ) | ||
|
|
||
| # New centralized, versioned dispatcher for embeddings |
| user: UserModel = Depends(get_verified_user) | ||
| ): | ||
| model_id_from_request = request_data.model | ||
| log = logging.getLogger(__name__) # Get logger instance |
Contributor
There was a problem hiding this comment.
Why are we getting a logger within a handler? Use the existing logger
| from starlette.background import BackgroundTask | ||
|
|
||
| from open_webui.models.models import Models | ||
| from open_webui.models.embeddings import OpenAIEmbeddingResponse |
Contributor
There was a problem hiding this comment.
This file has a line where "embeddings" is filtered out from the /openai handler.
With this PR that filter should be removed or handled differently?
Contributor
|
Any chance this can be picked back up? Or is there any other way to expose embedding models from an OpenAI-compatible backend (e.g. via /api/embed)? EDIT: Just half an hour after this comment #14667 popped up, which looks very good. |
8 tasks
Contributor
|
Closing in favour of #14667 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.