Merge pull request #591 from mindcraft-bots/cerebras

Cerebras and better default models
This commit is contained in:
Max Robinson 2025-08-23 14:41:35 -05:00 committed by GitHub
commit f69c14159a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 78 additions and 14 deletions

View file

@ -12,7 +12,8 @@ Do not connect this bot to public servers with coding enabled. This project allo
- [Minecraft Java Edition](https://www.minecraft.net/en-us/store/minecraft-java-bedrock-edition-pc) (up to v1.21.1, recommend v1.21.1)
- [Node.js Installed](https://nodejs.org/) (at least v18)
- One of these: [OpenAI API Key](https://openai.com/blog/openai-api) | [Gemini API Key](https://aistudio.google.com/app/apikey) | [Anthropic API Key](https://docs.anthropic.com/claude/docs/getting-access-to-claude) | [Replicate API Key](https://replicate.com/) | [Hugging Face API Key](https://huggingface.co/) | [Groq API Key](https://console.groq.com/keys) | [Ollama Installed](https://ollama.com/download). | [Mistral API Key](https://docs.mistral.ai/getting-started/models/models_overview/) | [Qwen API Key [Intl.]](https://www.alibabacloud.com/help/en/model-studio/developer-reference/get-api-key)/[[cn]](https://help.aliyun.com/zh/model-studio/getting-started/first-api-call-to-qwen?) | [Novita AI API Key](https://novita.ai/settings?utm_source=github_mindcraft&utm_medium=github_readme&utm_campaign=link#key-management) |
- One of these: [OpenAI API Key](https://openai.com/blog/openai-api) | [Gemini API Key](https://aistudio.google.com/app/apikey) | [Anthropic API Key](https://docs.anthropic.com/claude/docs/getting-access-to-claude) | [Replicate API Key](https://replicate.com/) | [Hugging Face API Key](https://huggingface.co/) | [Groq API Key](https://console.groq.com/keys) | [Ollama Installed](https://ollama.com/download). | [Mistral API Key](https://docs.mistral.ai/getting-started/models/models_overview/) | [Qwen API Key [Intl.]](https://www.alibabacloud.com/help/en/model-studio/developer-reference/get-api-key)/[[cn]](https://help.aliyun.com/zh/model-studio/getting-started/first-api-call-to-qwen?) | [Novita AI API Key](https://novita.ai/settings?utm_source=github_mindcraft&utm_medium=github_readme&utm_campaign=link#key-management) | [Cerebras API Key](https://cloud.cerebras.ai)
## Install and Run
@ -64,6 +65,7 @@ You can configure the agent's name, model, and prompts in their profile like `an
| `glhf.chat` | `GHLF_API_KEY` | `glhf/hf:meta-llama/Llama-3.1-405B-Instruct` | [docs](https://glhf.chat/user-settings/api) |
| `hyperbolic` | `HYPERBOLIC_API_KEY` | `hyperbolic/deepseek-ai/DeepSeek-V3` | [docs](https://docs.hyperbolic.xyz/docs/getting-started) |
| `vllm` | n/a | `vllm/llama3` | n/a |
| `cerebras` | `CEREBRAS_API_KEY` | `cerebras/llama-3.3-70b` | [docs](https://inference-docs.cerebras.ai/introduction) |
If you use Ollama, to install the models used by default (generation and embedding), execute the following terminal command:
`ollama pull llama3.1 && ollama pull nomic-embed-text`

View file

@ -13,5 +13,6 @@
"GHLF_API_KEY": "",
"HYPERBOLIC_API_KEY": "",
"NOVITA_API_KEY": "",
"OPENROUTER_API_KEY": ""
"OPENROUTER_API_KEY": "",
"CEREBRAS_API_KEY": ""
}

View file

@ -2,6 +2,7 @@
"type": "module",
"dependencies": {
"@anthropic-ai/sdk": "^0.17.1",
"@cerebras/cerebras_cloud_sdk": "^1.46.0",
"@google/generative-ai": "^0.2.1",
"@huggingface/inference": "^2.8.1",
"@mistralai/mistralai": "^1.1.0",

View file

@ -1,7 +1,7 @@
{
"name": "claude",
"model": "claude-3-5-sonnet-latest",
"model": "claude-4-sonnet-latest",
"embedding": "openai"
}

View file

@ -2,7 +2,7 @@
"name": "claude_thinker",
"model": {
"model": "claude-3-7-sonnet-latest",
"model": "claude-4-sonnet-latest",
"params": {
"thinking": {
"type": "enabled",

View file

@ -1,7 +1,7 @@
{
"name": "gemini",
"model": "gemini-2.0-flash",
"model": "gemini-2.5-flash",
"cooldown": 5000
}

View file

@ -1,7 +1,7 @@
{
"name": "Grok",
"model": "grok-beta",
"model": "grok-3-mini-latest",
"embedding": "openai"
}

61
src/models/cerebras.js Normal file
View file

@ -0,0 +1,61 @@
import CerebrasSDK from '@cerebras/cerebras_cloud_sdk';
import { strictFormat } from '../utils/text.js';
import { getKey } from '../utils/keys.js';
export class Cerebras {
static prefix = 'cerebras';
constructor(model_name, url, params) {
this.model_name = model_name;
this.url = url;
this.params = params;
// Initialize client with API key
this.client = new CerebrasSDK({ apiKey: getKey('CEREBRAS_API_KEY') });
}
async sendRequest(turns, systemMessage, stop_seq = '***') {
// Format messages array
const messages = strictFormat(turns);
messages.unshift({ role: 'system', content: systemMessage });
const pack = {
model: this.model_name || 'gpt-oss-120b',
messages,
stream: false,
...(this.params || {}),
};
let res;
try {
const completion = await this.client.chat.completions.create(pack);
// OpenAI-compatible shape
res = completion.choices?.[0]?.message?.content || '';
} catch (err) {
console.error('Cerebras API error:', err);
res = 'My brain disconnected, try again.';
}
return res;
}
async sendVisionRequest(messages, systemMessage, imageBuffer) {
const imageMessages = [...messages];
imageMessages.push({
role: "user",
content: [
{ type: "text", text: systemMessage },
{
type: "image_url",
image_url: {
url: `data:image/jpeg;base64,${imageBuffer.toString('base64')}`
}
}
]
});
return this.sendRequest(imageMessages, systemMessage);
}
async embed(text) {
throw new Error('Embeddings are not supported by Cerebras.');
}
}

View file

@ -37,7 +37,7 @@ export class Gemini {
async sendRequest(turns, systemMessage) {
let model;
const modelConfig = {
model: this.model_name || "gemini-1.5-flash",
model: this.model_name || "gemini-2.5-flash",
// systemInstruction does not work bc google is trash
};
if (this.url) {

View file

@ -3,7 +3,7 @@ import { getKey } from '../utils/keys.js';
// xAI doesn't supply a SDK for their models, but fully supports OpenAI and Anthropic SDKs
export class Grok {
static prefix = 'grok';
static prefix = 'xai';
constructor(model_name, url, params) {
this.model_name = model_name;
this.url = url;
@ -20,13 +20,12 @@ export class Grok {
this.openai = new OpenAIApi(config);
}
async sendRequest(turns, systemMessage, stop_seq='***') {
async sendRequest(turns, systemMessage) {
let messages = [{'role': 'system', 'content': systemMessage}].concat(turns);
const pack = {
model: this.model_name || "grok-beta",
model: this.model_name || "grok-3-mini-latest",
messages,
stop: [stop_seq],
...(this.params || {})
};
@ -43,7 +42,7 @@ export class Grok {
catch (err) {
if ((err.message == 'Context length exceeded' || err.code == 'context_length_exceeded') && turns.length > 1) {
console.log('Context length exceeded, trying again with shorter context.');
return await this.sendRequest(turns.slice(1), systemMessage, stop_seq);
return await this.sendRequest(turns.slice(1), systemMessage);
} else if (err.message.includes('The model expects a single `text` element per message.')) {
console.log(err);
res = 'Vision is only supported by certain models.';

View file

@ -50,7 +50,7 @@ export class GroqCloudAPI {
let completion = await this.groq.chat.completions.create({
"messages": messages,
"model": this.model_name || "llama-3.3-70b-versatile",
"model": this.model_name || "qwen/qwen3-32b",
"stream": false,
"stop": stop_seq,
...(this.params || {})

View file

@ -26,7 +26,7 @@ export class Novita {
messages = strictFormat(messages);
const pack = {
model: this.model_name || "meta-llama/llama-3.1-70b-instruct",
model: this.model_name || "meta-llama/llama-4-scout-17b-16e-instruct",
messages,
stop: [stop_seq],
...(this.params || {})