Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for extra_body parameter for embeddings API #906

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

AyushSawant18588
Copy link
Contributor

@AyushSawant18588 AyushSawant18588 commented Nov 23, 2024

Describe the change
This change adds support for an ExtraBody parameter in the EmbeddingRequest struct, allowing developers to include additional, arbitrary key-value pairs in the API request payload. This ensures extensibility and flexibility when working with the OpenAI Embeddings API, especially for experimental features, future API updates, or custom parameters that are not explicitly defined in the current request structure. The addition of ExtraBody is particularly valuable for supporting LLM engines like vLLM, Nvidia NIM, etc, which may require additional fields beyond the standard parameters. Refrence
There is an issue created that ExtraBody parameter support is required for vLLM engine also. #898
In this PR ExtraBody parameter support is added only for embedding API but it can be extended for other APIs as well like chat completions

Provide OpenAI documentation link
OpenAI's official python client also supports this extra_body field which this go client could also support. Refrence

Describe your solution
The solution involves:
Introducing the ExtraBody field in the EmbeddingRequest struct. This is a map of string keys to arbitrary values (map[string]any) that allows developers to pass additional fields to the API dynamically.
Updating the CreateEmbeddings method to merge the ExtraBody values into the main request payload (body) before sending it to the API. This is done through the withExtraBody request option, which ensures the fields in ExtraBody are included without overwriting existing mandatory parameters.

Tests
Added unit tests and done sanity check of embeddings api with extra_body param for Nvidia NIM embedding model

Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.71%. Comparing base (774fc9d) to head (2e5a45e).
Report is 73 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #906      +/-   ##
==========================================
+ Coverage   98.46%   98.71%   +0.25%     
==========================================
  Files          24       26       +2     
  Lines        1364     1788     +424     
==========================================
+ Hits         1343     1765     +422     
- Misses         15       16       +1     
- Partials        6        7       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@AyushSawant18588
Copy link
Contributor Author

@sashabaranov Can you please look into this?

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.

1 participant