Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NEAR AI model provider #3275

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ SMALL_LMSTUDIO_MODEL= # Default: hermes-3-llama-3.1-8b
MEDIUM_LMSTUDIO_MODEL= # Default: hermes-3-llama-3.1-8b
LARGE_LMSTUDIO_MODEL= # Default: hermes-3-llama-3.1-8b

# NEAR AI (https://near.ai) Configuration
NEARAI_API_URL= # Default: https://api.near.ai/v1
NEARAI_API_KEY= # NEAR AI API Key (optional). If you have run `nearai login` with NEAR AI CLI, the API key will be parsed from `~/.nearai/config.json`: https://docs.near.ai/agents/quickstart/
NEARAI_MODEL=
SMALL_NEARAI_MODEL= # Default: fireworks::accounts/fireworks/models/llama-v3p2-3b-instruct
MEDIUM_NEARAI_MODEL= # Default: fireworks::accounts/fireworks/models/llama-v3p1-70b-instruct
LARGE_NEARAI_MODEL= # Default: fireworks::accounts/fireworks/models/llama-v3p1-405b-instruct

# Remaining Provider Configurations
GOOGLE_GENERATIVE_AI_API_KEY= # Gemini API key
ALI_BAILIAN_API_KEY= # Ali Bailian API Key
Expand Down
13 changes: 13 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import { hyperbolicPlugin } from "@elizaos/plugin-hyperbolic";
import Database from "better-sqlite3";
import fs from "fs";
import net from "net";
import os from "os";
import path from "path";
import { fileURLToPath } from "url";
import yargs from "yargs";
Expand Down Expand Up @@ -671,6 +672,18 @@ export function getTokenForProvider(
character.settings?.secrets?.LIVEPEER_GATEWAY_URL ||
settings.LIVEPEER_GATEWAY_URL
);
case ModelProviderName.NEARAI:
try {
const config = JSON.parse(fs.readFileSync(path.join(os.homedir(), '.nearai/config.json'), 'utf8'));
return JSON.stringify(config?.auth);
} catch (e) {
elizaLogger.warn(`Error loading NEAR AI config: ${e}`);
}
return (
character.settings?.secrets?.NEARAI_API_KEY ||
settings.NEARAI_API_KEY
);

default:
const errorMessage = `Failed to get token - unsupported model provider: ${provider}`;
elizaLogger.error(errorMessage);
Expand Down
8 changes: 8 additions & 0 deletions docs/api/enumerations/ModelProviderName.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,11 @@ Available model providers
#### Defined in

[packages/core/src/types.ts:245](https://github.com/elizaOS/eliza/blob/main/packages/core/src/types.ts#L245)

### NEARAI

> **NEARAI**: `"nearai"`

#### Defined in

[packages/core/src/types.ts:242](https://github.com/elizaOS/eliza/blob/main/packages/core/src/types.ts#L275)
4 changes: 4 additions & 0 deletions docs/api/type-aliases/Models.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ Model configurations by provider

> **livepeer**: [`Model`](Model.md)

### nearai

> **nearai**: [`Model`](Model.md)

## Defined in

[packages/core/src/types.ts:191](https://github.com/elizaOS/eliza/blob/main/packages/core/src/types.ts#L191)
3 changes: 2 additions & 1 deletion packages/core/src/generation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,8 @@ export async function generateText({
case ModelProviderName.TOGETHER:
case ModelProviderName.NINETEEN_AI:
case ModelProviderName.AKASH_CHAT_API:
case ModelProviderName.LMSTUDIO: {
case ModelProviderName.LMSTUDIO:
case ModelProviderName.NEARAI: {
elizaLogger.debug(
"Initializing OpenAI model with Cloudflare check"
);
Expand Down
35 changes: 35 additions & 0 deletions packages/core/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,41 @@ export const models: Models = {
},
},
},
[ModelProviderName.NEARAI]: {
endpoint: settings.NEARAI_API_URL || "https://api.near.ai/v1",
model: {
[ModelClass.SMALL]: {
name:
settings.SMALL_NEARAI_MODEL ||
settings.NEARAI_MODEL ||
"fireworks::accounts/fireworks/models/llama-v3p2-3b-instruct",
stop: [],
maxInputTokens: 128000,
maxOutputTokens: 8192,
temperature: 0.6,
},
[ModelClass.MEDIUM]: {
name:
settings.MEDIUM_NEARAI_MODEL ||
settings.NEARAI_MODEL ||
"fireworks::accounts/fireworks/models/llama-v3p1-70b-instruct",
stop: [],
maxInputTokens: 128000,
maxOutputTokens: 8192,
temperature: 0.6,
},
[ModelClass.LARGE]: {
name:
settings.LARGE_NEARAI_MODEL ||
settings.NEARAI_MODEL ||
"fireworks::accounts/fireworks/models/llama-v3p1-405b-instruct",
stop: [],
maxInputTokens: 128000,
maxOutputTokens: 8192,
temperature: 0.6,
},
},
},
};

export function getModelSettings(
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export type Models = {
[ModelProviderName.INFERA]: Model;
[ModelProviderName.BEDROCK]: Model;
[ModelProviderName.ATOMA]: Model;
[ModelProviderName.NEARAI]: Model;
};

/**
Expand Down Expand Up @@ -272,6 +273,7 @@ export enum ModelProviderName {
INFERA = "infera",
BEDROCK = "bedrock",
ATOMA = "atoma",
NEARAI = "nearai",
}

/**
Expand Down