From 52f06afa4d64dd55c7fbcfb9bfef28b25802de89 Mon Sep 17 00:00:00 2001 From: shoushou Date: Fri, 20 Dec 2024 11:44:29 -0800 Subject: [PATCH] fix: TOGETHER_API_KEY --- src/server.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.ts b/src/server.ts index 4659cf7..d08173a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -24,7 +24,6 @@ class JsonResponse extends Response { } const router = AutoRouter(); -const together = new Together({ apiKey: process.env.TOGETHER_API_KEY }); /** * A simple hello page to verify the worker is working. @@ -75,7 +74,7 @@ router.post('/', async (request, env) => { ); const userPrompt = promptOption?.value; - const aiResponse = await sendToAIProvider(userPrompt || "No input"); + const aiResponse = await sendToAIProvider(env.TOGETHER_API_KEY, userPrompt || "No input"); return new JsonResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { @@ -113,7 +112,8 @@ const server = { fetch: router.fetch }; -async function sendToAIProvider(prompt: string): Promise { +async function sendToAIProvider(api_key: string, prompt: string): Promise { + const together = new Together({ apiKey: api_key }); const response = await together.chat.completions.create({ model: "meta-llama/Llama-Vision-Free", messages: [{ role: "user", content: prompt }],