Skip to content

Bedrock Titan Chat Missing Usage Information #1769

@gm2552

Description

@gm2552

Bug description
Bedrock/Titan chats return token usage information which is deserialized into a TitanChatResponse record. Token usage information is dropped in the BedrockTitanChatModel class when converting TitanChatResponse objects to ChatResponse objects.

    public ChatResponse call(Prompt prompt) {
        TitanChatBedrockApi.TitanChatResponse response = this.chatApi.chatCompletion(this.createRequest(prompt));
        List<Generation> generations = response.results().stream().map((result) -> {
            return new Generation(result.outputText());
        }).toList();
        return new ChatResponse(generations);
    }

Environment
All versions of Spring AI supporting Bedrock/Titan. Currently testing with M3-PLATFORM.

Steps to reproduce
Execute any valid Chat against a Chat based Bedrock/Titan model using a BedrockTitanChatModel and validate that usage meta data is empty.

Eg:

BedrockTitanChatModel = new BedrockTitanChatModel(...);
ChatClient.builder(chatModel).defaultOptions(options).build();
ChatResponse response = client.prompt(prompt).call().chatResponse();
Usage usage = response.getMetadata().getUsage();
assertThat(usage.getPromptTokens()).isEqualTo(0);

Expected behavior
Expecting that the usage in will be non-zero.

assertThat(usage.getPromptTokens()).isGreaterThan(0);

Metadata

Metadata

Assignees

Labels

BedrockbugSomething isn't workinginvalidThis doesn't seem rightusage

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions