diff --git a/.gitignore b/.gitignore index 6e6fd2d..a139094 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ package-lock.json scratch.js bots/**/action-code/** bots/**/ -config.json \ No newline at end of file +keys.json \ No newline at end of file diff --git a/README.md b/README.md index 6dd9c53..a7f1735 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This project allows an AI model to write/execute code on your computer that may ## Installation -Rename `config.example.json` to `config.json` and fill in the desired API keys +Rename `keys.example.json` to `keys.json` and fill in the desired API keys | API | Config Variable | Example Model name | Docs | |------|------|------|------| | OpenAI | `OPENAI_API_KEY` | `gpt-3.5-turbo` | [docs](https://platform.openai.com/docs/models) | (optionally add `OPENAI_ORG_ID`) diff --git a/config.example.json b/keys.example.json similarity index 100% rename from config.example.json rename to keys.example.json diff --git a/src/models/claude.js b/src/models/claude.js index 754cd7a..19fe053 100644 --- a/src/models/claude.js +++ b/src/models/claude.js @@ -1,5 +1,5 @@ import Anthropic from '@anthropic-ai/sdk'; -import configJson from "../../config.json" assert { type: "json" }; +import configJson from "../../keys.json" assert { type: "json" }; export class Claude { @@ -11,8 +11,10 @@ export class Claude { config.baseURL = url; if (configJson.ANTHROPIC_API_KEY) config.apiKey = configJson.ANTHROPIC_API_KEY; + else if (process.env.ANTHROPIC_API_KEY) + config.apiKey = process.env.ANTHROPIC_API_KEY; else - throw new Error('Anthropic API key missing! Make sure you set your ANTHROPIC_API_KEY in your config.json.'); + throw new Error('Anthropic API key missing! Make sure you set your ANTHROPIC_API_KEY in your keys.json.'); this.anthropic = new Anthropic(config); } diff --git a/src/models/gemini.js b/src/models/gemini.js index b0d315b..8273b96 100644 --- a/src/models/gemini.js +++ b/src/models/gemini.js @@ -1,16 +1,18 @@ import { GoogleGenerativeAI } from '@google/generative-ai'; import { toSinglePrompt } from '../utils/text.js'; -import configJson from "../../config.json" assert { type: "json" }; +import configJson from "../../keys.json" assert { type: "json" }; export class Gemini { constructor(model_name, url) { this.model_name = model_name; this.url = url; - if (!configJson.GEMINI_API_KEY) { - throw new Error('Gemini API key missing! Make sure you set your GEMINI_API_KEY in your config.json.'); - } - this.genAI = new GoogleGenerativeAI(configJson.GEMINI_API_KEY); + if (configJson.GEMINI_API_KEY) + this.genAI = new GoogleGenerativeAI(configJson.GEMINI_API_KEY); + else if (process.env.GEMINI_API_KEY) + this.genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY); + else + throw new Error('Gemini API key missing! Make sure you set your GEMINI_API_KEY in your keys.json.'); } async sendRequest(turns, systemMessage) { diff --git a/src/models/gpt.js b/src/models/gpt.js index 9f674b9..0f88ec5 100644 --- a/src/models/gpt.js +++ b/src/models/gpt.js @@ -1,5 +1,5 @@ import OpenAIApi from 'openai'; -import configJson from "../../config.json" assert { type: "json" }; +import configJson from "../../keys.json" assert { type: "json" }; export class GPT { constructor(model_name, url) { @@ -8,12 +8,18 @@ export class GPT { let config = {}; if (url) config.baseURL = url; + if (configJson.OPENAI_ORG_ID) - config.organization = configJson.OPENAI_ORG_ID; + config.apiKey = configJson.OPENAI_ORG_ID; + else if (process.env.OPENAI_ORG_ID) + config.apiKey = process.env.OPENAI_ORG_ID; + if (configJson.OPENAI_API_KEY) config.apiKey = configJson.OPENAI_API_KEY; + else if (process.env.OPENAI_API_KEY) + config.apiKey = process.env.OPENAI_API_KEY; else - throw new Error('OpenAI API key missing! Make sure you set your OPENAI_API_KEY in your config.json.'); + throw new Error('OpenAI API key missing! Make sure you set your OPENAI_API_KEY in your keys.json.'); this.openai = new OpenAIApi(config); } diff --git a/src/models/replicate.js b/src/models/replicate.js index 1059f0f..2ec30ba 100644 --- a/src/models/replicate.js +++ b/src/models/replicate.js @@ -1,6 +1,6 @@ import Replicate from 'replicate'; import { toSinglePrompt } from '../utils/text.js'; -import configJson from "../../config.json" assert { type: "json" }; +import configJson from "../../keys.json" assert { type: "json" }; // llama, mistral export class ReplicateAPI { @@ -12,13 +12,16 @@ export class ReplicateAPI { console.warn('Replicate API does not support custom URLs. Ignoring provided URL.'); } - if (!configJson.REPLICATE_API_KEY) { - throw new Error('Replicate API key missing! Make sure you set your REPLICATE_API_KEY in your config.json.'); - } - - this.replicate = new Replicate({ - auth: configJson.REPLICATE_API_KEY, - }); + if (configJson.REPLICATE_API_KEY) + this.replicate = new Replicate({ + auth: configJson.REPLICATE_API_KEY, + }); + else if (process.env.REPLICATE_API_KEY) + this.replicate = new Replicate({ + auth: process.env.REPLICATE_API_KEY, + }); + else + throw new Error('Replicate API key missing! Make sure you set your REPLICATE_API_KEY in your keys.json.'); } async sendRequest(turns, systemMessage) {