Data storage (#3)

* feat: add prisma

* fix: generate prisma
This commit is contained in:
2025-06-23 19:04:01 +02:00
committed by GitHub
parent 5e5c090cd9
commit 30c67a308b
8 changed files with 189 additions and 12 deletions

View File

@@ -1,6 +1,11 @@
import Anthropic from '@anthropic-ai/sdk';
export async function getMessage(text: string) {
interface AnthropicResponse {
text: string;
tokensUsed: number;
}
export async function getMessage(text: string): Promise<AnthropicResponse> {
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
});
@@ -18,7 +23,20 @@ export async function getMessage(text: string) {
try {
const data = response.content as [{ type: string; text: string }];
return data[0].text;
const tokensUsed =
(response.usage?.input_tokens || 0) +
(response.usage?.output_tokens || 0);
console.info('Token usage:', {
input_tokens: response.usage?.input_tokens,
output_tokens: response.usage?.output_tokens,
total: tokensUsed
});
return {
text: data[0].text,
tokensUsed
};
} catch (error) {
throw new Error(`Anthropic client error: ${JSON.stringify(error)}.`);
}