GH-6098: Expose Bedrock Cohere embedding token usage from HTTP headers#6145
Open
wolf8334 wants to merge 1 commit into
Open
GH-6098: Expose Bedrock Cohere embedding token usage from HTTP headers#6145wolf8334 wants to merge 1 commit into
wolf8334 wants to merge 1 commit into
Conversation
Contributor
|
You should drop the unrelated commit fd1bda2 for this PR. |
…rom HTTP headers Bedrock Cohere embedding API returns input token count in the x-amzn-bedrock-input-token-count HTTP response header, but AbstractBedrockApi.internalInvocation() only processed the response body, discarding the headers. This caused EmbeddingResponse metadata to contain no token usage information. Changes: - Add BedrockResponse<T> record and internalInvocationForModel() to AbstractBedrockApi that returns both the response body and SdkHttpResponse headers - Add CohereEmbeddingModelResponse wrapper and embeddingForModel() to CohereEmbeddingBedrockApi that extracts input token count from the x-amzn-bedrock-input-token-count header - Update BedrockCohereEmbeddingModel.call() to pass token usage via EmbeddingResponseMetadata + DefaultUsage - Add unit tests verifying token usage extraction from headers Fixes spring-projectsGH-6098 Signed-off-by: 钱多多 <2916947+wolf8334@users.noreply.github.com>
Author
thank you. |
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.
Problem
Bedrock Cohere embedding API returns input token count in the `x-amzn-bedrock-input-token-count` HTTP response header, but Spring AI's `AbstractBedrockApi.internalInvocation()` only processes the response body, discarding the headers. This means `EmbeddingResponse` metadata contains no token usage (all zeros).
Changes
Reference
Same issue was fixed in LangChain4j: langchain4j/langchain4j#5064
Closes GH-6098