mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-03-28 14:56:24 +01:00
Renamed config.json to keys.json and added check for env var if keys.json isn't found
This commit is contained in:
parent
b17f4806a3
commit
fe621ebcf8
7 changed files with 33 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,4 +4,4 @@ package-lock.json
|
|||
scratch.js
|
||||
bots/**/action-code/**
|
||||
bots/**/
|
||||
config.json
|
||||
keys.json
|
|
@ -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`)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue