Skip to content

Commit e49772a

Browse files
opencode-agent[bot]rekram1-noderyanl-cerebras
authored
fix(opencode): preserve Cerebras completion limit (anomalyco#43736)
Co-authored-by: Aiden <[email protected]> Co-authored-by: ryanl-cerebras <[email protected]>
1 parent 08faeb3 commit e49772a

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
2+
3+
export async function CerebrasPlugin(_input: PluginInput): Promise<Hooks> {
4+
return {
5+
"chat.params": async (input, output) => {
6+
if (input.model.api.npm !== "@ai-sdk/cerebras") return
7+
if (output.options.max_completion_tokens === undefined) return
8+
output.maxOutputTokens = undefined
9+
},
10+
}
11+
}

‎packages/opencode/src/plugin/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cl
2020
import { AzureAuthPlugin } from "./azure"
2121
import { DigitalOceanAuthPlugin } from "./digitalocean"
2222
import { XaiAuthPlugin } from "./xai"
23+
import { CerebrasPlugin } from "./cerebras"
2324
import { SnowflakeCortexAuthPlugin } from "./snowflake-cortex"
2425
import { Effect, Layer, Context } from "effect"
2526
import { EffectBridge } from "@/effect/bridge"
@@ -80,6 +81,7 @@ function internalPlugins(flags: RuntimeFlags.Info): PluginInstance[] {
8081
DigitalOceanAuthPlugin,
8182
SnowflakeCortexAuthPlugin,
8283
XaiAuthPlugin,
84+
CerebrasPlugin,
8385
]
8486
}
8587

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { describe, expect, test } from "bun:test"
2+
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
3+
import { CerebrasPlugin } from "../../src/plugin/cerebras"
4+
5+
type ChatParams = NonNullable<Hooks["chat.params"]>
6+
7+
function input(npm: string) {
8+
return {
9+
model: { api: { npm } },
10+
} as Parameters<ChatParams>[0]
11+
}
12+
13+
function output(options: Record<string, unknown>) {
14+
return {
15+
maxOutputTokens: 32_000,
16+
options,
17+
} as Parameters<ChatParams>[1]
18+
}
19+
20+
describe("CerebrasPlugin", () => {
21+
test("omits the generic output cap when max_completion_tokens is configured", async () => {
22+
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
23+
const params = output({ max_completion_tokens: 64 })
24+
25+
await hook(input("@ai-sdk/cerebras"), params)
26+
27+
expect(params.maxOutputTokens).toBeUndefined()
28+
})
29+
30+
test("preserves the generic output cap without max_completion_tokens", async () => {
31+
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
32+
const params = output({})
33+
34+
await hook(input("@ai-sdk/cerebras"), params)
35+
36+
expect(params.maxOutputTokens).toBe(32_000)
37+
})
38+
39+
test("does not change other providers", async () => {
40+
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
41+
const params = output({ max_completion_tokens: 64 })
42+
43+
await hook(input("@ai-sdk/openai"), params)
44+
45+
expect(params.maxOutputTokens).toBe(32_000)
46+
})
47+
})

0 commit comments

Comments
 (0)