feat: base shortcut code

This commit is contained in:
2025-01-18 21:54:26 +01:00
parent a820b29ea9
commit 3abe88c7a2
29 changed files with 5982 additions and 123 deletions

25
utils/anthropicClient.ts Normal file
View File

@@ -0,0 +1,25 @@
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)}.`);
}
}