Skip to content

Commit 57ce64d

Browse files
committed
new provider SiliconFlow
1 parent 4266d71 commit 57ce64d

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

packages/inference/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Currently, we support the following providers:
6060
- [Replicate](https://replicate.com)
6161
- [Sambanova](https://sambanova.ai)
6262
- [Scaleway](https://www.scaleway.com/en/generative-apis/)
63+
- [SiliconFlow](https://siliconflow.com)
6364
- [Clarifai](http://clarifai.com)
6465
- [Together](https://together.xyz)
6566
- [Baseten](https://baseten.co)
@@ -99,6 +100,7 @@ Only a subset of models are supported when requesting third-party providers. You
99100
- [Replicate supported models](https://huggingface.co/api/partners/replicate/models)
100101
- [Sambanova supported models](https://huggingface.co/api/partners/sambanova/models)
101102
- [Scaleway supported models](https://huggingface.co/api/partners/scaleway/models)
103+
- [SiliconFlow supported models](https://huggingface.co/api/partners/siliconflow/models)
102104
- [Together supported models](https://huggingface.co/api/partners/together/models)
103105
- [Baseten supported models](https://huggingface.co/api/partners/baseten/models)
104106
- [Clarifai supported models](https://huggingface.co/api/partners/clarifai/models)

packages/inference/src/lib/getProviderHelper.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as Nscale from "../providers/nscale.js";
1515
import * as OpenAI from "../providers/openai.js";
1616
import * as OvhCloud from "../providers/ovhcloud.js";
1717
import * as PublicAI from "../providers/publicai.js";
18+
import * as SiliconFlow from "../providers/siliconflow.js";
1819
import type {
1920
AudioClassificationTaskHelper,
2021
AudioToAudioTaskHelper,
@@ -169,6 +170,9 @@ export const PROVIDERS: Record<InferenceProvider, Partial<Record<InferenceTask,
169170
"text-generation": new Scaleway.ScalewayTextGenerationTask(),
170171
"feature-extraction": new Scaleway.ScalewayFeatureExtractionTask(),
171172
},
173+
siliconflow: {
174+
conversational: new SiliconFlow.SiliconFlowConversationalTask(),
175+
},
172176
together: {
173177
"text-to-image": new Together.TogetherTextToImageTask(),
174178
conversational: new Together.TogetherConversationalTask(),

packages/inference/src/providers/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const HARDCODED_MODEL_INFERENCE_MAPPING: Record<
3838
replicate: {},
3939
sambanova: {},
4040
scaleway: {},
41+
siliconflow: {},
4142
together: {},
4243
wavespeed: {},
4344
"zai-org": {},
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* SiliconFlow provider implementation
3+
*
4+
* API Documentation: https://docs.siliconflow.com
5+
*
6+
* SiliconFlow follows the OpenAI API standard for LLMs.
7+
*/
8+
import { BaseConversationalTask } from "./providerHelper.js";
9+
10+
const SILICONFLOW_API_BASE_URL = "https://api.siliconflow.com";
11+
12+
export class SiliconFlowConversationalTask extends BaseConversationalTask {
13+
constructor() {
14+
super("siliconflow", SILICONFLOW_API_BASE_URL);
15+
}
16+
}

packages/inference/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export const INFERENCE_PROVIDERS = [
6565
"replicate",
6666
"sambanova",
6767
"scaleway",
68+
"siliconflow",
6869
"together",
6970
"wavespeed",
7071
"zai-org",
@@ -102,6 +103,7 @@ export const PROVIDERS_HUB_ORGS: Record<InferenceProvider, string> = {
102103
replicate: "replicate",
103104
sambanova: "sambanovasystems",
104105
scaleway: "scaleway",
106+
siliconflow: "siliconflow",
105107
together: "togethercomputer",
106108
wavespeed: "wavespeed",
107109
"zai-org": "zai-org",

packages/inference/test/InferenceClient.spec.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,4 +2572,80 @@ describe.skip("InferenceClient", () => {
25722572
},
25732573
TIMEOUT
25742574
);
2575+
describe.concurrent(
2576+
"SiliconFlow",
2577+
() => {
2578+
const client = new InferenceClient(env.HF_SILICONFLOW_KEY ?? "dummy");
2579+
2580+
HARDCODED_MODEL_INFERENCE_MAPPING["siliconflow"] = {
2581+
"deepseek-ai/DeepSeek-R1": {
2582+
provider: "siliconflow",
2583+
hfModelId: "deepseek-ai/DeepSeek-R1",
2584+
providerId: "deepseek-ai/DeepSeek-R1",
2585+
status: "live",
2586+
task: "conversational",
2587+
},
2588+
"deepseek-ai/DeepSeek-V3": {
2589+
provider: "siliconflow",
2590+
hfModelId: "deepseek-ai/DeepSeek-V3",
2591+
providerId: "deepseek-ai/DeepSeek-V3",
2592+
status: "live",
2593+
task: "conversational",
2594+
},
2595+
};
2596+
2597+
it("chatCompletion - DeepSeek-R1", async () => {
2598+
const res = await client.chatCompletion({
2599+
model: "deepseek-ai/DeepSeek-R1",
2600+
provider: "siliconflow",
2601+
messages: [{ role: "user", content: "What is the capital of France?" }],
2602+
max_tokens: 20,
2603+
});
2604+
if (res.choices && res.choices.length > 0) {
2605+
const completion = res.choices[0].message?.content;
2606+
expect(completion).toBeDefined();
2607+
expect(typeof completion).toBe("string");
2608+
expect(completion).toMatch(/Paris/i);
2609+
}
2610+
});
2611+
2612+
it("chatCompletion - DeepSeek-V3", async () => {
2613+
const res = await client.chatCompletion({
2614+
model: "deepseek-ai/DeepSeek-V3",
2615+
provider: "siliconflow",
2616+
messages: [{ role: "user", content: "The weather today is" }],
2617+
max_tokens: 10,
2618+
});
2619+
expect(res.choices).toBeDefined();
2620+
expect(res.choices?.length).toBeGreaterThan(0);
2621+
expect(res.choices?.[0].message?.content).toBeDefined();
2622+
expect(typeof res.choices?.[0].message?.content).toBe("string");
2623+
expect(res.choices?.[0].message?.content?.length).toBeGreaterThan(0);
2624+
});
2625+
2626+
it("chatCompletion stream", async () => {
2627+
const stream = client.chatCompletionStream({
2628+
model: "deepseek-ai/DeepSeek-R1",
2629+
provider: "siliconflow",
2630+
messages: [{ role: "user", content: "Say 'this is a test'" }],
2631+
stream: true,
2632+
}) as AsyncGenerator<ChatCompletionStreamOutput>;
2633+
2634+
let fullResponse = "";
2635+
for await (const chunk of stream) {
2636+
if (chunk.choices && chunk.choices.length > 0) {
2637+
const content = chunk.choices[0].delta?.content;
2638+
if (content) {
2639+
fullResponse += content;
2640+
}
2641+
}
2642+
}
2643+
2644+
// Verify we got a meaningful response
2645+
expect(fullResponse).toBeTruthy();
2646+
expect(fullResponse.length).toBeGreaterThan(0);
2647+
});
2648+
},
2649+
TIMEOUT
2650+
);
25752651
});

0 commit comments

Comments
 (0)