whatsapp-claude-gpt
Version:
WhatsApp-Claude-GPT is an advanced chatbot for WhatsApp, integrating AI language models for text conversations, image generation, and voice messages.
37 lines (26 loc) • 971 B
text/typescript
import logger from '../logger';
import Anthropic from '@anthropic-ai/sdk';
import { AIConfig } from '../config';
import { MessageParam, TextBlock } from '@anthropic-ai/sdk/resources';
export class AnthropicService {
private anthropic : Anthropic;
constructor() {
this.anthropic = new Anthropic({
apiKey: AIConfig.ChatConfig.apiKey,
});
}
async sendChat(messageList: MessageParam[], systemPrompt: string) {
logger.debug(`[Claude->sendCompletion] Sending ${messageList.length} messages.`);
const response = await this.anthropic.messages.create({
system: systemPrompt,
model: AIConfig.ChatConfig.model,
messages: messageList,
max_tokens: 1024,
top_p: 1
});
logger.debug('[Claude->sendCompletion] Completion Response:');
logger.debug(response.content[0]);
const responseContent = response.content[0] as TextBlock;
return responseContent.text;
}
}