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 533c5ec..810c502 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 }} 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 bdfc3e8..50e422a 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -16,7 +16,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);