From fb96526177ff35615ded51fe401b889667d522c8 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Wed, 20 Mar 2024 00:17:04 +0200 Subject: [PATCH] #183: simplifed code by introducing a new var for the content --- pkg/providers/anthropic/chat.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/providers/anthropic/chat.go b/pkg/providers/anthropic/chat.go index 21329591..570b5e9c 100644 --- a/pkg/providers/anthropic/chat.go +++ b/pkg/providers/anthropic/chat.go @@ -139,6 +139,7 @@ func (c *Client) doChatRequest(ctx context.Context, payload *ChatRequest) (*sche return nil, err } + completion := anthropicResponse.Content[0] usage := anthropicResponse.Usage // Map response to ChatResponse schema @@ -151,11 +152,11 @@ func (c *Client) doChatRequest(ctx context.Context, payload *ChatRequest) (*sche ModelResponse: schemas.ModelResponse{ SystemID: map[string]string{}, Message: schemas.ChatMessage{ - Role: anthropicResponse.Content[0].Type, - Content: anthropicResponse.Content[0].Text, + Role: completion.Type, + Content: completion.Text, }, TokenUsage: schemas.TokenUsage{ - PromptTokens: usage.InputTokens, // Anthropic doesn't send prompt tokens + PromptTokens: usage.InputTokens, ResponseTokens: usage.OutputTokens, TotalTokens: usage.InputTokens + usage.OutputTokens, },