From 51584246184ab6d8746cba05862f87d79f7ceed3 Mon Sep 17 00:00:00 2001 From: mintyleaf Date: Thu, 3 Jul 2025 18:49:53 +0400 Subject: [PATCH 1/3] init integration --- packages/inference/README.md | 1 + .../inference/src/lib/getProviderHelper.ts | 5 +++ packages/inference/src/providers/consts.ts | 1 + packages/inference/src/providers/swarmind.ts | 45 +++++++++++++++++++ packages/inference/src/types.ts | 1 + 5 files changed, 53 insertions(+) create mode 100644 packages/inference/src/providers/swarmind.ts diff --git a/packages/inference/README.md b/packages/inference/README.md index 0ea60b2be7..2ffee4306b 100644 --- a/packages/inference/README.md +++ b/packages/inference/README.md @@ -63,6 +63,7 @@ Currently, we support the following providers: - [Cohere](https://cohere.com) - [Cerebras](https://cerebras.ai/) - [Groq](https://groq.com) +- [Swarmind](https://swarmind.ai) To send requests to a third-party provider, you have to pass the `provider` parameter to the inference function. The default value of the `provider` parameter is "auto", which will select the first of the providers available for the model, sorted by your preferred order in https://hf.co/settings/inference-providers. diff --git a/packages/inference/src/lib/getProviderHelper.ts b/packages/inference/src/lib/getProviderHelper.ts index 147fe08ec5..2026a4bade 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 Swarmind from "../providers/swarmind.js" import type { AudioClassificationTaskHelper, AudioToAudioTaskHelper, @@ -147,6 +148,10 @@ export const PROVIDERS: Record Swarmind model ID here: + * + * https://huggingface.co/api/partners/swarmind/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 Swarmind 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 Swarmind, please open an issue on the present repo + * and we will tag Swarmind team members. + * + * Thanks! + */ + +const SWARMIND_API_BASE_URL = "https://api.swarmind.ai/lai/private"; + +export class SwarmindTextGenerationTask extends BaseTextGenerationTask { + constructor() { + super("swarmind", SWARMIND_API_BASE_URL); + } + + override makeRoute(): string { + return "/v1/chat/completions"; + } +} + +export class SwarmindConversationalTask extends BaseConversationalTask { + constructor() { + super("swarmind", SWARMIND_API_BASE_URL); + } + + override makeRoute(): string { + return "/v1/chat/completions"; + } +} diff --git a/packages/inference/src/types.ts b/packages/inference/src/types.ts index 5d6be233d8..80423a4d0f 100644 --- a/packages/inference/src/types.ts +++ b/packages/inference/src/types.ts @@ -61,6 +61,7 @@ export const INFERENCE_PROVIDERS = [ "ovhcloud", "replicate", "sambanova", + "swarmind", "together", ] as const; From f5af0fb70a8da52aa1d38d4401ea22dd5ddebe09 Mon Sep 17 00:00:00 2001 From: mintyleaf Date: Thu, 10 Jul 2025 05:06:10 +0400 Subject: [PATCH 2/3] add tests --- .../inference/test/InferenceClient.spec.ts | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/packages/inference/test/InferenceClient.spec.ts b/packages/inference/test/InferenceClient.spec.ts index 0da191ea9d..5cea9f518f 100644 --- a/packages/inference/test/InferenceClient.spec.ts +++ b/packages/inference/test/InferenceClient.spec.ts @@ -22,7 +22,7 @@ if (!env.HF_TOKEN) { console.warn("Set HF_TOKEN in the env to run the tests for better rate limits"); } -describe.skip("InferenceClient", () => { +describe.only("InferenceClient", () => { // Individual tests can be ran without providing an api key, however running all tests without an api key will result in rate limiting error. describe("backward compatibility", () => { @@ -2107,4 +2107,55 @@ describe.skip("InferenceClient", () => { }, TIMEOUT ); + describe.concurrent( + "Swarmind", + () => { + const client = new InferenceClient(env.HF_SWARMIND_KEY ?? "dummy"); + + HARDCODED_MODEL_INFERENCE_MAPPING["swarmind"] = { + "TheDrummer/Tiger-Gemma-9B-v1": { + hfModelId: "TheDrummer/Tiger-Gemma-9B-v1", + providerId: "tiger-gemma-9b-v1-i1", + status: "live", + task: "conversational", + }, + }; + + it("chatCompletion", async () => { + const res = await client.chatCompletion({ + model: "TheDrummer/Tiger-Gemma-9B-v1", + provider: "swarmind", + 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: "TheDrummer/Tiger-Gemma-9B-v1", + provider: "swarmind", + 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 df475a5f2599851bf09bedf0f591dcec4d6f9005 Mon Sep 17 00:00:00 2001 From: mintyleaf Date: Sat, 12 Jul 2025 00:32:06 +0400 Subject: [PATCH 3/3] redisable tests --- packages/inference/test/InferenceClient.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/inference/test/InferenceClient.spec.ts b/packages/inference/test/InferenceClient.spec.ts index 5cea9f518f..804560c09b 100644 --- a/packages/inference/test/InferenceClient.spec.ts +++ b/packages/inference/test/InferenceClient.spec.ts @@ -22,7 +22,7 @@ if (!env.HF_TOKEN) { console.warn("Set HF_TOKEN in the env to run the tests for better rate limits"); } -describe.only("InferenceClient", () => { +describe.skip("InferenceClient", () => { // Individual tests can be ran without providing an api key, however running all tests without an api key will result in rate limiting error. describe("backward compatibility", () => {