Skip to content

Commit

Permalink
fix: parsing of anthropic response
Browse files Browse the repository at this point in the history
  • Loading branch information
gwilkes-rv committed Oct 13, 2024
1 parent 8533f79 commit e66ea3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ export class Bot {
const textContent = response.content.find(item => item.type === 'text');
if (textContent && 'text' in textContent) {
responseText = textContent.text;

// Clean up the response text
responseText = responseText.replace(/\n/g, '\\n').replace(/\r/g, '\\r');

try {
// Parse the JSON content
const parsedContent = JSON.parse(responseText);
responseText = JSON.stringify(parsedContent, null, 2); // Pretty print the JSON
} catch (parseError) {
warning(`Failed to parse response as JSON: ${parseError}`);
// If parsing fails, keep the original responseText
}
} else {
warning('No text content found in the response');
}
Expand Down

0 comments on commit e66ea3f

Please sign in to comment.