From 2811fa0d5526fb210002f0cbdb9f5b3ad9e5dc4b Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Wed, 23 Oct 2024 23:53:13 -0400 Subject: [PATCH] feat: adds OPENROUTER_API_KEY --- .cspell.json | 3 ++- .dev.vars.example | 4 +++- .github/workflows/compute.yml | 2 ++ .github/workflows/worker-deploy.yml | 1 + README.md | 10 +++++++--- src/plugin.ts | 2 +- src/types/env.ts | 1 + 7 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.cspell.json b/.cspell.json index bbe91d8..bfda9c8 100644 --- a/.cspell.json +++ b/.cspell.json @@ -30,7 +30,8 @@ "mixtral", "nemo", "Reranking", - "mistralai" + "mistralai", + "OPENROUTER_API_KEY" ], "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..10d5348 100644 --- a/.dev.vars.example +++ b/.dev.vars.example @@ -1,4 +1,6 @@ OPENAI_API_KEY="" SUPABASE_URL="" SUPABASE_KEY="" -VOYAGEAI_API_KEY="" \ No newline at end of file +VOYAGEAI_API_KEY="" +OPENROUTER_API_KEY="" +UBIQUITY_OS_APP_NAME="" \ 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 771552e..34ad999 100644 --- a/.github/workflows/worker-deploy.yml +++ b/.github/workflows/worker-deploy.yml @@ -49,6 +49,7 @@ jobs: UBIQUITY_OS_APP_NAME: ${{ secrets.UBIQUITY_OS_APP_NAME }} SUPABASE_URL: ${{ secrets.SUPABASE_URL }} SUPABASE_KEY: ${{ secrets.SUPABASE_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..8dac438 100644 --- a/README.md +++ b/README.md @@ -27,11 +27,15 @@ plugins: `.dev.vars` (for local testing): +To use the Openrouter API for fetching chat history, set the `OPENROUTER_API_KEY` in the `.dev.vars` file and specify the OpenAiBase URL in the `ubiquibot-config.yml` file. Alternatively, you can set the `OPENAI_API_KEY` in the `.dev.vars` file. + ```sh -# OpenAI API key -OPENAI_API_KEY=your-api-key +OPENAI_API_KEY=your_openai_api_key +SUPABASE_URL=your_supabase_url +SUPABASE_KEY=your_supabase_key +VOYAGEAI_API_KEY=your_voyageai_api_key +OPENROUTER_API_KEY=your_openrouter_api_key UBIQUITY_OS_APP_NAME="UbiquityOS" - ``` ## 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);