Skip to content

Commit

Permalink
commands(chat): implement claude support
Browse files Browse the repository at this point in the history
Signed-off-by: TRACTION <19631364+iamtraction@users.noreply.github.com>
  • Loading branch information
iamtraction committed Oct 6, 2024
1 parent 84893e1 commit 3fcb610
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/commands/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
import { ApplicationCommandOptionType, ChatInputCommandInteraction } from "discord.js";
import { Client, Command } from "@bastion/tesseract";
import Anthropic from "@anthropic-ai/sdk";
import OpenAI from "openai";
import { GoogleGenerativeAI } from "@google/generative-ai";

Expand Down Expand Up @@ -71,6 +72,33 @@ class ChatCommand extends Command {
});
}

// use Claude if Anthropic API key is present
if (((interaction.client as Client).settings as Settings).get("anthropic").apiKey) {
const anthropic = new Anthropic({
apiKey: ((interaction.client as Client).settings as Settings).get("anthropic").apiKey,
});

const result = await anthropic.messages.create({
model: ((interaction.client as Client).settings as Settings).get("anthropic").model,
max_tokens: ((interaction.client as Client).settings as Settings).get("anthropic").maxTokens,
messages: [
{
role: "user",
content: [
{
type: "text",
text: message,
},
],
},
],
});

return await interaction.editReply({
content: result.content[0].type === "text" && result.content[0].text,
});
}

return await interaction.editReply({
content: "You haven't set up API keys for any gen AI APIs.",
});
Expand Down

0 comments on commit 3fcb610

Please sign in to comment.