Skip to content

Commit

Permalink
Handle empty response form the LLM
Browse files Browse the repository at this point in the history
  • Loading branch information
narengogi committed Jul 10, 2024
1 parent 38d29eb commit f8b3416
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/providers/anthropic/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export const AnthropicChatCompleteResponseTransform: (
const { input_tokens = 0, output_tokens = 0 } = response?.usage;

let content = '';
if (response.content[0].type === 'text') {
if (response.content.length && response.content[0].type === 'text') {
content = response.content[0].text;
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/bedrock/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ export const BedrockAnthropicChatCompleteResponseTransform: (
Number(responseHeaders.get('X-Amzn-Bedrock-Output-Token-Count')) || 0;

let content = '';
if (response.content[0].type === 'text') {
if (response.content.length && response.content[0].type === 'text') {
content = response.content[0].text;
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/google-vertex-ai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export const VertexAnthropicChatCompleteResponseTransform: (
const { input_tokens = 0, output_tokens = 0 } = response?.usage;

let content = '';
if (response.content[0].type === 'text') {
if (response.content.length && response.content[0].type === 'text') {
content = response.content[0].text;
}

Expand Down

0 comments on commit f8b3416

Please sign in to comment.