Skip to content

feat: Embeddings endpoint added for 100% OpenAI compatibility#10018

Closed
hdnh2006 wants to merge 1 commit intoopen-webui:mainfrom
hdnh2006:main
Closed

feat: Embeddings endpoint added for 100% OpenAI compatibility#10018
hdnh2006 wants to merge 1 commit intoopen-webui:mainfrom
hdnh2006:main

Conversation

@hdnh2006
Copy link
Contributor

@hdnh2006 hdnh2006 commented Feb 14, 2025

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

This PR solves this feature request.

With this PR, I add a new route /api/embeddings that allows direct access to the embeddings functionality while maintaining the existing /openai/embeddings route. This enables more intuitive API access for embeddings generation.

Added

  • New route /api/embeddings that maps to the existing OpenAI embeddings functionality

Changed

  • Added new endpoint in main.py that redirects to the OpenAI embeddings handler

Deprecated

  • NA

Removed

  • NA

Fixed

  • This PR solves this feature request.

Security

  • NA

Breaking Changes

  • BREAKING CHANGE: NA

Additional Information

  • This change maintains backward compatibility while adding a more convenient access point
  • The implementation reuses existing code from the OpenAI router
  • No breaking changes or additional dependencies required
  • This PR solves this feature request.

Screenshots or Videos

image

Python code used for testing:

import requests
import json

# API endpoint
url = "http://localhost:3000/api/embeddings"

# Headers
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer sk-12345678"  # Replace with your actual token
}


# Request payload
payload = {
    "model": "text-embedding-ada-002",
    "input": [
        "Hello this is a single test",
    ]
}


# Make the POST request
response = requests.post(url, headers=headers, json=payload)

# Check if the request was successful
response.raise_for_status()

# Print the response
print("Response:", response.json())

Response gotten:

Response: {'model': 'text-embedding-ada-002-v2', 'data': [{'embedding': [-0.017571303993463516, 0.022639181464910507, -0.003385236021131277, -0.02396933175623417, ...], 'index': 0, 'object': 'embedding'}], 'object': 'list', 'usage': {'completion_tokens': 0, 'prompt_tokens': 6, 'total_tokens': 6, 'completion_tokens_details': None, 'prompt_tokens_details': None}}

@hdnh2006 hdnh2006 changed the title **feat**: Embeddings endpoint added for 100% OpenAI compatibility feat: Embeddings endpoint added for 100% OpenAI compatibility Feb 14, 2025
@tjbck
Copy link
Contributor

tjbck commented Feb 14, 2025

This does not implement /embeddings endpoint as it should. Please refer to how other endpoints are implemented.

@tjbck tjbck closed this Feb 14, 2025
@hdnh2006
Copy link
Contributor Author

This does not implement /embeddings endpoint as it should. Please refer to how other endpoints are implemented.

Could you please be more specific about what you expect?

What I did is to create an endpoint in openai route, how would you like to implement this?

Thanks in advance.

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

Successfully merging this pull request may close these issues.

2 participants