From 8544eae0b0b3235741c52631111c9a5168bf0555 Mon Sep 17 00:00:00 2001 From: jolow99 Date: Thu, 11 Sep 2025 12:38:51 +0800 Subject: [PATCH 1/3] Add publicai as inference provider --- packages/inference/src/lib/getProviderHelper.ts | 4 ++++ packages/inference/src/providers/publicai.ts | 7 +++++++ packages/inference/src/types.ts | 1 + 3 files changed, 12 insertions(+) create mode 100644 packages/inference/src/providers/publicai.ts diff --git a/packages/inference/src/lib/getProviderHelper.ts b/packages/inference/src/lib/getProviderHelper.ts index 3e95eceb8c..8ac7c32567 100644 --- a/packages/inference/src/lib/getProviderHelper.ts +++ b/packages/inference/src/lib/getProviderHelper.ts @@ -12,6 +12,7 @@ import * as Novita from "../providers/novita.js"; import * as Nscale from "../providers/nscale.js"; import * as OpenAI from "../providers/openai.js"; import * as OvhCloud from "../providers/ovhcloud.js"; +import * as PublicAI from "../providers/publicai.js"; import type { AudioClassificationTaskHelper, AudioToAudioTaskHelper, @@ -139,6 +140,9 @@ export const PROVIDERS: Record Date: Thu, 11 Sep 2025 13:10:17 +0800 Subject: [PATCH 2/3] Add test and update docs --- packages/inference/README.md | 1 + packages/inference/src/providers/consts.ts | 1 + .../inference/test/InferenceClient.spec.ts | 53 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/packages/inference/README.md b/packages/inference/README.md index ed43e0644f..06c5fa6084 100644 --- a/packages/inference/README.md +++ b/packages/inference/README.md @@ -56,6 +56,7 @@ Currently, we support the following providers: - [Novita](https://novita.ai) - [Nscale](https://nscale.com) - [OVHcloud](https://endpoints.ai.cloud.ovh.net/) +- [Public AI](https://publicai.co) - [Replicate](https://replicate.com) - [Sambanova](https://sambanova.ai) - [Scaleway](https://www.scaleway.com/en/generative-apis/) diff --git a/packages/inference/src/providers/consts.ts b/packages/inference/src/providers/consts.ts index 806e34282c..b6d27ace04 100644 --- a/packages/inference/src/providers/consts.ts +++ b/packages/inference/src/providers/consts.ts @@ -31,6 +31,7 @@ export const HARDCODED_MODEL_INFERENCE_MAPPING: Record< novita: {}, nscale: {}, openai: {}, + publicai: {}, ovhcloud: {}, replicate: {}, sambanova: {}, diff --git a/packages/inference/test/InferenceClient.spec.ts b/packages/inference/test/InferenceClient.spec.ts index 1cc60a43a9..0dc930c5b6 100644 --- a/packages/inference/test/InferenceClient.spec.ts +++ b/packages/inference/test/InferenceClient.spec.ts @@ -2238,4 +2238,57 @@ describe.skip("InferenceClient", () => { }, TIMEOUT ); + + describe.concurrent( + "PublicAI", + () => { + const client = new InferenceClient(env.HF_PUBLICAI_KEY ?? "dummy"); + + HARDCODED_MODEL_INFERENCE_MAPPING["publicai"] = { + "swiss-ai/Apertus-8B-Instruct-2509": { + provider: "publicai", + hfModelId: "swiss-ai/Apertus-8B-Instruct-2509", + providerId: "swiss-ai/apertus-8b-instruct", + status: "live", + task: "conversational", + }, + }; + + it("chatCompletion", async () => { + const res = await client.chatCompletion({ + model: "swiss-ai/Apertus-8B-Instruct-2509", + provider: "publicai", + 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: "swiss-ai/Apertus-8B-Instruct-2509", + provider: "publicai", + 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 + ); }); From c96b68bfa91038f5d08052ab1c25a274ea1fbfc2 Mon Sep 17 00:00:00 2001 From: Joseph Low Date: Fri, 12 Sep 2025 00:46:48 +0800 Subject: [PATCH 3/3] Fix linting Co-authored-by: Simon Brandeis <33657802+SBrandeis@users.noreply.github.com> --- packages/inference/src/providers/publicai.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inference/src/providers/publicai.ts b/packages/inference/src/providers/publicai.ts index 3d2e2fc06a..f1d350277b 100644 --- a/packages/inference/src/providers/publicai.ts +++ b/packages/inference/src/providers/publicai.ts @@ -4,4 +4,4 @@ export class PublicAIConversationalTask extends BaseConversationalTask { constructor() { super("publicai", "https://api.publicai.co"); } -} \ No newline at end of file +}