From 565cddf86c242ea949313efd4bfe43cbdb9dab2e Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 26 Sep 2025 08:52:24 +0200 Subject: [PATCH] Updates Anthropic API to use structured content Adapts the Anthropic client to use the new structured content format for messages and system prompts, ensuring compatibility with the API's expected input structure. This change modifies both the standard request and the test request within the Anthropic client. --- api/anthropicClient.ts | 8 ++++---- types.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/api/anthropicClient.ts b/api/anthropicClient.ts index e256415..cebf5a9 100644 --- a/api/anthropicClient.ts +++ b/api/anthropicClient.ts @@ -69,8 +69,8 @@ You MUST use exactly these markers. Do not deviate from this format.`; const request: AnthropicRequest = { model, max_tokens: ANTHROPIC_LIMITS.DEFAULT_MAX_OUTPUT_TOKENS, - messages: [{ role: 'user', content: userMessage }], - system: systemPrompt + messages: [{ role: 'user', content: [{ type: 'text', text: userMessage }] }], + system: [{ type: 'text', text: systemPrompt }] }; const response = await this.makeRequestWithRetry(request); @@ -100,8 +100,8 @@ You MUST use exactly these markers. Do not deviate from this format.`; const testRequest: AnthropicRequest = { model, max_tokens: 50, - messages: [{ role: 'user', content: 'Hello! Please respond with just "Test successful."' }], - system: 'You are a test assistant. Respond only with "Test successful." and nothing else.' + messages: [{ role: 'user', content: [{ type: 'text', text: 'Hello! Please respond with just "Test successful."' }] }], + system: [{ type: 'text', text: 'You are a test assistant. Respond only with "Test successful." and nothing else.' }] }; try { diff --git a/types.ts b/types.ts index b5a8567..fccce8c 100644 --- a/types.ts +++ b/types.ts @@ -12,14 +12,20 @@ export interface FreewritingCleanupSettings { export interface AnthropicMessage { role: 'user' | 'assistant' | 'system'; - content: string; + content: Array<{ + type: string; + text: string; + }>; } export interface AnthropicRequest { model: string; max_tokens: number; messages: AnthropicMessage[]; - system?: string; + system?: Array<{ + type: string; + text: string; + }>; } export interface AnthropicResponse {