mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-04 22:35:35 +02:00
Merge pull request #271 from jasonhp/novita
feat: add llm vendor Novita AI
This commit is contained in:
commit
c93243dc77
3 changed files with 57 additions and 1 deletions
|
@ -13,7 +13,7 @@ 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.20.4)
|
- [Minecraft Java Edition](https://www.minecraft.net/en-us/store/minecraft-java-bedrock-edition-pc) (up to v1.21.1, recommend v1.20.4)
|
||||||
- [Node.js Installed](https://nodejs.org/) (at least v14)
|
- [Node.js Installed](https://nodejs.org/) (at least v14)
|
||||||
- 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). | [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?) |
|
- 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). | [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) |
|
||||||
|
|
||||||
## Install and Run
|
## Install and Run
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ You can configure the agent's name, model, and prompts in their profile like `an
|
||||||
| Ollama (local) | n/a | `llama3` | [docs](https://ollama.com/library) |
|
| Ollama (local) | n/a | `llama3` | [docs](https://ollama.com/library) |
|
||||||
| Groq | `GROQCLOUD_API_KEY` | `groq/mixtral-8x7b-32768` | [docs](https://console.groq.com/docs/models) |
|
| Groq | `GROQCLOUD_API_KEY` | `groq/mixtral-8x7b-32768` | [docs](https://console.groq.com/docs/models) |
|
||||||
| Hugging Face | `HUGGINGFACE_API_KEY` | `huggingface/mistralai/Mistral-Nemo-Instruct-2407` | [docs](https://huggingface.co/models) |
|
| Hugging Face | `HUGGINGFACE_API_KEY` | `huggingface/mistralai/Mistral-Nemo-Instruct-2407` | [docs](https://huggingface.co/models) |
|
||||||
|
| Novita AI | `NOVITA_API_KEY` | `gryphe/mythomax-l2-13b` | [docs](https://novita.ai/model-api/product/llm-api?utm_source=github_mindcraft&utm_medium=github_readme&utm_campaign=link) |
|
||||||
| Qwen | `QWEN_API_KEY` | `qwen-max` | [Intl.](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api)/[cn](https://help.aliyun.com/zh/model-studio/getting-started/models) |
|
| Qwen | `QWEN_API_KEY` | `qwen-max` | [Intl.](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api)/[cn](https://help.aliyun.com/zh/model-studio/getting-started/models) |
|
||||||
| xAI | `XAI_API_KEY` | `grok-beta` | [docs](https://docs.x.ai/docs) |
|
| xAI | `XAI_API_KEY` | `grok-beta` | [docs](https://docs.x.ai/docs) |
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { GPT } from '../models/gpt.js';
|
||||||
import { Claude } from '../models/claude.js';
|
import { Claude } from '../models/claude.js';
|
||||||
import { ReplicateAPI } from '../models/replicate.js';
|
import { ReplicateAPI } from '../models/replicate.js';
|
||||||
import { Local } from '../models/local.js';
|
import { Local } from '../models/local.js';
|
||||||
|
import { Novita } from '../models/novita.js';
|
||||||
import { GroqCloudAPI } from '../models/groq.js';
|
import { GroqCloudAPI } from '../models/groq.js';
|
||||||
import { HuggingFace } from '../models/huggingface.js';
|
import { HuggingFace } from '../models/huggingface.js';
|
||||||
import { Qwen } from "../models/qwen.js";
|
import { Qwen } from "../models/qwen.js";
|
||||||
|
@ -45,6 +46,8 @@ export class Prompter {
|
||||||
chat.api = 'replicate';
|
chat.api = 'replicate';
|
||||||
else if (chat.model.includes("groq/") || chat.model.includes("groqcloud/"))
|
else if (chat.model.includes("groq/") || chat.model.includes("groqcloud/"))
|
||||||
chat.api = 'groq';
|
chat.api = 'groq';
|
||||||
|
else if (chat.model.includes('novita/'))
|
||||||
|
chat.api = 'novita';
|
||||||
else if (chat.model.includes('qwen'))
|
else if (chat.model.includes('qwen'))
|
||||||
chat.api = 'qwen';
|
chat.api = 'qwen';
|
||||||
else if (chat.model.includes('grok'))
|
else if (chat.model.includes('grok'))
|
||||||
|
@ -70,6 +73,8 @@ export class Prompter {
|
||||||
}
|
}
|
||||||
else if (chat.api === 'huggingface')
|
else if (chat.api === 'huggingface')
|
||||||
this.chat_model = new HuggingFace(chat.model, chat.url);
|
this.chat_model = new HuggingFace(chat.model, chat.url);
|
||||||
|
else if (chat.api === 'novita')
|
||||||
|
this.chat_model = new Novita(chat.model.replace('novita/', ''), chat.url);
|
||||||
else if (chat.api === 'qwen')
|
else if (chat.api === 'qwen')
|
||||||
this.chat_model = new Qwen(chat.model, chat.url);
|
this.chat_model = new Qwen(chat.model, chat.url);
|
||||||
else if (chat.api === 'xai')
|
else if (chat.api === 'xai')
|
||||||
|
|
50
src/models/novita.js
Normal file
50
src/models/novita.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
import OpenAIApi from 'openai';
|
||||||
|
import { getKey } from '../utils/keys.js';
|
||||||
|
|
||||||
|
// llama, mistral
|
||||||
|
export class Novita {
|
||||||
|
constructor(model_name, url) {
|
||||||
|
this.model_name = model_name.replace('novita/', '');
|
||||||
|
this.url = url || 'https://api.novita.ai/v3/openai';
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
baseURL: this.url
|
||||||
|
};
|
||||||
|
config.apiKey = getKey('NOVITA_API_KEY');
|
||||||
|
|
||||||
|
this.openai = new OpenAIApi(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
async sendRequest(turns, systemMessage, stop_seq='***') {
|
||||||
|
let messages = [{'role': 'system', 'content': systemMessage}].concat(turns);
|
||||||
|
const pack = {
|
||||||
|
model: this.model_name || "meta-llama/llama-3.1-70b-instruct",
|
||||||
|
messages,
|
||||||
|
stop: [stop_seq],
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = null;
|
||||||
|
try {
|
||||||
|
console.log('Awaiting novita api response...')
|
||||||
|
let completion = await this.openai.chat.completions.create(pack);
|
||||||
|
if (completion.choices[0].finish_reason == 'length')
|
||||||
|
throw new Error('Context length exceeded');
|
||||||
|
console.log('Received.')
|
||||||
|
res = completion.choices[0].message.content;
|
||||||
|
}
|
||||||
|
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 sendRequest(turns.slice(1), systemMessage, stop_seq);
|
||||||
|
} else {
|
||||||
|
console.log(err);
|
||||||
|
res = 'My brain disconnected, try again.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async embed(text) {
|
||||||
|
throw new Error('Embeddings are not supported by Novita AI.');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue