mirror of
https://github.com/anomalyco/opencode.git
synced 2026-07-10 00:38:31 +00:00
chore: generate
This commit is contained in:
parent
2859ce6e73
commit
c47cb28781
3 changed files with 25 additions and 13 deletions
|
|
@ -24,7 +24,11 @@ export function cortexFetch(upstream: FetchLike = fetch) {
|
|||
if (!response.ok && response.status === 400) {
|
||||
try {
|
||||
const errorData = (await response.clone().json()) as Record<string, unknown>
|
||||
if (String(errorData.message || errorData.error || "").toLowerCase().includes("conversation complete")) {
|
||||
if (
|
||||
String(errorData.message || errorData.error || "")
|
||||
.toLowerCase()
|
||||
.includes("conversation complete")
|
||||
) {
|
||||
return new Response(
|
||||
JSON.stringify({ choices: [{ finish_reason: "stop", message: { content: "", role: "assistant" } }] }),
|
||||
{ status: 200, headers: new Headers({ "content-type": "application/json" }) },
|
||||
|
|
@ -45,7 +49,9 @@ export function cortexFetch(upstream: FetchLike = fetch) {
|
|||
ctrl.close()
|
||||
return
|
||||
}
|
||||
ctrl.enqueue(encoder.encode(decoder.decode(value, { stream: true }).replace(/"role"\s*:\s*""/g, '"role":"assistant"')))
|
||||
ctrl.enqueue(
|
||||
encoder.encode(decoder.decode(value, { stream: true }).replace(/"role"\s*:\s*""/g, '"role":"assistant"')),
|
||||
)
|
||||
},
|
||||
cancel() {
|
||||
reader.cancel()
|
||||
|
|
@ -65,8 +71,7 @@ export const SnowflakeCortexPlugin = PluginV2.define({
|
|||
"aisdk.sdk": Effect.fn(function* (evt) {
|
||||
if (evt.model.providerID !== ProviderV2.ID.make("snowflake-cortex")) return
|
||||
const pat =
|
||||
process.env.SNOWFLAKE_CORTEX_PAT ??
|
||||
(typeof evt.options.apiKey === "string" ? evt.options.apiKey : undefined)
|
||||
process.env.SNOWFLAKE_CORTEX_PAT ?? (typeof evt.options.apiKey === "string" ? evt.options.apiKey : undefined)
|
||||
const upstream = typeof evt.options.fetch === "function" ? (evt.options.fetch as FetchLike) : undefined
|
||||
if (evt.options.includeUsage !== false) evt.options.includeUsage = true
|
||||
const mod = yield* Effect.promise(() => import("@ai-sdk/openai-compatible"))
|
||||
|
|
|
|||
|
|
@ -173,10 +173,18 @@ describe("cortexFetch", () => {
|
|||
bun_it("rewrites role:'' to role:'assistant' in streaming SSE chunks", async () => {
|
||||
const chunk = `data: {"choices":[{"delta":{"role":"","content":"Hi"},"index":0}]}\n\n`
|
||||
const upstream: FetchLike = async () =>
|
||||
new Response(new ReadableStream({ start: (ctrl) => { ctrl.enqueue(new TextEncoder().encode(chunk)); ctrl.close() } }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
})
|
||||
new Response(
|
||||
new ReadableStream({
|
||||
start: (ctrl) => {
|
||||
ctrl.enqueue(new TextEncoder().encode(chunk))
|
||||
ctrl.close()
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
},
|
||||
)
|
||||
const response = await cortexFetch(upstream)("https://test", {})
|
||||
const text = await response.text()
|
||||
expect(text).toContain('"role":"assistant"')
|
||||
|
|
|
|||
|
|
@ -860,10 +860,7 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
|
|||
(auth?.type === "api" ? auth.metadata?.account : undefined) ??
|
||||
input.options?.account
|
||||
|
||||
const pat =
|
||||
env["SNOWFLAKE_CORTEX_PAT"] ??
|
||||
(auth?.type === "api" ? auth.key : undefined) ??
|
||||
input.options?.apiKey
|
||||
const pat = env["SNOWFLAKE_CORTEX_PAT"] ?? (auth?.type === "api" ? auth.key : undefined) ?? input.options?.apiKey
|
||||
|
||||
if (!account || !pat) {
|
||||
const missing = [!account && "SNOWFLAKE_ACCOUNT", !pat && "SNOWFLAKE_CORTEX_PAT"].filter(Boolean).join(", ")
|
||||
|
|
@ -905,7 +902,9 @@ function custom(dep: CustomDep): Record<string, CustomLoader> {
|
|||
const errorMessage = String(errorData.message || errorData.error || "")
|
||||
if (errorMessage.toLowerCase().includes("conversation complete")) {
|
||||
return new Response(
|
||||
JSON.stringify({ choices: [{ finish_reason: "stop", message: { content: "", role: "assistant" } }] }),
|
||||
JSON.stringify({
|
||||
choices: [{ finish_reason: "stop", message: { content: "", role: "assistant" } }],
|
||||
}),
|
||||
{ status: 200, headers: new Headers({ "content-type": "application/json" }) },
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue