@chainfuse/ai-tools 1.1.13 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models.d.mts +1 -1
- package/dist/models.mjs +4 -2
- package/dist/providers/customProviders.d.mts +21 -4
- package/dist/providers/customProviders.mjs +99 -94
- package/dist/providers/rawProviders.d.mts +3 -5
- package/dist/providers/rawProviders.mjs +23 -18
- package/dist/providers/types.d.mts +26 -12
- package/dist/registry.d.mts +40 -8
- package/dist/registry.mjs +2 -2
- package/package.json +14 -14
package/dist/models.d.mts
CHANGED
|
@@ -9,7 +9,7 @@ type ProviderLanguageModels = {
|
|
|
9
9
|
[P in ValidProviders]: Parameters<ProvidersReturnType[P]['languageModel']>[0];
|
|
10
10
|
};
|
|
11
11
|
type ProviderTextEmbeddingModels = {
|
|
12
|
-
[P in ValidProviders]: Parameters<ProvidersReturnType[P]['
|
|
12
|
+
[P in ValidProviders]: Parameters<ProvidersReturnType[P]['embeddingModel']>[0];
|
|
13
13
|
};
|
|
14
14
|
export declare class AiModel extends AiBase {
|
|
15
15
|
wrappedLanguageModel<P extends ValidProviders>(args: AiRequestConfig, provider: P, model: ProviderLanguageModels[P]): Promise<ReturnType<typeof wrapLanguageModel>>;
|
package/dist/models.mjs
CHANGED
|
@@ -14,9 +14,11 @@ export class AiModel extends AiBase {
|
|
|
14
14
|
.then(({ AiRegistry }) => new AiRegistry(this.config).registry(args))
|
|
15
15
|
.then((registry) =>
|
|
16
16
|
// @ts-expect-error types are or-ed, but correct
|
|
17
|
-
registry.
|
|
17
|
+
registry.embeddingModel(model ? `${modelOrProvider}:${model}` : modelOrProvider));
|
|
18
18
|
}
|
|
19
19
|
get middleware() {
|
|
20
|
-
return {
|
|
20
|
+
return {
|
|
21
|
+
specificationVersion: 'v3',
|
|
22
|
+
};
|
|
21
23
|
}
|
|
22
24
|
}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
+
import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
1
2
|
import { AiBase } from '../base.mjs';
|
|
2
3
|
import type { AiRequestConfig } from '../types.mjs';
|
|
3
4
|
export declare class AiCustomProviders extends AiBase {
|
|
4
5
|
oaiOpenai(args: AiRequestConfig): Promise<import("@ai-sdk/openai").OpenAIProvider>;
|
|
5
|
-
azOpenai(args: AiRequestConfig): Promise<import("
|
|
6
|
+
azOpenai(args: AiRequestConfig): Promise<import("@ai-sdk/provider").ProviderV3 & {
|
|
7
|
+
languageModel(modelId: "o1" | "o3" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "o3-mini" | "o4-mini" | "gpt-5.1" | "o1-mini"): import("@ai-sdk/provider").LanguageModelV3;
|
|
8
|
+
embeddingModel(modelId: "text-embedding-3-large" | "text-embedding-3-small"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
9
|
+
imageModel(modelId: "gpt-image-1"): import("@ai-sdk/provider").ImageModelV3;
|
|
10
|
+
transcriptionModel(modelId: string): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
11
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
12
|
+
speechModel(modelId: string): import("@ai-sdk/provider").SpeechModelV3;
|
|
13
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
14
|
+
}>;
|
|
6
15
|
anthropic(args: AiRequestConfig): Promise<import("@ai-sdk/anthropic").AnthropicProvider>;
|
|
7
|
-
|
|
8
|
-
cfWorkersAi(args: AiRequestConfig): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<"@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b", "@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b", "@cf/baai/bge-m3" | "@cf/qwen/qwen3-embedding-0.6b" | "@cf/pfnet/plamo-embedding-1b" | "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/google/embeddinggemma-300m" | "@cf/baai/bge-large-en-v1.5", string>>;
|
|
9
|
-
custom(args: AiRequestConfig): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
|
|
16
|
+
custom(args: AiRequestConfig): Promise<OpenAICompatibleProvider<string, string, string, string>>;
|
|
10
17
|
googleAi(args: AiRequestConfig): Promise<import("@ai-sdk/google").GoogleGenerativeAIProvider>;
|
|
18
|
+
private static workersAiIsRest;
|
|
19
|
+
workersAi(args: AiRequestConfig): Promise<import("@ai-sdk/provider").ProviderV3 & {
|
|
20
|
+
languageModel(modelId: "@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@cf/zai-org/glm-4.7-flash" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b"): import("@ai-sdk/provider").LanguageModelV3;
|
|
21
|
+
embeddingModel(modelId: "@cf/baai/bge-m3" | "@cf/qwen/qwen3-embedding-0.6b" | "@cf/pfnet/plamo-embedding-1b" | "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/google/embeddinggemma-300m" | "@cf/baai/bge-large-en-v1.5"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
22
|
+
imageModel(modelId: "@cf/black-forest-labs/flux-2-klein-9b" | "@cf/runwayml/stable-diffusion-v1-5-inpainting" | "@cf/black-forest-labs/flux-1-schnell" | "@cf/bytedance/stable-diffusion-xl-lightning" | "@cf/lykon/dreamshaper-8-lcm" | "@cf/leonardo/phoenix-1.0" | "@cf/stabilityai/stable-diffusion-xl-base-1.0" | "@cf/black-forest-labs/flux-2-klein-4b" | "@cf/black-forest-labs/flux-2-dev" | "@cf/runwayml/stable-diffusion-v1-5-img2img" | "@cf/leonardo/lucid-origin"): import("@ai-sdk/provider").ImageModelV3;
|
|
23
|
+
transcriptionModel(modelId: "@cf/openai/whisper" | "@cf/deepgram/flux" | "@cf/deepgram/nova-3" | "@cf/openai/whisper-tiny-en" | "@cf/openai/whisper-large-v3-turbo"): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
24
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
25
|
+
speechModel(modelId: "@cf/myshell-ai/melotts" | "@cf/deepgram/aura-2-es" | "@cf/deepgram/aura-1" | "@cf/deepgram/aura-2-en"): import("@ai-sdk/provider").SpeechModelV3;
|
|
26
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
27
|
+
}>;
|
|
11
28
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { enabledCloudflareLlmProviders } from '@chainfuse/types/ai-tools/workers-ai';
|
|
2
|
-
import { customProvider, wrapLanguageModel } from 'ai';
|
|
3
1
|
import { AiBase } from '../base.mjs';
|
|
4
2
|
import { AiRawProviders } from './rawProviders.mjs';
|
|
5
3
|
export class AiCustomProviders extends AiBase {
|
|
@@ -7,113 +5,120 @@ export class AiCustomProviders extends AiBase {
|
|
|
7
5
|
return new AiRawProviders(this.config).oaiOpenai(args);
|
|
8
6
|
}
|
|
9
7
|
async azOpenai(args) {
|
|
10
|
-
|
|
8
|
+
const fallbackProvider = await new AiRawProviders(this.config).azOpenai(args);
|
|
9
|
+
return Promise.all([import('ai'), import('@chainfuse/types/ai-tools/azure')]).then(async ([{ customProvider }, { AzureEmbeddingModels, AzureChatModels, AzureImageModels }]) => customProvider({
|
|
10
|
+
// Rewrite to carry over types (`customProvider` overwrites to `string`)
|
|
11
|
+
embeddingModels: await AzureEmbeddingModels.reduce(async (accPromise, model) => {
|
|
12
|
+
const acc = await accPromise;
|
|
13
|
+
acc[model] = fallbackProvider.embedding(model);
|
|
14
|
+
return acc;
|
|
15
|
+
}, Promise.resolve({})),
|
|
16
|
+
// Must use Azure's `.chat()` since CF Ai Gateway doesn't support Responses API
|
|
17
|
+
languageModels: await AzureChatModels.reduce(async (accPromise, model) => {
|
|
18
|
+
const acc = await accPromise;
|
|
19
|
+
acc[model] = fallbackProvider.chat(model);
|
|
20
|
+
return acc;
|
|
21
|
+
}, Promise.resolve({})),
|
|
22
|
+
imageModels: await AzureImageModels.reduce(async (accPromise, model) => {
|
|
23
|
+
const acc = await accPromise;
|
|
24
|
+
acc[model] = fallbackProvider.image(model);
|
|
25
|
+
return acc;
|
|
26
|
+
}, Promise.resolve({})),
|
|
27
|
+
// The rest are compatible as is
|
|
28
|
+
fallbackProvider: fallbackProvider,
|
|
29
|
+
}));
|
|
11
30
|
}
|
|
12
31
|
anthropic(args) {
|
|
13
32
|
return new AiRawProviders(this.config).anthropic(args);
|
|
14
33
|
}
|
|
34
|
+
custom(args) {
|
|
35
|
+
return new AiRawProviders(this.config).custom(args);
|
|
36
|
+
}
|
|
37
|
+
async googleAi(args) {
|
|
38
|
+
return new AiRawProviders(this.config).googleAi(args);
|
|
39
|
+
}
|
|
15
40
|
static workersAiIsRest(arg) {
|
|
16
41
|
return typeof arg === 'object' && 'apiToken' in arg;
|
|
17
42
|
}
|
|
18
|
-
async
|
|
43
|
+
async workersAi(args) {
|
|
19
44
|
const raw = new AiRawProviders(this.config);
|
|
20
45
|
if (AiCustomProviders.workersAiIsRest(this.config.providers.workersAi)) {
|
|
21
|
-
|
|
22
|
-
|
|
46
|
+
const fallbackProvider = await raw.restWorkersAi(args);
|
|
47
|
+
return Promise.all([import('ai'), import('@chainfuse/types/ai-tools/workers-ai')]).then(async ([{ customProvider }, { enabledCloudflareLlmEmbeddingProviders, enabledCloudflareLlmImageProviders, enabledCloudflareLlmProviders, enabledCloudflareLlmSpeechProviders, enabledCloudflareLlmTranscriptionProviders }]) => customProvider({
|
|
48
|
+
// Workers AI exposes it as `textEmbedding` but ai sdk expects `embeddingModel`
|
|
49
|
+
embeddingModels: await enabledCloudflareLlmEmbeddingProviders.reduce(async (accPromise, model) => {
|
|
50
|
+
const acc = await accPromise;
|
|
51
|
+
acc[model] = fallbackProvider.embeddingModel(model);
|
|
52
|
+
return acc;
|
|
53
|
+
}, Promise.resolve({})),
|
|
54
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
55
|
+
imageModels: await enabledCloudflareLlmImageProviders.reduce(async (accPromise, model) => {
|
|
56
|
+
const acc = await accPromise;
|
|
57
|
+
acc[model] = fallbackProvider.imageModel(model);
|
|
58
|
+
return acc;
|
|
59
|
+
}, Promise.resolve({})),
|
|
60
|
+
// Workers AI exposes it as `chat` but ai sdk expects `languageModel`
|
|
23
61
|
languageModels: await enabledCloudflareLlmProviders.reduce(async (accPromise, model) => {
|
|
24
62
|
const acc = await accPromise;
|
|
25
|
-
|
|
26
|
-
* Intercept and add in missing index property to be OpenAI compatible
|
|
27
|
-
*/
|
|
28
|
-
// @ts-expect-error override for types
|
|
29
|
-
acc[model] = wrapLanguageModel({
|
|
30
|
-
model: (await raw.restWorkersAi(args))(model),
|
|
31
|
-
middleware: [
|
|
32
|
-
/**
|
|
33
|
-
* @todo @demosjarco Rework for zod v4 error format
|
|
34
|
-
*/
|
|
35
|
-
// {
|
|
36
|
-
// wrapStream: async ({ doStream }) => {
|
|
37
|
-
// const { stream, ...rest } = await doStream();
|
|
38
|
-
// const transformStream = new TransformStream<LanguageModelV2StreamPart, LanguageModelV2StreamPart>({
|
|
39
|
-
// transform(chunk, controller) {
|
|
40
|
-
// if (chunk.type === 'error') {
|
|
41
|
-
// if (TypeValidationError.isInstance(chunk.error) && chunk.error.cause instanceof ZodError) {
|
|
42
|
-
// if (chunk.error.cause.issues.filter((issues) => issues.code === 'invalid_union')) {
|
|
43
|
-
// // Verify the specific error instead of assuming all errors
|
|
44
|
-
// const missingIndexPropertyError = chunk.error.cause.issues
|
|
45
|
-
// .filter((issues) => issues.code === 'invalid_union')
|
|
46
|
-
// .flatMap((issue) => issue.unionErrors)
|
|
47
|
-
// .flatMap((issue) => issue.issues)
|
|
48
|
-
// .filter((issue) => issue.code === 'invalid_type' && Helpers.areArraysEqual(issue.path, ['choices', 0, 'index']));
|
|
49
|
-
// if (missingIndexPropertyError.length > 0) {
|
|
50
|
-
// const newChunk = chunk.error.value as ChatCompletionChunk;
|
|
51
|
-
// newChunk.choices
|
|
52
|
-
// .filter((choice) => choice.delta.content)
|
|
53
|
-
// .forEach((choice) => {
|
|
54
|
-
// controller.enqueue({
|
|
55
|
-
// type: 'text-delta',
|
|
56
|
-
// delta: choice.delta.content!,
|
|
57
|
-
// id: '',
|
|
58
|
-
// });
|
|
59
|
-
// });
|
|
60
|
-
// }
|
|
61
|
-
// }
|
|
62
|
-
// }
|
|
63
|
-
// } else {
|
|
64
|
-
// // Passthrough untouched
|
|
65
|
-
// controller.enqueue(chunk);
|
|
66
|
-
// }
|
|
67
|
-
// },
|
|
68
|
-
// });
|
|
69
|
-
// return {
|
|
70
|
-
// stream: stream.pipeThrough(transformStream),
|
|
71
|
-
// ...rest,
|
|
72
|
-
// };
|
|
73
|
-
// },
|
|
74
|
-
// },
|
|
75
|
-
// Fix output generation where it's correct, but encapsulated in a code fence
|
|
76
|
-
{
|
|
77
|
-
wrapGenerate: async ({ doGenerate, model }) => {
|
|
78
|
-
const result = await doGenerate();
|
|
79
|
-
/**
|
|
80
|
-
* `chunkSchema` is undocumented but always present in `model` regardless of model
|
|
81
|
-
* Can't use `responseFormat` (in `params`) because it isn't always present because some models don't support that part of openai api spec.
|
|
82
|
-
*/
|
|
83
|
-
if ('chunkSchema' in model) {
|
|
84
|
-
const codeFenceStart = new RegExp(/^`{1,3}\w*\s*(?=[\[{])/i);
|
|
85
|
-
const codefenceEnd = new RegExp(/(?![\]}])\s*`{1,3}$/i);
|
|
86
|
-
return {
|
|
87
|
-
...result,
|
|
88
|
-
/**
|
|
89
|
-
* 1. trim initially to remove any leading/trailing whitespace
|
|
90
|
-
* 2. Remove start and end
|
|
91
|
-
* 3. Trim again to remove any leading/trailing whitespace
|
|
92
|
-
*/
|
|
93
|
-
content: result.content.map((content) => ({
|
|
94
|
-
...content,
|
|
95
|
-
...('text' in content && { text: content.text.trim().replace(codeFenceStart, '').replace(codefenceEnd, '').trim() }),
|
|
96
|
-
})),
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
],
|
|
103
|
-
});
|
|
63
|
+
acc[model] = fallbackProvider.chatModel(model);
|
|
104
64
|
return acc;
|
|
105
65
|
}, Promise.resolve({})),
|
|
106
|
-
fallbackProvider
|
|
107
|
-
|
|
66
|
+
...('speechModel' in fallbackProvider && {
|
|
67
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
68
|
+
speechModels: await enabledCloudflareLlmSpeechProviders.reduce(async (accPromise, model) => {
|
|
69
|
+
const acc = await accPromise;
|
|
70
|
+
acc[model] = fallbackProvider.speechModel(model);
|
|
71
|
+
return acc;
|
|
72
|
+
}, Promise.resolve({})),
|
|
73
|
+
}),
|
|
74
|
+
...('transcriptionModel' in fallbackProvider && {
|
|
75
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
76
|
+
transcriptionModels: await enabledCloudflareLlmTranscriptionProviders.reduce(async (accPromise, model) => {
|
|
77
|
+
const acc = await accPromise;
|
|
78
|
+
acc[model] = fallbackProvider.transcriptionModel(model);
|
|
79
|
+
return acc;
|
|
80
|
+
}, Promise.resolve({})),
|
|
81
|
+
}),
|
|
82
|
+
// The rest are compatible as is
|
|
83
|
+
fallbackProvider: fallbackProvider,
|
|
84
|
+
}));
|
|
108
85
|
}
|
|
109
86
|
else {
|
|
110
|
-
|
|
87
|
+
const fallbackProvider = await raw.bindingWorkersAi(args);
|
|
88
|
+
return Promise.all([import('ai'), import('@chainfuse/types/ai-tools/workers-ai')]).then(async ([{ customProvider }, { enabledCloudflareLlmEmbeddingProviders, enabledCloudflareLlmImageProviders, enabledCloudflareLlmProviders, enabledCloudflareLlmSpeechProviders, enabledCloudflareLlmTranscriptionProviders }]) => customProvider({
|
|
89
|
+
// Workers AI exposes it as `textEmbedding` but ai sdk expects `embeddingModel`
|
|
90
|
+
embeddingModels: await enabledCloudflareLlmEmbeddingProviders.reduce(async (accPromise, model) => {
|
|
91
|
+
const acc = await accPromise;
|
|
92
|
+
acc[model] = fallbackProvider.textEmbedding(model);
|
|
93
|
+
return acc;
|
|
94
|
+
}, Promise.resolve({})),
|
|
95
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
96
|
+
imageModels: await enabledCloudflareLlmImageProviders.reduce(async (accPromise, model) => {
|
|
97
|
+
const acc = await accPromise;
|
|
98
|
+
acc[model] = fallbackProvider.image(model);
|
|
99
|
+
return acc;
|
|
100
|
+
}, Promise.resolve({})),
|
|
101
|
+
// Workers AI exposes it as `chat` but ai sdk expects `languageModel`
|
|
102
|
+
languageModels: await enabledCloudflareLlmProviders.reduce(async (accPromise, model) => {
|
|
103
|
+
const acc = await accPromise;
|
|
104
|
+
acc[model] = fallbackProvider.chat(model);
|
|
105
|
+
return acc;
|
|
106
|
+
}, Promise.resolve({})),
|
|
107
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
108
|
+
speechModels: await enabledCloudflareLlmSpeechProviders.reduce(async (accPromise, model) => {
|
|
109
|
+
const acc = await accPromise;
|
|
110
|
+
acc[model] = fallbackProvider.speech(model);
|
|
111
|
+
return acc;
|
|
112
|
+
}, Promise.resolve({})),
|
|
113
|
+
// Rewrite to carry over types (`workers-ai-provider` resolves to `any`)
|
|
114
|
+
transcriptionModels: await enabledCloudflareLlmTranscriptionProviders.reduce(async (accPromise, model) => {
|
|
115
|
+
const acc = await accPromise;
|
|
116
|
+
acc[model] = fallbackProvider.transcription(model);
|
|
117
|
+
return acc;
|
|
118
|
+
}, Promise.resolve({})),
|
|
119
|
+
// The rest are compatible as is
|
|
120
|
+
fallbackProvider: fallbackProvider,
|
|
121
|
+
}));
|
|
111
122
|
}
|
|
112
123
|
}
|
|
113
|
-
custom(args) {
|
|
114
|
-
return new AiRawProviders(this.config).custom(args);
|
|
115
|
-
}
|
|
116
|
-
async googleAi(args) {
|
|
117
|
-
return new AiRawProviders(this.config).googleAi(args);
|
|
118
|
-
}
|
|
119
124
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import type { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
2
|
-
import type { cloudflareModelPossibilities } from '@chainfuse/types/ai-tools/workers-ai';
|
|
3
1
|
import { AiBase } from '../base.mjs';
|
|
4
2
|
import type { AiRequestConfig } from '../types.mjs';
|
|
5
3
|
import type { AzureOpenAIProvider } from './types.mts';
|
|
@@ -10,8 +8,8 @@ export declare class AiRawProviders extends AiBase {
|
|
|
10
8
|
oaiOpenai(args: AiRequestConfig): Promise<import("@ai-sdk/openai").OpenAIProvider>;
|
|
11
9
|
azOpenai(args: AiRequestConfig): Promise<AzureOpenAIProvider>;
|
|
12
10
|
anthropic(args: AiRequestConfig): Promise<import("@ai-sdk/anthropic").AnthropicProvider>;
|
|
13
|
-
custom(args: AiRequestConfig): Promise<OpenAICompatibleProvider<string, string, string, string>>;
|
|
11
|
+
custom(args: AiRequestConfig): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>>;
|
|
14
12
|
googleAi(args: AiRequestConfig): Promise<import("@ai-sdk/google").GoogleGenerativeAIProvider>;
|
|
15
|
-
restWorkersAi(args: AiRequestConfig): Promise<OpenAICompatibleProvider<
|
|
16
|
-
bindingWorkersAi(args: AiRequestConfig): Promise<
|
|
13
|
+
restWorkersAi(args: AiRequestConfig): Promise<import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<"@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@cf/zai-org/glm-4.7-flash" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b", "@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@cf/zai-org/glm-4.7-flash" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b", "@cf/baai/bge-m3" | "@cf/qwen/qwen3-embedding-0.6b" | "@cf/pfnet/plamo-embedding-1b" | "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/google/embeddinggemma-300m" | "@cf/baai/bge-large-en-v1.5", "@cf/black-forest-labs/flux-2-klein-9b" | "@cf/runwayml/stable-diffusion-v1-5-inpainting" | "@cf/black-forest-labs/flux-1-schnell" | "@cf/bytedance/stable-diffusion-xl-lightning" | "@cf/lykon/dreamshaper-8-lcm" | "@cf/leonardo/phoenix-1.0" | "@cf/stabilityai/stable-diffusion-xl-base-1.0" | "@cf/black-forest-labs/flux-2-klein-4b" | "@cf/black-forest-labs/flux-2-dev" | "@cf/runwayml/stable-diffusion-v1-5-img2img" | "@cf/leonardo/lucid-origin">>;
|
|
14
|
+
bindingWorkersAi(args: AiRequestConfig): Promise<import("workers-ai-provider").WorkersAI>;
|
|
17
15
|
}
|
|
@@ -671,6 +671,7 @@ export class AiRawProviders extends AiBase {
|
|
|
671
671
|
...(args.skipCache && { 'cf-aig-skip-cache': 'true' }),
|
|
672
672
|
},
|
|
673
673
|
includeUsage: true,
|
|
674
|
+
supportsStructuredOutputs: true,
|
|
674
675
|
name: 'workersai',
|
|
675
676
|
fetch: async (input, rawInit) => {
|
|
676
677
|
const startRoundTrip = performance.now();
|
|
@@ -754,24 +755,28 @@ export class AiRawProviders extends AiBase {
|
|
|
754
755
|
},
|
|
755
756
|
}));
|
|
756
757
|
}
|
|
757
|
-
|
|
758
|
-
return import('workers-ai-provider').then(async ({ createWorkersAI }) =>
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
...(args.
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
758
|
+
bindingWorkersAi(args) {
|
|
759
|
+
return import('workers-ai-provider').then(async ({ createWorkersAI }) => {
|
|
760
|
+
const idempotencyId = args.idempotencyId ?? (await BufferHelpers.generateUuid7()).utf8;
|
|
761
|
+
if (args.logging ?? this.gatewayLog)
|
|
762
|
+
console.info(new Date().toISOString(), this.chalk.rgb(...Helpers.uniqueIdColor(idempotencyId))(`[${idempotencyId}]`), this.chalk.magenta('POST'), this.chalk.magenta('apiToken' in this.config.providers.workersAi ? new URL(`https://gateway.ai.cloudflare.com/v1/${this.config.gateway.accountId}/${this.gatewayName}/workers-ai/model-placeholder`).pathname : 'Ai.run(model-placeholder)'));
|
|
763
|
+
return createWorkersAI({
|
|
764
|
+
binding: this.config.providers.workersAi,
|
|
765
|
+
gateway: {
|
|
766
|
+
id: this.gatewayName,
|
|
767
|
+
...(args.cache && { cacheTtl: typeof args.cache === 'boolean' ? (args.cache ? this.cacheTtl : 0) : args.cache }),
|
|
768
|
+
...(args.skipCache && { skipCache: true }),
|
|
769
|
+
metadata: {
|
|
770
|
+
dataspaceId: (await BufferHelpers.uuidConvert(args.dataspaceId)).utf8,
|
|
771
|
+
...(args.groupBillingId && { groupBillingId: (await BufferHelpers.uuidConvert(args.groupBillingId)).utf8 }),
|
|
772
|
+
serverInfo: JSON.stringify({
|
|
773
|
+
name: 'cloudflare',
|
|
774
|
+
}),
|
|
775
|
+
idempotencyId,
|
|
776
|
+
executor: JSON.stringify(args.executor),
|
|
777
|
+
},
|
|
773
778
|
},
|
|
774
|
-
}
|
|
775
|
-
})
|
|
779
|
+
});
|
|
780
|
+
});
|
|
776
781
|
}
|
|
777
782
|
}
|
|
@@ -1,32 +1,46 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { AzureOpenAIProvider as OriginalAzureOpenAIProvider } from '@ai-sdk/azure';
|
|
2
|
+
import type { EmbeddingModelV3, ImageModelV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
3
|
+
import type { AzureChatModels, AzureEmbeddingModels, AzureImageModels } from '@chainfuse/types/ai-tools/azure';
|
|
4
|
+
export interface AzureOpenAIProvider extends OriginalAzureOpenAIProvider {
|
|
5
|
+
(deploymentId: (typeof AzureChatModels)[number]): LanguageModelV3;
|
|
5
6
|
/**
|
|
6
7
|
* Creates an Azure OpenAI chat model for text generation.
|
|
7
8
|
*/
|
|
8
|
-
languageModel(deploymentId: AzureChatModels):
|
|
9
|
+
languageModel(deploymentId: (typeof AzureChatModels)[number]): LanguageModelV3;
|
|
9
10
|
/**
|
|
10
11
|
* Creates an Azure OpenAI chat model for text generation.
|
|
11
12
|
*/
|
|
12
|
-
chat(deploymentId: AzureChatModels):
|
|
13
|
+
chat(deploymentId: (typeof AzureChatModels)[number]): LanguageModelV3;
|
|
13
14
|
/**
|
|
14
15
|
* Creates an Azure OpenAI responses API model for text generation.
|
|
15
16
|
*/
|
|
16
|
-
responses(deploymentId: AzureChatModels):
|
|
17
|
+
responses(deploymentId: (typeof AzureChatModels)[number]): LanguageModelV3;
|
|
17
18
|
/**
|
|
18
19
|
* Creates an Azure OpenAI completion model for text generation.
|
|
19
20
|
*/
|
|
20
|
-
completion(deploymentId: AzureChatModels):
|
|
21
|
+
completion(deploymentId: (typeof AzureChatModels)[number]): LanguageModelV3;
|
|
21
22
|
/**
|
|
22
|
-
* Creates an Azure OpenAI
|
|
23
|
+
* Creates an Azure OpenAI model for text embeddings.
|
|
24
|
+
*/
|
|
25
|
+
embedding(deploymentId: (typeof AzureEmbeddingModels)[number]): EmbeddingModelV3;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an Azure OpenAI model for text embeddings.
|
|
23
28
|
*/
|
|
29
|
+
embeddingModel(deploymentId: (typeof AzureEmbeddingModels)[number]): EmbeddingModelV3;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `embedding` instead.
|
|
32
|
+
*/
|
|
33
|
+
textEmbedding(deploymentId: (typeof AzureEmbeddingModels)[number]): EmbeddingModelV3;
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated Use `embeddingModel` instead.
|
|
36
|
+
*/
|
|
37
|
+
textEmbeddingModel(deploymentId: (typeof AzureEmbeddingModels)[number]): EmbeddingModelV3;
|
|
24
38
|
/**
|
|
25
39
|
* Creates an Azure OpenAI DALL-E model for image generation.
|
|
26
40
|
*/
|
|
27
|
-
|
|
41
|
+
image(deploymentId: (typeof AzureImageModels)[number]): ImageModelV3;
|
|
28
42
|
/**
|
|
29
|
-
* Creates an Azure OpenAI model for
|
|
43
|
+
* Creates an Azure OpenAI DALL-E model for image generation.
|
|
30
44
|
*/
|
|
31
|
-
|
|
45
|
+
imageModel(deploymentId: (typeof AzureImageModels)[number]): ImageModelV3;
|
|
32
46
|
}
|
package/dist/registry.d.mts
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
import { AiBase } from './base.mjs';
|
|
2
2
|
import type { AiRequestConfig } from './types.mjs';
|
|
3
3
|
export declare class AiRegistry extends AiBase {
|
|
4
|
-
providers(args: AiRequestConfig): Promise<
|
|
4
|
+
providers(args: AiRequestConfig): Promise<{
|
|
5
5
|
openai: import("@ai-sdk/openai").OpenAIProvider;
|
|
6
|
-
azure: import("
|
|
6
|
+
azure: import("@ai-sdk/provider").ProviderV3 & {
|
|
7
|
+
languageModel(modelId: "o1" | "o3" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "o3-mini" | "o4-mini" | "gpt-5.1" | "o1-mini"): import("@ai-sdk/provider").LanguageModelV3;
|
|
8
|
+
embeddingModel(modelId: "text-embedding-3-large" | "text-embedding-3-small"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
9
|
+
imageModel(modelId: "gpt-image-1"): import("@ai-sdk/provider").ImageModelV3;
|
|
10
|
+
transcriptionModel(modelId: string): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
11
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
12
|
+
speechModel(modelId: string): import("@ai-sdk/provider").SpeechModelV3;
|
|
13
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
14
|
+
};
|
|
7
15
|
anthropic: import("@ai-sdk/anthropic").AnthropicProvider;
|
|
8
16
|
custom: import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>;
|
|
9
17
|
'google.generative-ai': import("@ai-sdk/google").GoogleGenerativeAIProvider;
|
|
10
|
-
workersai: import("@ai-sdk/
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
workersai: import("@ai-sdk/provider").ProviderV3 & {
|
|
19
|
+
languageModel(modelId: "@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@cf/zai-org/glm-4.7-flash" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b"): import("@ai-sdk/provider").LanguageModelV3;
|
|
20
|
+
embeddingModel(modelId: "@cf/baai/bge-m3" | "@cf/qwen/qwen3-embedding-0.6b" | "@cf/pfnet/plamo-embedding-1b" | "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/google/embeddinggemma-300m" | "@cf/baai/bge-large-en-v1.5"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
21
|
+
imageModel(modelId: "@cf/black-forest-labs/flux-2-klein-9b" | "@cf/runwayml/stable-diffusion-v1-5-inpainting" | "@cf/black-forest-labs/flux-1-schnell" | "@cf/bytedance/stable-diffusion-xl-lightning" | "@cf/lykon/dreamshaper-8-lcm" | "@cf/leonardo/phoenix-1.0" | "@cf/stabilityai/stable-diffusion-xl-base-1.0" | "@cf/black-forest-labs/flux-2-klein-4b" | "@cf/black-forest-labs/flux-2-dev" | "@cf/runwayml/stable-diffusion-v1-5-img2img" | "@cf/leonardo/lucid-origin"): import("@ai-sdk/provider").ImageModelV3;
|
|
22
|
+
transcriptionModel(modelId: "@cf/openai/whisper" | "@cf/deepgram/flux" | "@cf/deepgram/nova-3" | "@cf/openai/whisper-tiny-en" | "@cf/openai/whisper-large-v3-turbo"): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
23
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
24
|
+
speechModel(modelId: "@cf/myshell-ai/melotts" | "@cf/deepgram/aura-2-es" | "@cf/deepgram/aura-1" | "@cf/deepgram/aura-2-en"): import("@ai-sdk/provider").SpeechModelV3;
|
|
25
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
26
|
+
};
|
|
27
|
+
}>;
|
|
28
|
+
registry(args: AiRequestConfig): Promise<import("ai").ProviderRegistryProvider<{
|
|
13
29
|
openai: import("@ai-sdk/openai").OpenAIProvider;
|
|
14
|
-
azure: import("
|
|
30
|
+
azure: import("@ai-sdk/provider").ProviderV3 & {
|
|
31
|
+
languageModel(modelId: "o1" | "o3" | "gpt-4.1" | "gpt-4.1-mini" | "gpt-4.1-nano" | "gpt-4o" | "gpt-4o-mini" | "gpt-5" | "gpt-5-mini" | "gpt-5-nano" | "o3-mini" | "o4-mini" | "gpt-5.1" | "o1-mini"): import("@ai-sdk/provider").LanguageModelV3;
|
|
32
|
+
embeddingModel(modelId: "text-embedding-3-large" | "text-embedding-3-small"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
33
|
+
imageModel(modelId: "gpt-image-1"): import("@ai-sdk/provider").ImageModelV3;
|
|
34
|
+
transcriptionModel(modelId: string): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
35
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
36
|
+
speechModel(modelId: string): import("@ai-sdk/provider").SpeechModelV3;
|
|
37
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
38
|
+
};
|
|
15
39
|
anthropic: import("@ai-sdk/anthropic").AnthropicProvider;
|
|
16
40
|
custom: import("@ai-sdk/openai-compatible").OpenAICompatibleProvider<string, string, string, string>;
|
|
17
41
|
'google.generative-ai': import("@ai-sdk/google").GoogleGenerativeAIProvider;
|
|
18
|
-
workersai: import("@ai-sdk/
|
|
19
|
-
|
|
42
|
+
workersai: import("@ai-sdk/provider").ProviderV3 & {
|
|
43
|
+
languageModel(modelId: "@cf/openai/gpt-oss-120b" | "@cf/qwen/qwen1.5-0.5b-chat" | "@cf/google/gemma-2b-it-lora" | "@hf/nexusflow/starling-lm-7b-beta" | "@cf/meta/llama-3-8b-instruct" | "@cf/meta/llama-3.2-3b-instruct" | "@hf/thebloke/neural-chat-7b-v3-1-awq" | "@cf/meta/llama-guard-3-8b" | "@cf/meta/llama-2-7b-chat-fp16" | "@cf/mistral/mistral-7b-instruct-v0.1" | "@cf/mistral/mistral-7b-instruct-v0.2-lora" | "@cf/tinyllama/tinyllama-1.1b-chat-v1.0" | "@hf/mistral/mistral-7b-instruct-v0.2" | "@cf/fblgit/una-cybertron-7b-v2-bf16" | "@cf/deepseek-ai/deepseek-r1-distill-qwen-32b" | "@cf/thebloke/discolm-german-7b-v1-awq" | "@cf/meta/llama-2-7b-chat-int8" | "@cf/meta/llama-3.1-8b-instruct-fp8" | "@hf/thebloke/mistral-7b-instruct-v0.1-awq" | "@cf/qwen/qwen1.5-7b-chat-awq" | "@cf/meta/llama-3.2-1b-instruct" | "@cf/zai-org/glm-4.7-flash" | "@hf/thebloke/llama-2-13b-chat-awq" | "@hf/thebloke/deepseek-coder-6.7b-base-awq" | "@cf/meta-llama/llama-2-7b-chat-hf-lora" | "@cf/meta/llama-3.3-70b-instruct-fp8-fast" | "@cf/ibm-granite/granite-4.0-h-micro" | "@hf/thebloke/openhermes-2.5-mistral-7b-awq" | "@hf/thebloke/deepseek-coder-6.7b-instruct-awq" | "@cf/qwen/qwen2.5-coder-32b-instruct" | "@cf/deepseek-ai/deepseek-math-7b-instruct" | "@cf/tiiuae/falcon-7b-instruct" | "@hf/nousresearch/hermes-2-pro-mistral-7b" | "@cf/aisingapore/gemma-sea-lion-v4-27b-it" | "@cf/qwen/qwen3-30b-a3b-fp8" | "@cf/meta/llama-3.1-8b-instruct-awq" | "@hf/thebloke/zephyr-7b-beta-awq" | "@cf/google/gemma-7b-it-lora" | "@cf/qwen/qwen1.5-1.8b-chat" | "@cf/mistralai/mistral-small-3.1-24b-instruct" | "@cf/meta/llama-3-8b-instruct-awq" | "@cf/meta/llama-3.2-11b-vision-instruct" | "@cf/defog/sqlcoder-7b-2" | "@cf/microsoft/phi-2" | "@cf/openai/gpt-oss-20b" | "@hf/google/gemma-7b-it" | "@cf/qwen/qwen1.5-14b-chat-awq" | "@cf/openchat/openchat-3.5-0106" | "@cf/meta/llama-4-scout-17b-16e-instruct" | "@cf/google/gemma-3-12b-it" | "@cf/qwen/qwq-32b"): import("@ai-sdk/provider").LanguageModelV3;
|
|
44
|
+
embeddingModel(modelId: "@cf/baai/bge-m3" | "@cf/qwen/qwen3-embedding-0.6b" | "@cf/pfnet/plamo-embedding-1b" | "@cf/baai/bge-small-en-v1.5" | "@cf/baai/bge-base-en-v1.5" | "@cf/google/embeddinggemma-300m" | "@cf/baai/bge-large-en-v1.5"): import("@ai-sdk/provider").EmbeddingModelV3;
|
|
45
|
+
imageModel(modelId: "@cf/black-forest-labs/flux-2-klein-9b" | "@cf/runwayml/stable-diffusion-v1-5-inpainting" | "@cf/black-forest-labs/flux-1-schnell" | "@cf/bytedance/stable-diffusion-xl-lightning" | "@cf/lykon/dreamshaper-8-lcm" | "@cf/leonardo/phoenix-1.0" | "@cf/stabilityai/stable-diffusion-xl-base-1.0" | "@cf/black-forest-labs/flux-2-klein-4b" | "@cf/black-forest-labs/flux-2-dev" | "@cf/runwayml/stable-diffusion-v1-5-img2img" | "@cf/leonardo/lucid-origin"): import("@ai-sdk/provider").ImageModelV3;
|
|
46
|
+
transcriptionModel(modelId: "@cf/openai/whisper" | "@cf/deepgram/flux" | "@cf/deepgram/nova-3" | "@cf/openai/whisper-tiny-en" | "@cf/openai/whisper-large-v3-turbo"): import("@ai-sdk/provider").TranscriptionModelV3;
|
|
47
|
+
rerankingModel(modelId: string): import("@ai-sdk/provider").RerankingModelV3;
|
|
48
|
+
speechModel(modelId: "@cf/myshell-ai/melotts" | "@cf/deepgram/aura-2-es" | "@cf/deepgram/aura-1" | "@cf/deepgram/aura-2-en"): import("@ai-sdk/provider").SpeechModelV3;
|
|
49
|
+
videoModel(modelId: string): import("@ai-sdk/provider").Experimental_VideoModelV3;
|
|
50
|
+
};
|
|
51
|
+
}, ":">>;
|
|
20
52
|
}
|
package/dist/registry.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { AiBase } from './base.mjs';
|
|
2
2
|
export class AiRegistry extends AiBase {
|
|
3
3
|
providers(args) {
|
|
4
|
-
return import('./providers/customProviders.mjs').then(async ({ AiCustomProviders }) =>
|
|
4
|
+
return import('./providers/customProviders.mjs').then(async ({ AiCustomProviders }) => ({
|
|
5
5
|
openai: await new AiCustomProviders(this.config).oaiOpenai(args),
|
|
6
6
|
azure: await new AiCustomProviders(this.config).azOpenai(args),
|
|
7
7
|
anthropic: await new AiCustomProviders(this.config).anthropic(args),
|
|
8
8
|
custom: await new AiCustomProviders(this.config).custom(args),
|
|
9
9
|
'google.generative-ai': await new AiCustomProviders(this.config).googleAi(args),
|
|
10
|
-
workersai: await new AiCustomProviders(this.config).
|
|
10
|
+
workersai: await new AiCustomProviders(this.config).workersAi(args),
|
|
11
11
|
}));
|
|
12
12
|
}
|
|
13
13
|
registry(args) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chainfuse/ai-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "ChainFuse",
|
|
6
6
|
"homepage": "https://github.com/ChainFuse/packages/tree/main/packages/ai-tools#readme",
|
|
@@ -48,23 +48,23 @@
|
|
|
48
48
|
},
|
|
49
49
|
"prettier": "@demosjarco/prettier-config",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@ai-sdk/anthropic": "^
|
|
52
|
-
"@ai-sdk/azure": "^
|
|
53
|
-
"@ai-sdk/google": "^
|
|
54
|
-
"@ai-sdk/openai": "^
|
|
55
|
-
"@ai-sdk/openai-compatible": "^
|
|
56
|
-
"@ai-sdk/provider": "^
|
|
57
|
-
"@chainfuse/helpers": "^4.4.
|
|
58
|
-
"@chainfuse/types": "^4.2.
|
|
59
|
-
"ai": "^
|
|
51
|
+
"@ai-sdk/anthropic": "^3.0.44",
|
|
52
|
+
"@ai-sdk/azure": "^3.0.30",
|
|
53
|
+
"@ai-sdk/google": "^3.0.29",
|
|
54
|
+
"@ai-sdk/openai": "^3.0.10",
|
|
55
|
+
"@ai-sdk/openai-compatible": "^2.0.30",
|
|
56
|
+
"@ai-sdk/provider": "^3.0.3",
|
|
57
|
+
"@chainfuse/helpers": "^4.4.4",
|
|
58
|
+
"@chainfuse/types": "^4.2.18",
|
|
59
|
+
"ai": "^6.0.86",
|
|
60
60
|
"chalk": "^5.6.2",
|
|
61
61
|
"haversine-distance": "^1.2.4",
|
|
62
|
-
"workers-ai-provider": "^
|
|
62
|
+
"workers-ai-provider": "^3.1.1",
|
|
63
63
|
"zod": "^4.3.6"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@cloudflare/workers-types": "^4.
|
|
67
|
-
"openai": "^6.
|
|
66
|
+
"@cloudflare/workers-types": "^4.20260214.0",
|
|
67
|
+
"openai": "^6.22.0"
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "35ba883c1b46192bb3d11b02914ecd12bb2a2291"
|
|
70
70
|
}
|