-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Support for extra_body parameter for embeddings API #906
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #906 +/- ##
==========================================
+ Coverage 98.46% 98.71% +0.25%
==========================================
Files 24 26 +2
Lines 1364 1789 +425
==========================================
+ Hits 1343 1766 +423
- Misses 15 16 +1
- Partials 6 7 +1 ☔ View full report in Codecov by Sentry. |
@sashabaranov Can you please look into this? |
} | ||
if baseReq.Dimensions > 0 { // Assuming 0 means the field is not set | ||
body["dimensions"] = baseReq.Dimensions | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR! Do I understand correctly that we'll need to extend logic here every time EmbeddingRequest
gets updated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, could we maybe serialize baseReq
to json and then back to map[string]any
? That would allow us not to keep this logic updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes will need to extend logic here also if EmbeddingRequest gets updated. But yeah I think to support extra_body param this map approach is the way to do so in Golang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, could we maybe serialize
baseReq
to json and then back tomap[string]any
? That would allow us not to keep this logic updated
Okay will look into it and update the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sashabaranov I have updated the PR and tested the changes, can you please review the changes?
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