export class OpenAIClient { constructor(private apiKey: string) {} async generateText(prompt: string, systemPrompt?: string): Promise { const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { Authorization: `Bearer ${this.apiKey}`, "Content-Type": "application/json", }, body: JSON.stringify({ model: "gpt-4-turbo-preview", messages: [ ...(systemPrompt ? [{ role: "system", content: systemPrompt }] : []), { role: "user", content: prompt }, ], temperature: 0.7, max_tokens: 3000, }), }); if (!response.ok) { const error = await response.text(); throw new Error(`OpenAI API error: ${error}`); } const data = await response.json(); return data.choices[0].message.content; } } export class AnthropicClient { constructor(private apiKey: string) {} async generateText(prompt: string, systemPrompt?: string): Promise { const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", headers: { "x-api-key": this.apiKey, "anthropic-version": "2023-06-01", "Content-Type": "application/json", }, body: JSON.stringify({ model: "claude-3-5-sonnet-20241022", max_tokens: 3000, system: systemPrompt || undefined, messages: [ { role: "user", content: prompt }, ], }), }); if (!response.ok) { const error = await response.text(); throw new Error(`Anthropic API error: ${error}`); } const data = await response.json(); return data.content[0].text; } }