Skip to content

Commit fe621eb

Browse files
committed
Renamed config.json to keys.json and added check for env var if keys.json isn't found
1 parent b17f480 commit fe621eb

7 files changed

Lines changed: 33 additions & 20 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ package-lock.json
44
scratch.js
55
bots/**/action-code/**
66
bots/**/
7-
config.json
7+
keys.json

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This project allows an AI model to write/execute code on your computer that may
1414

1515
## Installation
1616

17-
Rename `config.example.json` to `config.json` and fill in the desired API keys
17+
Rename `keys.example.json` to `keys.json` and fill in the desired API keys
1818
| API | Config Variable | Example Model name | Docs |
1919
|------|------|------|------|
2020
| OpenAI | `OPENAI_API_KEY` | `gpt-3.5-turbo` | [docs](https://platform.openai.com/docs/models) | (optionally add `OPENAI_ORG_ID`)
File renamed without changes.

‎src/models/claude.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Anthropic from '@anthropic-ai/sdk';
2-
import configJson from "../../config.json" assert { type: "json" };
2+
import configJson from "../../keys.json" assert { type: "json" };
33

44

55
export class Claude {
@@ -11,8 +11,10 @@ export class Claude {
1111
config.baseURL = url;
1212
if (configJson.ANTHROPIC_API_KEY)
1313
config.apiKey = configJson.ANTHROPIC_API_KEY;
14+
else if (process.env.ANTHROPIC_API_KEY)
15+
config.apiKey = process.env.ANTHROPIC_API_KEY;
1416
else
15-
throw new Error('Anthropic API key missing! Make sure you set your ANTHROPIC_API_KEY in your config.json.');
17+
throw new Error('Anthropic API key missing! Make sure you set your ANTHROPIC_API_KEY in your keys.json.');
1618

1719
this.anthropic = new Anthropic(config);
1820
}

‎src/models/gemini.js‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import { GoogleGenerativeAI } from '@google/generative-ai';
22
import { toSinglePrompt } from '../utils/text.js';
3-
import configJson from "../../config.json" assert { type: "json" };
3+
import configJson from "../../keys.json" assert { type: "json" };
44

55
export class Gemini {
66
constructor(model_name, url) {
77
this.model_name = model_name;
88
this.url = url;
99

10-
if (!configJson.GEMINI_API_KEY) {
11-
throw new Error('Gemini API key missing! Make sure you set your GEMINI_API_KEY in your config.json.');
12-
}
13-
this.genAI = new GoogleGenerativeAI(configJson.GEMINI_API_KEY);
10+
if (configJson.GEMINI_API_KEY)
11+
this.genAI = new GoogleGenerativeAI(configJson.GEMINI_API_KEY);
12+
else if (process.env.GEMINI_API_KEY)
13+
this.genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
14+
else
15+
throw new Error('Gemini API key missing! Make sure you set your GEMINI_API_KEY in your keys.json.');
1416
}
1517

1618
async sendRequest(turns, systemMessage) {

‎src/models/gpt.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import OpenAIApi from 'openai';
2-
import configJson from "../../config.json" assert { type: "json" };
2+
import configJson from "../../keys.json" assert { type: "json" };
33

44
export class GPT {
55
constructor(model_name, url) {
@@ -8,12 +8,18 @@ export class GPT {
88
let config = {};
99
if (url)
1010
config.baseURL = url;
11+
1112
if (configJson.OPENAI_ORG_ID)
12-
config.organization = configJson.OPENAI_ORG_ID;
13+
config.apiKey = configJson.OPENAI_ORG_ID;
14+
else if (process.env.OPENAI_ORG_ID)
15+
config.apiKey = process.env.OPENAI_ORG_ID;
16+
1317
if (configJson.OPENAI_API_KEY)
1418
config.apiKey = configJson.OPENAI_API_KEY;
19+
else if (process.env.OPENAI_API_KEY)
20+
config.apiKey = process.env.OPENAI_API_KEY;
1521
else
16-
throw new Error('OpenAI API key missing! Make sure you set your OPENAI_API_KEY in your config.json.');
22+
throw new Error('OpenAI API key missing! Make sure you set your OPENAI_API_KEY in your keys.json.');
1723

1824
this.openai = new OpenAIApi(config);
1925
}

‎src/models/replicate.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Replicate from 'replicate';
22
import { toSinglePrompt } from '../utils/text.js';
3-
import configJson from "../../config.json" assert { type: "json" };
3+
import configJson from "../../keys.json" assert { type: "json" };
44

55
// llama, mistral
66
export class ReplicateAPI {
@@ -12,13 +12,16 @@ export class ReplicateAPI {
1212
console.warn('Replicate API does not support custom URLs. Ignoring provided URL.');
1313
}
1414

15-
if (!configJson.REPLICATE_API_KEY) {
16-
throw new Error('Replicate API key missing! Make sure you set your REPLICATE_API_KEY in your config.json.');
17-
}
18-
19-
this.replicate = new Replicate({
20-
auth: configJson.REPLICATE_API_KEY,
21-
});
15+
if (configJson.REPLICATE_API_KEY)
16+
this.replicate = new Replicate({
17+
auth: configJson.REPLICATE_API_KEY,
18+
});
19+
else if (process.env.REPLICATE_API_KEY)
20+
this.replicate = new Replicate({
21+
auth: process.env.REPLICATE_API_KEY,
22+
});
23+
else
24+
throw new Error('Replicate API key missing! Make sure you set your REPLICATE_API_KEY in your keys.json.');
2225
}
2326

2427
async sendRequest(turns, systemMessage) {

0 commit comments

Comments
 (0)