Support for extra_body parameter for embeddings API #906
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.
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