From 629d0801e4d868c8c2285600bbdc1688f09202f8 Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Wed, 23 Oct 2024 23:31:50 -0400 Subject: [PATCH] feat: fix OPENROUTER_API_KEY --- .cspell.json | 3 ++- .dev.vars.example | 3 ++- .github/workflows/compute.yml | 2 ++ .github/workflows/worker-deploy.yml | 8 ++++++++ README.md | 4 +++- src/plugin.ts | 2 +- src/types/env.ts | 1 + 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.cspell.json b/.cspell.json index bbe91d8..0f66bc6 100644 --- a/.cspell.json +++ b/.cspell.json @@ -30,7 +30,8 @@ "mixtral", "nemo", "Reranking", - "mistralai" + "mistralai", + "OPENROUTER" ], "dictionaries": ["typescript", "node", "software-terms"], "import": ["@cspell/dict-typescript/cspell-ext.json", "@cspell/dict-node/cspell-ext.json", "@cspell/dict-software-terms"], diff --git a/.dev.vars.example b/.dev.vars.example index e39f3dd..a443dae 100644 --- a/.dev.vars.example +++ b/.dev.vars.example @@ -1,4 +1,5 @@ OPENAI_API_KEY="" SUPABASE_URL="" SUPABASE_KEY="" -VOYAGEAI_API_KEY="" \ No newline at end of file +VOYAGEAI_API_KEY="" +OPENROUTER_API_KEY="" \ No newline at end of file diff --git a/.github/workflows/compute.yml b/.github/workflows/compute.yml index 285665e..895baec 100644 --- a/.github/workflows/compute.yml +++ b/.github/workflows/compute.yml @@ -28,6 +28,7 @@ jobs: SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }} steps: @@ -49,4 +50,5 @@ jobs: SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }} OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }} \ No newline at end of file diff --git a/.github/workflows/worker-deploy.yml b/.github/workflows/worker-deploy.yml index cba478c..161eab8 100644 --- a/.github/workflows/worker-deploy.yml +++ b/.github/workflows/worker-deploy.yml @@ -39,8 +39,16 @@ jobs: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} secrets: | OPENAI_API_KEY + SUPABASE_URL + SUPABASE_KEY + VOYAGEAI_API_KEY + OPENROUTER_API_KEY env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + SUPABASE_URL: ${{ secrets.SUPABASE_URL }} + SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} + VOYAGEAI_API_KEY: ${{ secrets.VOYAGEAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} - name: Write Deployment URL to Summary run: | diff --git a/README.md b/README.md index ae289dc..2d75788 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,13 @@ plugins: `.dev.vars` (for local testing): +If you plan on using the OpenRouter API, set both the `OPENROUTER_API_KEY` and the `openAiBaseUrl` in the `ubiquibot-config.yml` file. Otherwise, use the `OPENAI_API_KEY`. + ```sh # OpenAI API key OPENAI_API_KEY=your-api-key UBIQUITY_OS_APP_NAME="UbiquityOS" - +OPENROUTER_API_KEY=your-api-key ``` ## Testing diff --git a/src/plugin.ts b/src/plugin.ts index 8eab234..b1ff223 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -17,7 +17,7 @@ export async function plugin(inputs: PluginInputs, env: Env) { apiKey: env.VOYAGEAI_API_KEY, }); const openAiObject = { - apiKey: env.OPENAI_API_KEY, + apiKey: (inputs.settings.openAiBaseUrl && env.OPENROUTER_API_KEY) || env.OPENAI_API_KEY, ...(inputs.settings.openAiBaseUrl && { baseURL: inputs.settings.openAiBaseUrl }), }; const openaiClient = new OpenAI(openAiObject); diff --git a/src/types/env.ts b/src/types/env.ts index d548e9d..11229dc 100644 --- a/src/types/env.ts +++ b/src/types/env.ts @@ -17,6 +17,7 @@ export const envSchema = T.Object({ VOYAGEAI_API_KEY: T.String(), SUPABASE_URL: T.String(), SUPABASE_KEY: T.String(), + OPENROUTER_API_KEY: T.String(), }); export const envValidator = new StandardValidator(envSchema);