@ai-sdk/cerebras 3.0.59 → 3.0.61
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/CHANGELOG.md +20 -0
- package/dist/index.d.ts +86 -82
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +136 -186
- package/dist/index.js.map +1 -1
- package/docs/40-cerebras.mdx +2 -2
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @ai-sdk/cerebras
|
|
2
2
|
|
|
3
|
+
## 3.0.61
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [8c65988]
|
|
8
|
+
- Updated dependencies [527a163]
|
|
9
|
+
- @ai-sdk/provider@4.0.21
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.53
|
|
11
|
+
- @ai-sdk/openai-compatible@3.0.61
|
|
12
|
+
|
|
13
|
+
## 3.0.60
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- ede5b89: chore: migrate package builds from tsup to tsdown
|
|
18
|
+
- Updated dependencies [ede5b89]
|
|
19
|
+
- @ai-sdk/openai-compatible@3.0.60
|
|
20
|
+
- @ai-sdk/provider@4.0.20
|
|
21
|
+
- @ai-sdk/provider-utils@5.0.52
|
|
22
|
+
|
|
3
23
|
## 3.0.59
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,93 +1,97 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FetchFunction } from
|
|
3
|
-
import { z } from
|
|
4
|
-
|
|
1
|
+
import { LanguageModelV4, ProviderV4 } from "@ai-sdk/provider";
|
|
2
|
+
import { FetchFunction } from "@ai-sdk/provider-utils";
|
|
3
|
+
import { z } from "zod/v4";
|
|
4
|
+
//#region src/cerebras-chat-options.d.ts
|
|
5
5
|
type CerebrasChatModelId = 'gpt-oss-120b' | 'gemma-4-31b' | (string & {});
|
|
6
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/cerebras-provider.d.ts
|
|
7
8
|
declare const cerebrasErrorSchema: z.ZodObject<{
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
message: z.ZodString;
|
|
10
|
+
type: z.ZodString;
|
|
11
|
+
param: z.ZodString;
|
|
12
|
+
code: z.ZodString;
|
|
12
13
|
}, z.core.$strip>;
|
|
13
14
|
type CerebrasErrorData = z.infer<typeof cerebrasErrorSchema>;
|
|
14
15
|
interface CerebrasProviderSettings {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Cerebras API key.
|
|
18
|
+
*/
|
|
19
|
+
apiKey?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Base URL for the API calls.
|
|
22
|
+
*/
|
|
23
|
+
baseURL?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Custom headers to include in the requests.
|
|
26
|
+
*/
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
30
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
31
|
+
*/
|
|
32
|
+
fetch?: FetchFunction;
|
|
32
33
|
}
|
|
33
34
|
interface CerebrasProvider extends ProviderV4 {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Creates a Cerebras model for text generation.
|
|
37
|
+
*/
|
|
38
|
+
(modelId: CerebrasChatModelId): LanguageModelV4;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a Cerebras model for text generation.
|
|
41
|
+
*/
|
|
42
|
+
languageModel(modelId: CerebrasChatModelId): LanguageModelV4;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a Cerebras chat model for text generation.
|
|
45
|
+
*/
|
|
46
|
+
chat(modelId: CerebrasChatModelId): LanguageModelV4;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use `embeddingModel` instead.
|
|
49
|
+
*/
|
|
50
|
+
textEmbeddingModel(modelId: string): never;
|
|
50
51
|
}
|
|
51
|
-
declare function createCerebras(options?: CerebrasProviderSettings): CerebrasProvider;
|
|
52
|
-
declare const cerebras: CerebrasProvider;
|
|
53
|
-
|
|
52
|
+
export declare function createCerebras(options?: CerebrasProviderSettings): CerebrasProvider;
|
|
53
|
+
export declare const cerebras: CerebrasProvider;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/cerebras-chat-language-model-options.d.ts
|
|
54
56
|
declare const cerebrasLanguageModelChatOptions: z.ZodObject<{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
57
|
+
user: z.ZodOptional<z.ZodString>;
|
|
58
|
+
strictJsonSchema: z.ZodOptional<z.ZodBoolean>;
|
|
59
|
+
parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
|
|
60
|
+
logprobs: z.ZodOptional<z.ZodBoolean>;
|
|
61
|
+
topLogprobs: z.ZodOptional<z.ZodNumber>;
|
|
62
|
+
logitBias: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
63
|
+
serviceTier: z.ZodOptional<z.ZodEnum<{
|
|
64
|
+
default: "default";
|
|
65
|
+
auto: "auto";
|
|
66
|
+
flex: "flex";
|
|
67
|
+
priority: "priority";
|
|
68
|
+
}>>;
|
|
69
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
70
|
+
none: "none";
|
|
71
|
+
low: "low";
|
|
72
|
+
medium: "medium";
|
|
73
|
+
high: "high";
|
|
74
|
+
}>>;
|
|
75
|
+
reasoningFormat: z.ZodOptional<z.ZodEnum<{
|
|
76
|
+
none: "none";
|
|
77
|
+
parsed: "parsed";
|
|
78
|
+
text_parsed: "text_parsed";
|
|
79
|
+
raw: "raw";
|
|
80
|
+
hidden: "hidden";
|
|
81
|
+
}>>;
|
|
82
|
+
prediction: z.ZodOptional<z.ZodObject<{
|
|
83
|
+
type: z.ZodLiteral<"content">;
|
|
84
|
+
content: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodObject<{
|
|
85
|
+
type: z.ZodLiteral<"text">;
|
|
86
|
+
text: z.ZodString;
|
|
87
|
+
}, z.core.$strip>>]>;
|
|
88
|
+
}, z.core.$strip>>;
|
|
89
|
+
promptCacheKey: z.ZodOptional<z.ZodString>;
|
|
88
90
|
}, z.core.$strip>;
|
|
89
91
|
type CerebrasLanguageModelChatOptions = z.infer<typeof cerebrasLanguageModelChatOptions>;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/version.d.ts
|
|
94
|
+
export declare const VERSION: string;
|
|
95
|
+
//#endregion
|
|
96
|
+
export type { CerebrasErrorData, CerebrasLanguageModelChatOptions, CerebrasProvider, CerebrasProviderSettings };
|
|
97
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/cerebras-chat-options.ts","../src/cerebras-provider.ts","../src/cerebras-chat-language-model-options.ts","../src/version.ts"],"mappings":";;;;KACY;;;cCiBN,qBAAmB,EAAA;;;;;GAKvB,EAAA,KAAA;KAEU,oBAAoB,EAAE,aAAa;UAkE9B;;;;EAIf;;;;EAIA;;;;EAIA,UAAU;;;;;EAKV,QAAQ;;UAGO,yBAAyB;;;;GAIvC,SAAS,sBAAsB;;;;EAKhC,cAAc,SAAS,sBAAsB;;;;EAK7C,KAAK,SAAS,sBAAsB;;;;EAKpC,mBAAmB;;wBAGL,eACd,UAAS,2BACR;qBA+CU,UAAQ;;;cClLR,kCAAgC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsB3C,EAAA,KAAA;KAEU,mCAAmC,EAAE,aACxC;;;qBC3BI"}
|
package/dist/index.js
CHANGED
|
@@ -1,195 +1,145 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
NoSuchModelError
|
|
4
|
-
} from "@ai-sdk/provider";
|
|
5
|
-
import {
|
|
6
|
-
loadApiKey,
|
|
7
|
-
withoutTrailingSlash,
|
|
8
|
-
withUserAgentSuffix
|
|
9
|
-
} from "@ai-sdk/provider-utils";
|
|
10
|
-
|
|
11
|
-
// src/cerebras-chat-language-model.ts
|
|
1
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
2
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, loadApiKey, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash } from "@ai-sdk/provider-utils";
|
|
12
3
|
import { OpenAICompatibleChatLanguageModel } from "@ai-sdk/openai-compatible";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} from "@ai-sdk/provider-utils";
|
|
18
|
-
function isStructuredOutputWithToolCallsFinishReason({
|
|
19
|
-
rawFinishReason,
|
|
20
|
-
hasText,
|
|
21
|
-
responseFormatType
|
|
22
|
-
}) {
|
|
23
|
-
return responseFormatType === "json" && rawFinishReason === "tool_calls" && hasText;
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
//#region src/cerebras-chat-language-model.ts
|
|
6
|
+
function isStructuredOutputWithToolCallsFinishReason({ rawFinishReason, hasText, responseFormatType }) {
|
|
7
|
+
return responseFormatType === "json" && rawFinishReason === "tool_calls" && hasText;
|
|
24
8
|
}
|
|
25
|
-
var CerebrasChatLanguageModel = class
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
unified: "stop"
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (options.responseFormat?.type === "json" && hasText && (part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "tool-input-end" || part.type === "tool-call")) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
controller.enqueue(part);
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
9
|
+
var CerebrasChatLanguageModel = class CerebrasChatLanguageModel extends OpenAICompatibleChatLanguageModel {
|
|
10
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
11
|
+
return serializeModelOptions({
|
|
12
|
+
modelId: model.modelId,
|
|
13
|
+
config: model.config
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
17
|
+
return new CerebrasChatLanguageModel(options.modelId, options.config);
|
|
18
|
+
}
|
|
19
|
+
async doGenerate(options) {
|
|
20
|
+
const result = await super.doGenerate(options);
|
|
21
|
+
if (!isStructuredOutputWithToolCallsFinishReason({
|
|
22
|
+
rawFinishReason: result.finishReason.raw,
|
|
23
|
+
hasText: result.content.some((part) => part.type === "text" && part.text.length > 0),
|
|
24
|
+
responseFormatType: options.responseFormat?.type
|
|
25
|
+
})) return result;
|
|
26
|
+
return {
|
|
27
|
+
...result,
|
|
28
|
+
content: result.content.filter((part) => part.type !== "tool-call"),
|
|
29
|
+
finishReason: {
|
|
30
|
+
...result.finishReason,
|
|
31
|
+
unified: "stop"
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async doStream(options) {
|
|
36
|
+
const result = await super.doStream(options);
|
|
37
|
+
let hasText = false;
|
|
38
|
+
return {
|
|
39
|
+
...result,
|
|
40
|
+
stream: result.stream.pipeThrough(new TransformStream({ transform(part, controller) {
|
|
41
|
+
if (part.type === "text-delta" && part.delta.length > 0) hasText = true;
|
|
42
|
+
if (part.type === "finish" && isStructuredOutputWithToolCallsFinishReason({
|
|
43
|
+
rawFinishReason: part.finishReason.raw,
|
|
44
|
+
hasText,
|
|
45
|
+
responseFormatType: options.responseFormat?.type
|
|
46
|
+
})) {
|
|
47
|
+
controller.enqueue({
|
|
48
|
+
...part,
|
|
49
|
+
finishReason: {
|
|
50
|
+
...part.finishReason,
|
|
51
|
+
unified: "stop"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (options.responseFormat?.type === "json" && hasText && (part.type === "tool-input-start" || part.type === "tool-input-delta" || part.type === "tool-input-end" || part.type === "tool-call")) return;
|
|
57
|
+
controller.enqueue(part);
|
|
58
|
+
} }))
|
|
59
|
+
};
|
|
60
|
+
}
|
|
91
61
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
});
|
|
106
|
-
var cerebrasErrorStructure = {
|
|
107
|
-
errorSchema: cerebrasErrorSchema,
|
|
108
|
-
errorToMessage: (data) => data.message
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/version.ts
|
|
64
|
+
const VERSION = "3.0.61";
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/cerebras-provider.ts
|
|
67
|
+
const cerebrasErrorStructure = {
|
|
68
|
+
errorSchema: z.object({
|
|
69
|
+
message: z.string(),
|
|
70
|
+
type: z.string(),
|
|
71
|
+
param: z.string(),
|
|
72
|
+
code: z.string()
|
|
73
|
+
}),
|
|
74
|
+
errorToMessage: (data) => data.message
|
|
109
75
|
};
|
|
76
|
+
/**
|
|
77
|
+
* Cerebras expects assistant reasoning history in the `reasoning` field, while
|
|
78
|
+
* the shared OpenAI-compatible converter serializes it as `reasoning_content`.
|
|
79
|
+
*/
|
|
110
80
|
function transformCerebrasRequestBody(args) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
...logitBias !== void 0 && { logit_bias: logitBias },
|
|
131
|
-
...serviceTier !== void 0 && { service_tier: serviceTier },
|
|
132
|
-
...reasoningFormat !== void 0 && {
|
|
133
|
-
reasoning_format: reasoningFormat
|
|
134
|
-
},
|
|
135
|
-
...promptCacheKey !== void 0 && {
|
|
136
|
-
prompt_cache_key: promptCacheKey
|
|
137
|
-
},
|
|
138
|
-
messages: Array.isArray(args.messages) ? args.messages.map((message) => {
|
|
139
|
-
if (message == null || typeof message !== "object" || message.role !== "assistant" || !("reasoning_content" in message)) {
|
|
140
|
-
return message;
|
|
141
|
-
}
|
|
142
|
-
const { reasoning_content, ...rest } = message;
|
|
143
|
-
return {
|
|
144
|
-
...rest,
|
|
145
|
-
...!("reasoning" in rest) && reasoning_content !== void 0 ? { reasoning: reasoning_content } : {}
|
|
146
|
-
};
|
|
147
|
-
}) : args.messages
|
|
148
|
-
};
|
|
81
|
+
const { max_tokens: maxTokens, parallelToolCalls, topLogprobs, logitBias, serviceTier, reasoningFormat, promptCacheKey, ...restArgs } = args;
|
|
82
|
+
return {
|
|
83
|
+
...restArgs,
|
|
84
|
+
...maxTokens !== void 0 && { max_completion_tokens: maxTokens },
|
|
85
|
+
...parallelToolCalls !== void 0 && { parallel_tool_calls: parallelToolCalls },
|
|
86
|
+
...topLogprobs !== void 0 && { top_logprobs: topLogprobs },
|
|
87
|
+
...logitBias !== void 0 && { logit_bias: logitBias },
|
|
88
|
+
...serviceTier !== void 0 && { service_tier: serviceTier },
|
|
89
|
+
...reasoningFormat !== void 0 && { reasoning_format: reasoningFormat },
|
|
90
|
+
...promptCacheKey !== void 0 && { prompt_cache_key: promptCacheKey },
|
|
91
|
+
messages: Array.isArray(args.messages) ? args.messages.map((message) => {
|
|
92
|
+
if (message == null || typeof message !== "object" || message.role !== "assistant" || !("reasoning_content" in message)) return message;
|
|
93
|
+
const { reasoning_content, ...rest } = message;
|
|
94
|
+
return {
|
|
95
|
+
...rest,
|
|
96
|
+
...!("reasoning" in rest) && reasoning_content !== void 0 ? { reasoning: reasoning_content } : {}
|
|
97
|
+
};
|
|
98
|
+
}) : args.messages
|
|
99
|
+
};
|
|
149
100
|
}
|
|
150
101
|
function createCerebras(options = {}) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
102
|
+
const baseURL = withoutTrailingSlash(options.baseURL ?? "https://api.cerebras.ai/v1");
|
|
103
|
+
const getHeaders = () => withUserAgentSuffix({
|
|
104
|
+
Authorization: `Bearer ${loadApiKey({
|
|
105
|
+
apiKey: options.apiKey,
|
|
106
|
+
environmentVariableName: "CEREBRAS_API_KEY",
|
|
107
|
+
description: "Cerebras API key"
|
|
108
|
+
})}`,
|
|
109
|
+
...options.headers
|
|
110
|
+
}, `ai-sdk-cerebras/${VERSION}`);
|
|
111
|
+
const createLanguageModel = (modelId) => {
|
|
112
|
+
return new CerebrasChatLanguageModel(modelId, {
|
|
113
|
+
provider: `cerebras.chat`,
|
|
114
|
+
url: ({ path }) => `${baseURL}${path}`,
|
|
115
|
+
headers: getHeaders,
|
|
116
|
+
fetch: options.fetch,
|
|
117
|
+
errorStructure: cerebrasErrorStructure,
|
|
118
|
+
supportsStructuredOutputs: true,
|
|
119
|
+
transformRequestBody: transformCerebrasRequestBody
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
const provider = (modelId) => createLanguageModel(modelId);
|
|
123
|
+
provider.specificationVersion = "v4";
|
|
124
|
+
provider.languageModel = createLanguageModel;
|
|
125
|
+
provider.chat = createLanguageModel;
|
|
126
|
+
provider.embeddingModel = (modelId) => {
|
|
127
|
+
throw new NoSuchModelError({
|
|
128
|
+
modelId,
|
|
129
|
+
modelType: "embeddingModel"
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
provider.textEmbeddingModel = provider.embeddingModel;
|
|
133
|
+
provider.imageModel = (modelId) => {
|
|
134
|
+
throw new NoSuchModelError({
|
|
135
|
+
modelId,
|
|
136
|
+
modelType: "imageModel"
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
return provider;
|
|
188
140
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
createCerebras
|
|
194
|
-
};
|
|
141
|
+
const cerebras = createCerebras();
|
|
142
|
+
//#endregion
|
|
143
|
+
export { VERSION, cerebras, createCerebras };
|
|
144
|
+
|
|
195
145
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cerebras-provider.ts","../src/cerebras-chat-language-model.ts","../src/version.ts"],"sourcesContent":["import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { CerebrasChatLanguageModel } from './cerebras-chat-language-model';\nimport type { CerebrasChatModelId } from './cerebras-chat-options';\nimport { z } from 'zod/v4';\nimport { VERSION } from './version';\n\n// Add error schema and structure\nconst cerebrasErrorSchema = z.object({\n message: z.string(),\n type: z.string(),\n param: z.string(),\n code: z.string(),\n});\n\nexport type CerebrasErrorData = z.infer<typeof cerebrasErrorSchema>;\n\nconst cerebrasErrorStructure: ProviderErrorStructure<CerebrasErrorData> = {\n errorSchema: cerebrasErrorSchema,\n errorToMessage: data => data.message,\n};\n\n/**\n * Cerebras expects assistant reasoning history in the `reasoning` field, while\n * the shared OpenAI-compatible converter serializes it as `reasoning_content`.\n */\nfunction transformCerebrasRequestBody(\n args: Record<string, any>,\n): Record<string, any> {\n const {\n max_tokens: maxTokens,\n parallelToolCalls,\n topLogprobs,\n logitBias,\n serviceTier,\n reasoningFormat,\n promptCacheKey,\n ...restArgs\n } = args;\n\n return {\n ...restArgs,\n ...(maxTokens !== undefined && {\n max_completion_tokens: maxTokens,\n }),\n ...(parallelToolCalls !== undefined && {\n parallel_tool_calls: parallelToolCalls,\n }),\n ...(topLogprobs !== undefined && { top_logprobs: topLogprobs }),\n ...(logitBias !== undefined && { logit_bias: logitBias }),\n ...(serviceTier !== undefined && { service_tier: serviceTier }),\n ...(reasoningFormat !== undefined && {\n reasoning_format: reasoningFormat,\n }),\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n messages: Array.isArray(args.messages)\n ? args.messages.map(message => {\n if (\n message == null ||\n typeof message !== 'object' ||\n message.role !== 'assistant' ||\n !('reasoning_content' in message)\n ) {\n return message;\n }\n\n const { reasoning_content, ...rest } = message;\n\n return {\n ...rest,\n ...(!('reasoning' in rest) && reasoning_content !== undefined\n ? { reasoning: reasoning_content }\n : {}),\n };\n })\n : args.messages,\n };\n}\n\nexport interface CerebrasProviderSettings {\n /**\n * Cerebras API key.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface CerebrasProvider extends ProviderV4 {\n /**\n * Creates a Cerebras model for text generation.\n */\n (modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras model for text generation.\n */\n languageModel(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras chat model for text generation.\n */\n chat(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createCerebras(\n options: CerebrasProviderSettings = {},\n): CerebrasProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.cerebras.ai/v1',\n );\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'CEREBRAS_API_KEY',\n description: 'Cerebras API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-cerebras/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: CerebrasChatModelId) => {\n return new CerebrasChatLanguageModel(modelId, {\n provider: `cerebras.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: cerebrasErrorStructure,\n supportsStructuredOutputs: true,\n transformRequestBody: transformCerebrasRequestBody,\n });\n };\n\n const provider = (modelId: CerebrasChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const cerebras = createCerebras();\n","import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\nimport type {\n LanguageModelV4,\n LanguageModelV4CallOptions,\n LanguageModelV4GenerateResult,\n LanguageModelV4StreamPart,\n LanguageModelV4StreamResult,\n} from '@ai-sdk/provider';\nimport {\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { CerebrasChatModelId } from './cerebras-chat-language-model-options';\n\ntype CerebrasChatConfig = ConstructorParameters<\n typeof OpenAICompatibleChatLanguageModel\n>[1];\n\nfunction isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason,\n hasText,\n responseFormatType,\n}: {\n rawFinishReason: string | undefined;\n hasText: boolean;\n responseFormatType:\n | NonNullable<LanguageModelV4CallOptions['responseFormat']>['type']\n | undefined;\n}) {\n return (\n responseFormatType === 'json' && rawFinishReason === 'tool_calls' && hasText\n );\n}\n\nexport class CerebrasChatLanguageModel\n extends OpenAICompatibleChatLanguageModel\n implements LanguageModelV4\n{\n static [WORKFLOW_SERIALIZE](model: CerebrasChatLanguageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: CerebrasChatModelId;\n config: CerebrasChatConfig;\n }) {\n return new CerebrasChatLanguageModel(options.modelId, options.config);\n }\n\n async doGenerate(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4GenerateResult> {\n const result = await super.doGenerate(options);\n\n if (\n !isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: result.finishReason.raw,\n hasText: result.content.some(\n part => part.type === 'text' && part.text.length > 0,\n ),\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n return result;\n }\n\n return {\n ...result,\n // Cerebras GLM can return valid structured output text while also\n // repeating a tool call. Treat that mixed response as the final answer.\n content: result.content.filter(part => part.type !== 'tool-call'),\n finishReason: {\n ...result.finishReason,\n unified: 'stop',\n },\n };\n }\n\n async doStream(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4StreamResult> {\n const result = await super.doStream(options);\n let hasText = false;\n\n return {\n ...result,\n stream: result.stream.pipeThrough(\n new TransformStream<\n LanguageModelV4StreamPart,\n LanguageModelV4StreamPart\n >({\n transform(part, controller) {\n if (part.type === 'text-delta' && part.delta.length > 0) {\n hasText = true;\n }\n\n if (\n part.type === 'finish' &&\n isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: part.finishReason.raw,\n hasText,\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n controller.enqueue({\n ...part,\n finishReason: {\n ...part.finishReason,\n unified: 'stop',\n },\n });\n return;\n }\n\n if (\n options.responseFormat?.type === 'json' &&\n hasText &&\n (part.type === 'tool-input-start' ||\n part.type === 'tool-input-delta' ||\n part.type === 'tool-input-end' ||\n part.type === 'tool-call')\n ) {\n return;\n }\n\n controller.enqueue(part);\n },\n }),\n ),\n };\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AACA;AAAA,EACE;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACXP,SAAS,yCAAyC;AAQlD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAS,4CAA4C;AAAA,EACnD;AAAA,EACA;AAAA,EACA;AACF,GAMG;AACD,SACE,uBAAuB,UAAU,oBAAoB,gBAAgB;AAEzE;AAEO,IAAM,4BAAN,MAAM,mCACH,kCAEV;AAAA,EACE,QAAQ,kBAAkB,EAAE,OAAkC;AAC5D,WAAO,sBAAsB;AAAA,MAC3B,SAAS,MAAM;AAAA,MACf,QAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH;AAAA,EAEA,QAAQ,oBAAoB,EAAE,SAG3B;AACD,WAAO,IAAI,2BAA0B,QAAQ,SAAS,QAAQ,MAAM;AAAA,EACtE;AAAA,EAEA,MAAM,WACJ,SACwC;AACxC,UAAM,SAAS,MAAM,MAAM,WAAW,OAAO;AAE7C,QACE,CAAC,4CAA4C;AAAA,MAC3C,iBAAiB,OAAO,aAAa;AAAA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,CAAC,GACnB;AAClB,QAAM,UAAU;AAAA,IACd,QAAQ,WAAW;AAAA,EACrB;AACA,QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,mBAAmB,OAAO;AAAA,EAC5B;AAEF,QAAM,sBAAsB,CAAC,YAAiC;AAC5D,WAAO,IAAI,0BAA0B,SAAS;AAAA,MAC5C,UAAU;AAAA,MACV,KAAK,CAAC,EAAE,KAAK,MAAM,GAAG,OAAO,GAAG,IAAI;AAAA,MACpC,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA,MACf,gBAAgB;AAAA,MAChB,2BAA2B;AAAA,MAC3B,sBAAsB;AAAA,IACxB,CAAC;AAAA,EACH;AAEA,QAAM,WAAW,CAAC,YAChB,oBAAoB,OAAO;AAE7B,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,OAAO;AAEhB,WAAS,iBAAiB,CAAC,YAAoB;AAC7C,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,iBAAiB,CAAC;AAAA,EACrE;AACA,WAAS,qBAAqB,SAAS;AACvC,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,SAAO;AACT;AAEO,IAAM,WAAW,eAAe;","names":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/cerebras-chat-language-model.ts","../src/version.ts","../src/cerebras-provider.ts"],"sourcesContent":["import { OpenAICompatibleChatLanguageModel } from '@ai-sdk/openai-compatible';\nimport type {\n LanguageModelV4,\n LanguageModelV4CallOptions,\n LanguageModelV4GenerateResult,\n LanguageModelV4StreamPart,\n LanguageModelV4StreamResult,\n} from '@ai-sdk/provider';\nimport {\n serializeModelOptions,\n WORKFLOW_DESERIALIZE,\n WORKFLOW_SERIALIZE,\n} from '@ai-sdk/provider-utils';\nimport type { CerebrasChatModelId } from './cerebras-chat-language-model-options';\n\ntype CerebrasChatConfig = ConstructorParameters<\n typeof OpenAICompatibleChatLanguageModel\n>[1];\n\nfunction isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason,\n hasText,\n responseFormatType,\n}: {\n rawFinishReason: string | undefined;\n hasText: boolean;\n responseFormatType:\n | NonNullable<LanguageModelV4CallOptions['responseFormat']>['type']\n | undefined;\n}) {\n return (\n responseFormatType === 'json' && rawFinishReason === 'tool_calls' && hasText\n );\n}\n\nexport class CerebrasChatLanguageModel\n extends OpenAICompatibleChatLanguageModel\n implements LanguageModelV4\n{\n static [WORKFLOW_SERIALIZE](model: CerebrasChatLanguageModel) {\n return serializeModelOptions({\n modelId: model.modelId,\n config: model.config,\n });\n }\n\n static [WORKFLOW_DESERIALIZE](options: {\n modelId: CerebrasChatModelId;\n config: CerebrasChatConfig;\n }) {\n return new CerebrasChatLanguageModel(options.modelId, options.config);\n }\n\n async doGenerate(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4GenerateResult> {\n const result = await super.doGenerate(options);\n\n if (\n !isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: result.finishReason.raw,\n hasText: result.content.some(\n part => part.type === 'text' && part.text.length > 0,\n ),\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n return result;\n }\n\n return {\n ...result,\n // Cerebras GLM can return valid structured output text while also\n // repeating a tool call. Treat that mixed response as the final answer.\n content: result.content.filter(part => part.type !== 'tool-call'),\n finishReason: {\n ...result.finishReason,\n unified: 'stop',\n },\n };\n }\n\n async doStream(\n options: LanguageModelV4CallOptions,\n ): Promise<LanguageModelV4StreamResult> {\n const result = await super.doStream(options);\n let hasText = false;\n\n return {\n ...result,\n stream: result.stream.pipeThrough(\n new TransformStream<\n LanguageModelV4StreamPart,\n LanguageModelV4StreamPart\n >({\n transform(part, controller) {\n if (part.type === 'text-delta' && part.delta.length > 0) {\n hasText = true;\n }\n\n if (\n part.type === 'finish' &&\n isStructuredOutputWithToolCallsFinishReason({\n rawFinishReason: part.finishReason.raw,\n hasText,\n responseFormatType: options.responseFormat?.type,\n })\n ) {\n controller.enqueue({\n ...part,\n finishReason: {\n ...part.finishReason,\n unified: 'stop',\n },\n });\n return;\n }\n\n if (\n options.responseFormat?.type === 'json' &&\n hasText &&\n (part.type === 'tool-input-start' ||\n part.type === 'tool-input-delta' ||\n part.type === 'tool-input-end' ||\n part.type === 'tool-call')\n ) {\n return;\n }\n\n controller.enqueue(part);\n },\n }),\n ),\n };\n }\n}\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n","import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';\nimport {\n NoSuchModelError,\n type LanguageModelV4,\n type ProviderV4,\n} from '@ai-sdk/provider';\nimport {\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n type FetchFunction,\n} from '@ai-sdk/provider-utils';\nimport { CerebrasChatLanguageModel } from './cerebras-chat-language-model';\nimport type { CerebrasChatModelId } from './cerebras-chat-options';\nimport { z } from 'zod/v4';\nimport { VERSION } from './version';\n\n// Add error schema and structure\nconst cerebrasErrorSchema = z.object({\n message: z.string(),\n type: z.string(),\n param: z.string(),\n code: z.string(),\n});\n\nexport type CerebrasErrorData = z.infer<typeof cerebrasErrorSchema>;\n\nconst cerebrasErrorStructure: ProviderErrorStructure<CerebrasErrorData> = {\n errorSchema: cerebrasErrorSchema,\n errorToMessage: data => data.message,\n};\n\n/**\n * Cerebras expects assistant reasoning history in the `reasoning` field, while\n * the shared OpenAI-compatible converter serializes it as `reasoning_content`.\n */\nfunction transformCerebrasRequestBody(\n args: Record<string, any>,\n): Record<string, any> {\n const {\n max_tokens: maxTokens,\n parallelToolCalls,\n topLogprobs,\n logitBias,\n serviceTier,\n reasoningFormat,\n promptCacheKey,\n ...restArgs\n } = args;\n\n return {\n ...restArgs,\n ...(maxTokens !== undefined && {\n max_completion_tokens: maxTokens,\n }),\n ...(parallelToolCalls !== undefined && {\n parallel_tool_calls: parallelToolCalls,\n }),\n ...(topLogprobs !== undefined && { top_logprobs: topLogprobs }),\n ...(logitBias !== undefined && { logit_bias: logitBias }),\n ...(serviceTier !== undefined && { service_tier: serviceTier }),\n ...(reasoningFormat !== undefined && {\n reasoning_format: reasoningFormat,\n }),\n ...(promptCacheKey !== undefined && {\n prompt_cache_key: promptCacheKey,\n }),\n messages: Array.isArray(args.messages)\n ? args.messages.map(message => {\n if (\n message == null ||\n typeof message !== 'object' ||\n message.role !== 'assistant' ||\n !('reasoning_content' in message)\n ) {\n return message;\n }\n\n const { reasoning_content, ...rest } = message;\n\n return {\n ...rest,\n ...(!('reasoning' in rest) && reasoning_content !== undefined\n ? { reasoning: reasoning_content }\n : {}),\n };\n })\n : args.messages,\n };\n}\n\nexport interface CerebrasProviderSettings {\n /**\n * Cerebras API key.\n */\n apiKey?: string;\n /**\n * Base URL for the API calls.\n */\n baseURL?: string;\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n}\n\nexport interface CerebrasProvider extends ProviderV4 {\n /**\n * Creates a Cerebras model for text generation.\n */\n (modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras model for text generation.\n */\n languageModel(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * Creates a Cerebras chat model for text generation.\n */\n chat(modelId: CerebrasChatModelId): LanguageModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(modelId: string): never;\n}\n\nexport function createCerebras(\n options: CerebrasProviderSettings = {},\n): CerebrasProvider {\n const baseURL = withoutTrailingSlash(\n options.baseURL ?? 'https://api.cerebras.ai/v1',\n );\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'CEREBRAS_API_KEY',\n description: 'Cerebras API key',\n })}`,\n ...options.headers,\n },\n `ai-sdk-cerebras/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: CerebrasChatModelId) => {\n return new CerebrasChatLanguageModel(modelId, {\n provider: `cerebras.chat`,\n url: ({ path }) => `${baseURL}${path}`,\n headers: getHeaders,\n fetch: options.fetch,\n errorStructure: cerebrasErrorStructure,\n supportsStructuredOutputs: true,\n transformRequestBody: transformCerebrasRequestBody,\n });\n };\n\n const provider = (modelId: CerebrasChatModelId) =>\n createLanguageModel(modelId);\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createLanguageModel;\n provider.chat = createLanguageModel;\n\n provider.embeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'embeddingModel' });\n };\n provider.textEmbeddingModel = provider.embeddingModel;\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n return provider;\n}\n\nexport const cerebras = createCerebras();\n"],"mappings":";;;;;AAmBA,SAAS,4CAA4C,EACnD,iBACA,SACA,sBAOC;CACD,OACE,uBAAuB,UAAU,oBAAoB,gBAAgB;AAEzE;AAEA,IAAa,4BAAb,MAAa,kCACH,kCAEV;CACE,QAAQ,oBAAoB,OAAkC;EAC5D,OAAO,sBAAsB;GAC3B,SAAS,MAAM;GACf,QAAQ,MAAM;EAChB,CAAC;CACH;CAEA,QAAQ,sBAAsB,SAG3B;EACD,OAAO,IAAI,0BAA0B,QAAQ,SAAS,QAAQ,MAAM;CACtE;CAEA,MAAM,WACJ,SACwC;EACxC,MAAM,SAAS,MAAM,MAAM,WAAW,OAAO;EAE7C,IACE,CAAC,4CAA4C;GAC3C,iBAAiB,OAAO,aAAa;GACrC,SAA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AS,kBAAkB,YAAoB;EAC7C,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAiB,CAAC;CACrE;CACA,SAAS,qBAAqB,SAAS;CACvC,SAAS,cAAc,YAAoB;EACzC,MAAM,IAAI,iBAAiB;GAAE;GAAS,WAAW;EAAa,CAAC;CACjE;CAEA,OAAO;AACT;AAEA,MAAa,WAAW,eAAe"}
|
package/docs/40-cerebras.mdx
CHANGED
|
@@ -79,8 +79,8 @@ const model = cerebras('gpt-oss-120b');
|
|
|
79
79
|
You can also use the `.languageModel()` and `.chat()` methods:
|
|
80
80
|
|
|
81
81
|
```ts
|
|
82
|
-
const
|
|
83
|
-
const
|
|
82
|
+
const languageModel = cerebras.languageModel('gpt-oss-120b');
|
|
83
|
+
const chatModel = cerebras.chat('gpt-oss-120b');
|
|
84
84
|
```
|
|
85
85
|
|
|
86
86
|
### Reasoning Models
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/cerebras",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.61",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
33
|
-
"@ai-sdk/provider": "4.0.
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.61",
|
|
33
|
+
"@ai-sdk/provider": "4.0.21",
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.53"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "22.19.19",
|
|
38
38
|
"@vercel/ai-tsconfig": "0.0.0",
|
|
39
|
-
"
|
|
39
|
+
"tsdown": "^0.23.0",
|
|
40
40
|
"typescript": "5.8.3",
|
|
41
41
|
"zod": "3.25.76"
|
|
42
42
|
},
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
],
|
|
65
65
|
"description": "The **Cerebras provider** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for [Cerebras](https://cerebras.ai), offering high-speed AI model inference powered by Cerebras Wafer-Scale Engines and CS-3 systems.",
|
|
66
66
|
"scripts": {
|
|
67
|
-
"build": "pnpm clean &&
|
|
68
|
-
"build:watch": "pnpm clean &&
|
|
69
|
-
"clean": "del-cli
|
|
67
|
+
"build": "pnpm clean && tsdown",
|
|
68
|
+
"build:watch": "pnpm clean && tsdown --watch",
|
|
69
|
+
"clean": "del-cli docs *.tsbuildinfo",
|
|
70
70
|
"type-check": "tsc --build",
|
|
71
71
|
"test": "pnpm test:node && pnpm test:edge",
|
|
72
72
|
"test:update": "pnpm test:node -u",
|