diff --git a/packages/inference/README.md b/packages/inference/README.md index 664c224583..c089bb16fc 100644 --- a/packages/inference/README.md +++ b/packages/inference/README.md @@ -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) @@ -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) diff --git a/packages/inference/src/lib/getProviderHelper.ts b/packages/inference/src/lib/getProviderHelper.ts index a733a37b65..24844c99a0 100644 --- a/packages/inference/src/lib/getProviderHelper.ts +++ b/packages/inference/src/lib/getProviderHelper.ts @@ -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"; @@ -136,6 +137,9 @@ export const PROVIDERS: Record 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); + } +} diff --git a/packages/inference/src/types.ts b/packages/inference/src/types.ts index e4165914d6..d296c3de3f 100644 --- a/packages/inference/src/types.ts +++ b/packages/inference/src/types.ts @@ -56,6 +56,7 @@ export const INFERENCE_PROVIDERS = [ "groq", "hf-inference", "hyperbolic", + "near-ai", "nebius", "novita", "nscale", @@ -93,6 +94,7 @@ export const PROVIDERS_HUB_ORGS: Record = { groq: "groq", "hf-inference": "hf-inference", hyperbolic: "Hyperbolic", + "near-ai": "NEAR-AI", nebius: "nebius", novita: "novita", nscale: "nscale", diff --git a/packages/inference/test/InferenceClient.spec.ts b/packages/inference/test/InferenceClient.spec.ts index 00f9d9953f..7369630fa0 100644 --- a/packages/inference/test/InferenceClient.spec.ts +++ b/packages/inference/test/InferenceClient.spec.ts @@ -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; + + 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", () => {