Skip to content
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
2 changes: 2 additions & 0 deletions packages/inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Currently, we support the following providers:
- [Fireworks AI](https://fireworks.ai)
- [HF Inference](https://huggingface.co/docs/inference-providers/providers/hf-inference)
- [Hyperbolic](https://hyperbolic.xyz)
- [NEAR AI](https://near.ai)
- [Nebius](https://studio.nebius.ai)
- [Novita](https://novita.ai)
- [Nscale](https://nscale.com)
Expand Down Expand Up @@ -93,6 +94,7 @@ Only a subset of models are supported when requesting third-party providers. You
- [Fireworks AI supported models](https://huggingface.co/api/partners/fireworks-ai/models)
- [HF Inference supported models](https://huggingface.co/api/partners/hf-inference/models)
- [Hyperbolic supported models](https://huggingface.co/api/partners/hyperbolic/models)
- [NEAR AI supported models](https://huggingface.co/api/partners/near-ai/models)
- [Nebius supported models](https://huggingface.co/api/partners/nebius/models)
- [Nscale supported models](https://huggingface.co/api/partners/nscale/models)
- [OVHcloud supported models](https://huggingface.co/api/partners/ovhcloud/models)
Expand Down
4 changes: 4 additions & 0 deletions packages/inference/src/lib/getProviderHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as Groq from "../providers/groq.js";
import * as HFInference from "../providers/hf-inference.js";
import * as Hyperbolic from "../providers/hyperbolic.js";
import * as Nebius from "../providers/nebius.js";
import * as NearAI from "../providers/near-ai.js";
import * as Novita from "../providers/novita.js";
import * as Nscale from "../providers/nscale.js";
import * as OpenAI from "../providers/openai.js";
Expand Down Expand Up @@ -136,6 +137,9 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
"text-generation": new Nebius.NebiusTextGenerationTask(),
"feature-extraction": new Nebius.NebiusFeatureExtractionTask(),
},
"near-ai": {
conversational: new NearAI.NearAIConversationalTask(),
},
novita: {
conversational: new Novita.NovitaConversationalTask(),
"text-generation": new Novita.NovitaTextGenerationTask(),
Expand Down
1 change: 1 addition & 0 deletions packages/inference/src/providers/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const HARDCODED_MODEL_INFERENCE_MAPPING: Record<
groq: {},
"hf-inference": {},
hyperbolic: {},
"near-ai": {},
nebius: {},
novita: {},
nscale: {},
Expand Down
25 changes: 25 additions & 0 deletions packages/inference/src/providers/near-ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* See the registered mapping of HF model ID => NEAR AI model ID here:
*
* https://huggingface.co/api/partners/near-ai/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at NEAR AI and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to NEAR AI, please open an issue on the present repo
* and we will tag NEAR AI team members.
*
* Thanks!
*/
import { BaseConversationalTask } from "./providerHelper.js";

const NEAR_AI_API_BASE_URL = "https://cloud-api.near.ai";

export class NearAIConversationalTask extends BaseConversationalTask {
constructor() {
super("near-ai", NEAR_AI_API_BASE_URL);
}
}
2 changes: 2 additions & 0 deletions packages/inference/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const INFERENCE_PROVIDERS = [
"groq",
"hf-inference",
"hyperbolic",
"near-ai",
"nebius",
"novita",
"nscale",
Expand Down Expand Up @@ -93,6 +94,7 @@ export const PROVIDERS_HUB_ORGS: Record<InferenceProvider, string> = {
groq: "groq",
"hf-inference": "hf-inference",
hyperbolic: "Hyperbolic",
"near-ai": "NEAR-AI",
nebius: "nebius",
novita: "novita",
nscale: "nscale",
Expand Down
53 changes: 53 additions & 0 deletions packages/inference/test/InferenceClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2578,6 +2578,59 @@ describe.skip("InferenceClient", () => {
TIMEOUT
);

describe.concurrent(
"NEAR AI",
() => {
const client = new InferenceClient(env.HF_NEAR_AI_KEY ?? "dummy");

HARDCODED_MODEL_INFERENCE_MAPPING["near-ai"] = {
"openai/gpt-oss-120b": {
provider: "near-ai",
hfModelId: "openai/gpt-oss-120b",
providerId: "openai/gpt-oss-120b",
status: "live",
task: "conversational",
},
};

it("chatCompletion", async () => {
const res = await client.chatCompletion({
model: "openai/gpt-oss-120b",
provider: "near-ai",
messages: [{ role: "user", content: "Complete this sentence with words, one plus one is equal " }],
});
if (res.choices && res.choices.length > 0) {
const completion = res.choices[0].message?.content;
expect(completion).toContain("two");
}
});

it("chatCompletion stream", async () => {
const stream = client.chatCompletionStream({
model: "openai/gpt-oss-120b",
provider: "near-ai",
messages: [{ role: "user", content: "Say this is a test" }],
stream: true,
}) as AsyncGenerator<ChatCompletionStreamOutput>;

let fullResponse = "";
for await (const chunk of stream) {
if (chunk.choices && chunk.choices.length > 0) {
const content = chunk.choices[0].delta?.content;
if (content) {
fullResponse += content;
}
}
}

// Verify we got a meaningful response
expect(fullResponse).toBeTruthy();
expect(fullResponse.length).toBeGreaterThan(0);
});
},
TIMEOUT
);

describe.concurrent(
"clarifai",
() => {
Expand Down