This repository has been archived on 2026-02-01. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
siri-shortcuts/utils/anthropicClient.ts

26 lines
661 B
TypeScript

import Anthropic from '@anthropic-ai/sdk';
export async function getMessage(text: string) {
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
});
console.info('Anthropic request with text: ', text);
const response = await anthropic.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 2048,
messages: [{ role: 'user', content: text }]
});
console.info('Anthropic response: ', response);
try {
const data = response.content as [{ type: string; text: string }];
return data[0].text;
} catch (error) {
throw new Error(`Anthropic client error: ${JSON.stringify(error)}.`);
}
}