From 567cc50bb51c9c5c51fa36683356de472a825556 Mon Sep 17 00:00:00 2001 From: aryan Date: Tue, 11 Feb 2025 15:58:05 -0700 Subject: [PATCH] fix: bugs --- src/index.ts | 23 +++++++++++++++----- templates/next/components/chat/ChatInput.tsx | 4 ++++ templates/next/config/agent.ts | 9 +++++++- templates/next/package.json | 1 + 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 984aacb..2f5a4b2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -79,14 +79,23 @@ export async function main(argv: string[]) { } }, }), - openaiApiKey: () => + model: () => + p.select({ + message: "Choose your AI model:", + options: [ + { value: "claude-sonnet", label: "Claude Sonnet"}, + { value: "gpt-4", label: "GPT-4" }, + { value: "deepseek-chat", label: "DeepSeek Chat" }, + ], + }), + apiKey: (results) => p.text({ - message: "DeepSeek or OpenAI API Key:", + message: `${results.results.model === "claude-sonnet" ? "Anthropic" : results.results.model === "gpt-4" ? "OpenAI" : "DeepSeek"} API Key:`, placeholder: "sk-...", defaultValue: "", validate(value) { if (!value) { - return "DeepSeek or OpenAI API Key is required"; + return "API Key is required"; } }, }), @@ -110,7 +119,7 @@ export async function main(argv: string[]) { }, ); - const { projectName, rpcURL, openaiApiKey, solanaPrivateKey } = group; + const { projectName, rpcURL, model, apiKey, solanaPrivateKey } = group; const finalProjectName = projectName || defaultProjectName; const finalRpcURL = rpcURL || defaultRpcURL; @@ -128,9 +137,13 @@ export async function main(argv: string[]) { await fs.promises.writeFile(pkgPath, JSON.stringify(pkg, null, 2)); const envPath = path.join(root, ".env"); + const apiKeyName = model === "claude-sonnet" ? "ANTHROPIC_API_KEY" + : model === "gpt-4" ? "OPENAI_API_KEY" + : "DEEPSEEK_API_KEY"; + await fs.promises.writeFile( envPath, - `OPENAI_API_KEY=${openaiApiKey}\nRPC_URL=${finalRpcURL}\nSOLANA_PRIVATE_KEY=${solanaPrivateKey}`, + `MODEL=${model}\n${apiKeyName}=${apiKey}\nRPC_URL=${finalRpcURL}\nSOLANA_PRIVATE_KEY=${solanaPrivateKey}`, ); spinner.succeed(); diff --git a/templates/next/components/chat/ChatInput.tsx b/templates/next/components/chat/ChatInput.tsx index c370e12..612ac1d 100644 --- a/templates/next/components/chat/ChatInput.tsx +++ b/templates/next/components/chat/ChatInput.tsx @@ -7,6 +7,10 @@ import { AGENT_MODES } from "./ModeSelector"; import { DropdownComp } from "./WalletSelector"; import { useEffect, useState } from "react"; export const MOCK_MODELS = [ + { + name: "Claude", + subTxt: "Claude 3.5 Sonnet", + }, { name: "OpenAI", subTxt: "GPT-4o-mini", diff --git a/templates/next/config/agent.ts b/templates/next/config/agent.ts index 2a1b1c2..dadd556 100644 --- a/templates/next/config/agent.ts +++ b/templates/next/config/agent.ts @@ -1,6 +1,7 @@ import { MemorySaver } from "@langchain/langgraph"; import { createReactAgent } from "@langchain/langgraph/prebuilt"; import { ChatOpenAI } from "@langchain/openai"; +import { ChatAnthropic } from "@langchain/anthropic"; import { validateEnvironment } from "@/lib/utils"; import { SolanaAgentKit } from "solana-agent-kit"; import { createSolanaTools } from "solana-agent-kit"; @@ -9,10 +10,16 @@ import { ChatDeepSeek } from "@langchain/deepseek"; export async function initializeAgent(modelName: string) { const llm = modelName?.includes("OpenAI") ? new ChatOpenAI({ - modelName: "gpt-4o-mini", + modelName: "gpt-4o-turbo", temperature: 0.3, apiKey: process.env.OPENAI_API_KEY!, }) + : modelName?.includes("Claude") + ? new ChatAnthropic({ + modelName: "claude-3-sonnet-latest", + temperature: 0.3, + apiKey: process.env.ANTHROPIC_API_KEY!, + }) : new ChatDeepSeek({ model: "deepseek-chat", temperature: 0, diff --git a/templates/next/package.json b/templates/next/package.json index bfb73ad..87a1b99 100644 --- a/templates/next/package.json +++ b/templates/next/package.json @@ -14,6 +14,7 @@ "@langchain/core": "^0.3.27", "@langchain/deepseek": "^0.0.1", "@langchain/langgraph": "^0.2.38", + "@langchain/anthropic": "^0.3.13", "@langchain/openai": "^0.3.16", "@phosphor-icons/react": "^2.1.7", "@radix-ui/react-dropdown-menu": "^2.1.4",