From 96217b72075f8ccb9ec2507feb64dda756bab705 Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 9 Dec 2024 12:50:56 +1300 Subject: [PATCH 1/3] Add NanoGPT model provider --- .env.example | 1 + agent/src/index.ts | 5 +++++ packages/core/src/generation.ts | 4 +++- packages/core/src/models.ts | 16 ++++++++++++++++ packages/core/src/types.ts | 2 ++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 35f4863f0d..4a739e875e 100644 --- a/.env.example +++ b/.env.example @@ -16,6 +16,7 @@ GOOGLE_GENERATIVE_AI_API_KEY= # Gemini API key ALI_BAILIAN_API_KEY= # Ali Bailian API Key VOLENGINE_API_KEY= # VolEngine API Key +NANOGPT_API_KEY= # NanoGPT API Key # Speech Synthesis ELEVENLABS_XI_API_KEY= # API key from elevenlabs diff --git a/agent/src/index.ts b/agent/src/index.ts index e866ad264d..0f03c51811 100644 --- a/agent/src/index.ts +++ b/agent/src/index.ts @@ -270,6 +270,11 @@ export function getTokenForProvider( character.settings?.secrets?.VOLENGINE_API_KEY || settings.VOLENGINE_API_KEY ); + case ModelProviderName.NANOGPT: + return ( + character.settings?.secrets?.NANOGPT_API_KEY || + settings.NANOGPT_API_KEY + ); } } diff --git a/packages/core/src/generation.ts b/packages/core/src/generation.ts index 9642aa8d10..d87bf45e0f 100644 --- a/packages/core/src/generation.ts +++ b/packages/core/src/generation.ts @@ -129,7 +129,8 @@ export async function generateText({ case ModelProviderName.ALI_BAILIAN: case ModelProviderName.VOLENGINE: case ModelProviderName.LLAMACLOUD: - case ModelProviderName.TOGETHER: { + case ModelProviderName.TOGETHER: + case ModelProviderName.NANOGPT: { elizaLogger.debug("Initializing OpenAI model."); const openai = createOpenAI({ apiKey, baseURL: endpoint }); @@ -1214,6 +1215,7 @@ export async function handleProvider( case ModelProviderName.VOLENGINE: case ModelProviderName.LLAMACLOUD: case ModelProviderName.TOGETHER: + case ModelProviderName.NANOGPT: return await handleOpenAI(options); case ModelProviderName.ANTHROPIC: return await handleAnthropic(options); diff --git a/packages/core/src/models.ts b/packages/core/src/models.ts index ff6389c91c..02b123c918 100644 --- a/packages/core/src/models.ts +++ b/packages/core/src/models.ts @@ -384,6 +384,22 @@ export const models: Models = { [ModelClass.EMBEDDING]: "doubao-embedding", }, }, + [ModelProviderName.NANOGPT]: { + endpoint: "https://nano-gpt.com/api/v1", + settings: { + stop: [], + maxInputTokens: 128000, + maxOutputTokens: 8192, + frequency_penalty: 0.0, + presence_penalty: 0.0, + temperature: 0.6, + }, + model: { + [ModelClass.SMALL]: "gpt-4o-mini", + [ModelClass.MEDIUM]: "gpt-4o", + [ModelClass.LARGE]: "gpt-4o", + } + }, }; export function getModel(provider: ModelProviderName, type: ModelClass) { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 9b33376c45..2c09cc9b67 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -205,6 +205,7 @@ export type Models = { [ModelProviderName.GAIANET]: Model; [ModelProviderName.ALI_BAILIAN]: Model; [ModelProviderName.VOLENGINE]: Model; + [ModelProviderName.NANOGPT]: Model; }; /** @@ -230,6 +231,7 @@ export enum ModelProviderName { GAIANET = "gaianet", ALI_BAILIAN = "ali_bailian", VOLENGINE = "volengine", + NANOGPT = "nanogpt", } /** From f904d5e1e694982dc4747f18fc6ce51c9368afc6 Mon Sep 17 00:00:00 2001 From: dylan Date: Mon, 9 Dec 2024 13:00:56 +1300 Subject: [PATCH 2/3] Allow configuring NanoGPT models --- .env.example | 5 +++++ packages/core/src/models.ts | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 4a739e875e..0238ec6881 100644 --- a/.env.example +++ b/.env.example @@ -88,6 +88,11 @@ MEDIUM_GROQ_MODEL= # Default: llama-3.3-70b-versatile LARGE_GROQ_MODEL= # Default: llama-3.2-90b-vision-preview EMBEDDING_GROQ_MODEL= # Default: llama-3.1-8b-instant +# NanoGPT Configuration +SMALL_NANOGPT_MODEL= # Default: gpt-4o-mini +MEDIUM_NANOGPT_MODEL= # Default: gpt-4o +LARGE_NANOGPT_MODEL= # Default: gpt-4o + #LlamaLocal Configuration LLAMALOCAL_PATH= # Default: "" which is the current directory in plugin-node/dist/ which gets destroyed and recreated on every build diff --git a/packages/core/src/models.ts b/packages/core/src/models.ts index 02b123c918..1af77cb5b2 100644 --- a/packages/core/src/models.ts +++ b/packages/core/src/models.ts @@ -395,9 +395,9 @@ export const models: Models = { temperature: 0.6, }, model: { - [ModelClass.SMALL]: "gpt-4o-mini", - [ModelClass.MEDIUM]: "gpt-4o", - [ModelClass.LARGE]: "gpt-4o", + [ModelClass.SMALL]: settings.SMALL_NANOGPT_MODEL || "gpt-4o-mini", + [ModelClass.MEDIUM]: settings.MEDIUM_NANOGPT_MODEL || "gpt-4o", + [ModelClass.LARGE]: settings.LARGE_NANOGPT_MODEL || "gpt-4o", } }, }; From e9a96997979e4af85f22bd40a7700b14b19fb433 Mon Sep 17 00:00:00 2001 From: Odilitime Date: Tue, 10 Dec 2024 11:23:37 -0800 Subject: [PATCH 3/3] Remove duplicate TOGETHER on switch --- packages/core/src/generation.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/generation.ts b/packages/core/src/generation.ts index b140209772..26ff7eaccc 100644 --- a/packages/core/src/generation.ts +++ b/packages/core/src/generation.ts @@ -129,7 +129,6 @@ export async function generateText({ case ModelProviderName.ALI_BAILIAN: case ModelProviderName.VOLENGINE: case ModelProviderName.LLAMACLOUD: - case ModelProviderName.TOGETHER: case ModelProviderName.NANOGPT: case ModelProviderName.HYPERBOLIC: case ModelProviderName.TOGETHER: {