Skip to content

Commit

Permalink
#183: simplifed code by introducing a new var for the content
Browse files Browse the repository at this point in the history
  • Loading branch information
roma-glushko committed Mar 19, 2024
1 parent f03b3d9 commit fb96526
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/providers/anthropic/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
},
Expand Down

0 comments on commit fb96526

Please sign in to comment.