fix(opencode): preserve Cerebras completion limit (#43736)
Co-authored-by: Aiden <rekram1-node@users.noreply.github.com> Co-authored-by: ryanl-cerebras <230249923+ryanl-cerebras@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
08faeb3893
commit
e49772a8b4
@@ -0,0 +1,11 @@
|
|||||||
|
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
|
||||||
|
|
||||||
|
export async function CerebrasPlugin(_input: PluginInput): Promise<Hooks> {
|
||||||
|
return {
|
||||||
|
"chat.params": async (input, output) => {
|
||||||
|
if (input.model.api.npm !== "@ai-sdk/cerebras") return
|
||||||
|
if (output.options.max_completion_tokens === undefined) return
|
||||||
|
output.maxOutputTokens = undefined
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import { CloudflareAIGatewayAuthPlugin, CloudflareWorkersAuthPlugin } from "./cl
|
|||||||
import { AzureAuthPlugin } from "./azure"
|
import { AzureAuthPlugin } from "./azure"
|
||||||
import { DigitalOceanAuthPlugin } from "./digitalocean"
|
import { DigitalOceanAuthPlugin } from "./digitalocean"
|
||||||
import { XaiAuthPlugin } from "./xai"
|
import { XaiAuthPlugin } from "./xai"
|
||||||
|
import { CerebrasPlugin } from "./cerebras"
|
||||||
import { SnowflakeCortexAuthPlugin } from "./snowflake-cortex"
|
import { SnowflakeCortexAuthPlugin } from "./snowflake-cortex"
|
||||||
import { Effect, Layer, Context } from "effect"
|
import { Effect, Layer, Context } from "effect"
|
||||||
import { EffectBridge } from "@/effect/bridge"
|
import { EffectBridge } from "@/effect/bridge"
|
||||||
@@ -80,6 +81,7 @@ function internalPlugins(flags: RuntimeFlags.Info): PluginInstance[] {
|
|||||||
DigitalOceanAuthPlugin,
|
DigitalOceanAuthPlugin,
|
||||||
SnowflakeCortexAuthPlugin,
|
SnowflakeCortexAuthPlugin,
|
||||||
XaiAuthPlugin,
|
XaiAuthPlugin,
|
||||||
|
CerebrasPlugin,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
|
||||||
|
import { CerebrasPlugin } from "../../src/plugin/cerebras"
|
||||||
|
|
||||||
|
type ChatParams = NonNullable<Hooks["chat.params"]>
|
||||||
|
|
||||||
|
function input(npm: string) {
|
||||||
|
return {
|
||||||
|
model: { api: { npm } },
|
||||||
|
} as Parameters<ChatParams>[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
function output(options: Record<string, unknown>) {
|
||||||
|
return {
|
||||||
|
maxOutputTokens: 32_000,
|
||||||
|
options,
|
||||||
|
} as Parameters<ChatParams>[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("CerebrasPlugin", () => {
|
||||||
|
test("omits the generic output cap when max_completion_tokens is configured", async () => {
|
||||||
|
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
|
||||||
|
const params = output({ max_completion_tokens: 64 })
|
||||||
|
|
||||||
|
await hook(input("@ai-sdk/cerebras"), params)
|
||||||
|
|
||||||
|
expect(params.maxOutputTokens).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
test("preserves the generic output cap without max_completion_tokens", async () => {
|
||||||
|
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
|
||||||
|
const params = output({})
|
||||||
|
|
||||||
|
await hook(input("@ai-sdk/cerebras"), params)
|
||||||
|
|
||||||
|
expect(params.maxOutputTokens).toBe(32_000)
|
||||||
|
})
|
||||||
|
|
||||||
|
test("does not change other providers", async () => {
|
||||||
|
const hook = (await CerebrasPlugin({} as PluginInput))["chat.params"]!
|
||||||
|
const params = output({ max_completion_tokens: 64 })
|
||||||
|
|
||||||
|
await hook(input("@ai-sdk/openai"), params)
|
||||||
|
|
||||||
|
expect(params.maxOutputTokens).toBe(32_000)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user