mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-21 04:12:08 +03:00
feat(ai): Responses routes for Fireworks and Groq
This commit is contained in:
@@ -1517,6 +1517,10 @@ const deepseek = DeepSeek.configure({ apiKey }).model("deepseek-chat")
|
||||
const fireworks = Fireworks.configure({ apiKey }).model("accounts/fireworks/models/my-model")
|
||||
```
|
||||
|
||||
Fireworks and Groq also select their Responses API with `responses(modelID)`, or through `providers/fireworks/responses`
|
||||
and `providers/groq/responses`. They use the provider-neutral Open Responses protocol with `store: false`. Groq rejects
|
||||
`include`, so its reasoning is not replayed as encrypted content.
|
||||
|
||||
The former `OpenAICompatible.baseten`, `.cerebras`, `.deepinfra`, `.deepseek`, `.fireworks`, `.groq`, and `.togetherai` presets are replaced by the top-level `Baseten`, `Cerebras`, `DeepInfra`, `DeepSeek`, `Fireworks`, `Groq`, and `TogetherAI` exports. Use `CloudflareAIGateway` and `CloudflareWorkersAI` directly; each has its own module. `OpenAICompatible` configures generic endpoints with an explicit `baseURL`.
|
||||
|
||||
### Provider entrypoints
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
"./providers/digitalocean/responses": "./src/providers/digitalocean/responses.ts",
|
||||
"./providers/elevenlabs": "./src/providers/elevenlabs.ts",
|
||||
"./providers/fireworks": "./src/providers/fireworks.ts",
|
||||
"./providers/fireworks/responses": "./src/providers/fireworks/responses.ts",
|
||||
"./providers/google": "./src/providers/google.ts",
|
||||
"./providers/google-vertex": "./src/providers/google-vertex.ts",
|
||||
"./providers/google-vertex-messages": "./src/providers/google-vertex-messages.ts",
|
||||
@@ -73,6 +74,7 @@
|
||||
"./providers/google/images": "./src/providers/google/images.ts",
|
||||
"./providers/google/interactions": "./src/providers/google/interactions.ts",
|
||||
"./providers/groq": "./src/providers/groq.ts",
|
||||
"./providers/groq/responses": "./src/providers/groq/responses.ts",
|
||||
"./providers/meta": "./src/providers/meta.ts",
|
||||
"./providers/meta/chat": "./src/providers/meta/chat.ts",
|
||||
"./providers/meta/images": "./src/providers/meta/images.ts",
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
import { Endpoint } from "../route/endpoint.js"
|
||||
import { ProviderID, type ModelID } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
|
||||
export const id = ProviderID.make("fireworks")
|
||||
const baseURL = "https://api.fireworks.ai/inference/v1"
|
||||
@@ -12,11 +14,11 @@ const baseURL = "https://api.fireworks.ai/inference/v1"
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput
|
||||
readonly providerOptions?: OpenAIProviderOptionsInput | OpenResponsesProviderOptionsInput
|
||||
}
|
||||
|
||||
export type Settings = ProviderPackage.Settings &
|
||||
OpenAIProviderOptionsInput & {
|
||||
export type Settings<Options = OpenAIProviderOptionsInput> = ProviderPackage.Settings &
|
||||
Options & {
|
||||
readonly apiKey?: string | false
|
||||
readonly baseURL?: string
|
||||
}
|
||||
@@ -30,35 +32,55 @@ export const route = Route.make({
|
||||
framing: OpenAIChat.framing,
|
||||
})
|
||||
|
||||
export const routes = [route]
|
||||
const responsesRoute = Route.make({
|
||||
id: "fireworks-responses",
|
||||
provider: id,
|
||||
providerMetadataKey: "fireworks",
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false, include: ["reasoning.encrypted_content"] } },
|
||||
})
|
||||
|
||||
export const routes = [route, responsesRoute]
|
||||
|
||||
export const configure = (input: Config = {}) => {
|
||||
const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input
|
||||
const configured = route.with({
|
||||
const options = {
|
||||
...defaults,
|
||||
endpoint: { baseURL: endpoint ?? baseURL },
|
||||
auth: AuthOptions.bearer(input, "FIREWORKS_API_KEY"),
|
||||
})
|
||||
}
|
||||
const configured = route.with(options)
|
||||
const configuredResponses = responsesRoute.with(options)
|
||||
return {
|
||||
id,
|
||||
model: (modelID: string | ModelID) =>
|
||||
configured.model<OpenAIProviderOptionsInput>({ id: modelID, compatibility: { supportsPromptCacheKey: true } }),
|
||||
responses: (modelID: string | ModelID) =>
|
||||
configuredResponses.model<OpenResponsesProviderOptionsInput>({ id: modelID }),
|
||||
configure,
|
||||
}
|
||||
}
|
||||
|
||||
export const provider = configure()
|
||||
export const responses = provider.responses
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
export const model: ProviderPackage.Model<Settings, OpenAIProviderOptionsInput> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
export const responsesModel: ProviderPackage.Model<
|
||||
Settings<OpenResponsesProviderOptionsInput>,
|
||||
OpenResponsesProviderOptionsInput
|
||||
> = (modelID, settings) => configure(config(settings)).responses(modelID)
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings<Config["providerOptions"]> = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
}
|
||||
}
|
||||
|
||||
export * as Fireworks from "./fireworks.js"
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { OpenResponsesProviderOptionsInput } from "../open-responses-options.js"
|
||||
import type { Fireworks } from "../fireworks.js"
|
||||
export { responsesModel as model } from "../fireworks.js"
|
||||
export type Settings = Fireworks.Settings<OpenResponsesProviderOptionsInput>
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Effect, Schema } from "effect"
|
||||
import type { ProviderPackage } from "../provider-package.js"
|
||||
import { OpenAIChat } from "../protocols/openai-chat.js"
|
||||
import { OpenResponses } from "../protocols/open-responses.js"
|
||||
import { ProviderShared } from "../protocols/shared.js"
|
||||
import { AuthOptions, type ProviderAuthOption } from "../route/auth-options.js"
|
||||
import { Route, type RouteDefaultsInput } from "../route/client.js"
|
||||
@@ -8,6 +9,7 @@ import { Endpoint } from "../route/endpoint.js"
|
||||
import { Protocol } from "../route/protocol.js"
|
||||
import { ProviderID, type ModelID, type LLMRequest } from "../schema/index.js"
|
||||
import type { OpenAIProviderOptionsInput } from "./openai-options.js"
|
||||
import type { OpenResponsesProviderOptionsInput } from "./open-responses-options.js"
|
||||
|
||||
export const id = ProviderID.make("groq")
|
||||
const baseURL = "https://api.groq.com/openai/v1"
|
||||
@@ -23,11 +25,11 @@ export type ProviderOptions = Pick<OpenAIProviderOptionsInput, "reasoningEffort"
|
||||
export type Config = Omit<RouteDefaultsInput, "providerOptions"> &
|
||||
ProviderAuthOption<"optional"> & {
|
||||
readonly baseURL?: string
|
||||
readonly providerOptions?: ProviderOptions
|
||||
readonly providerOptions?: ProviderOptions | OpenResponsesProviderOptionsInput
|
||||
}
|
||||
|
||||
export type Settings = ProviderPackage.Settings &
|
||||
ProviderOptions & {
|
||||
export type Settings<Options = ProviderOptions> = ProviderPackage.Settings &
|
||||
Options & {
|
||||
readonly apiKey?: string | false
|
||||
readonly baseURL?: string
|
||||
}
|
||||
@@ -71,13 +73,26 @@ export const route = Route.make({
|
||||
framing: OpenAIChat.framing,
|
||||
})
|
||||
|
||||
// Groq's Responses API is stateless and rejects `include`, so reasoning is not replayed as encrypted content.
|
||||
const responsesRoute = Route.make({
|
||||
id: "groq-responses",
|
||||
provider: id,
|
||||
providerMetadataKey: "groq",
|
||||
protocol: OpenResponses.protocol,
|
||||
endpoint: Endpoint.path("/responses", { baseURL }),
|
||||
transport: OpenResponses.httpTransport,
|
||||
defaults: { providerOptions: { store: false } },
|
||||
})
|
||||
|
||||
export const configure = (input: Config = {}) => {
|
||||
const { apiKey: _apiKey, auth: _auth, baseURL: endpoint, ...defaults } = input
|
||||
const configured = route.with({
|
||||
const options = {
|
||||
...defaults,
|
||||
endpoint: { baseURL: endpoint ?? baseURL },
|
||||
auth: AuthOptions.bearer(input, "GROQ_API_KEY"),
|
||||
})
|
||||
}
|
||||
const configured = route.with(options)
|
||||
const configuredResponses = responsesRoute.with(options)
|
||||
return {
|
||||
id,
|
||||
model: (modelID: string | ModelID) =>
|
||||
@@ -90,22 +105,30 @@ export const configure = (input: Config = {}) => {
|
||||
supportsStrictMode: false,
|
||||
},
|
||||
}),
|
||||
responses: (modelID: string | ModelID) =>
|
||||
configuredResponses.model<OpenResponsesProviderOptionsInput>({ id: modelID }),
|
||||
configure,
|
||||
}
|
||||
}
|
||||
|
||||
export const provider = configure()
|
||||
export const responses = provider.responses
|
||||
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (
|
||||
modelID,
|
||||
{ apiKey, baseURL, body, headers, ...providerOptions }: Settings = {},
|
||||
) =>
|
||||
configure({
|
||||
export const model: ProviderPackage.Model<Settings, ProviderOptions> = (modelID, settings) =>
|
||||
configure(config(settings)).model(modelID)
|
||||
export const responsesModel: ProviderPackage.Model<
|
||||
Settings<OpenResponsesProviderOptionsInput>,
|
||||
OpenResponsesProviderOptionsInput
|
||||
> = (modelID, settings) => configure(config(settings)).responses(modelID)
|
||||
|
||||
function config({ apiKey, baseURL, body, headers, ...providerOptions }: Settings<Config["providerOptions"]> = {}) {
|
||||
return {
|
||||
apiKey,
|
||||
baseURL,
|
||||
headers,
|
||||
http: body === undefined ? undefined : { body },
|
||||
providerOptions,
|
||||
}).model(modelID)
|
||||
}
|
||||
}
|
||||
|
||||
export * as Groq from "./groq.js"
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import type { OpenResponsesProviderOptionsInput } from "../open-responses-options.js"
|
||||
import type { Groq } from "../groq.js"
|
||||
export { responsesModel as model } from "../groq.js"
|
||||
export type Settings = Groq.Settings<OpenResponsesProviderOptionsInput>
|
||||
+53
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+53
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -104,6 +104,38 @@ describe("provider package entrypoints", () => {
|
||||
}
|
||||
})
|
||||
|
||||
test("maps Fireworks and Groq Responses entrypoints onto provider-owned routes", async () => {
|
||||
const settings = {
|
||||
apiKey: "fixture",
|
||||
headers: { "x-test": "fixture" },
|
||||
body: { future_option: true },
|
||||
reasoningEffort: "low",
|
||||
}
|
||||
const encrypted = { store: false, include: ["reasoning.encrypted_content"] }
|
||||
const selected = [
|
||||
[
|
||||
(await import("@opencode/ai/providers/fireworks/responses")).model("gpt-oss", settings),
|
||||
"fireworks-responses",
|
||||
"https://api.fireworks.ai/inference/v1",
|
||||
encrypted,
|
||||
],
|
||||
[
|
||||
(await import("@opencode/ai/providers/groq/responses")).model("gpt-oss", settings),
|
||||
"groq-responses",
|
||||
"https://api.groq.com/openai/v1",
|
||||
{ store: false },
|
||||
],
|
||||
] as const
|
||||
for (const [model, route, baseURL, defaults] of selected) {
|
||||
expect(model.route.id).toBe(route)
|
||||
expect(model.route.protocol).toBe("open-responses")
|
||||
expect(model.route.endpoint).toMatchObject({ baseURL, path: "/responses" })
|
||||
expect(model.route.defaults.headers).toEqual(settings.headers)
|
||||
expect(model.route.defaults.http?.body).toEqual(settings.body)
|
||||
expect(model.route.defaults.providerOptions).toEqual({ reasoningEffort: "low", ...defaults })
|
||||
}
|
||||
})
|
||||
|
||||
test("maps Cohere entrypoints onto native and compatibility routes", async () => {
|
||||
const modules = await Promise.all([
|
||||
import("@opencode/ai/providers/cohere"),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from "bun:test"
|
||||
import { Effect, Schema } from "effect"
|
||||
import { ai, LLMEvent, toDefinitions } from "../../src/effect.js"
|
||||
import { DigitalOcean, OpenRouter, Venice } from "../../src/providers.js"
|
||||
import { DigitalOcean, Fireworks, Groq, OpenRouter, Venice } from "../../src/providers.js"
|
||||
import { LLMClient } from "../../src/route.js"
|
||||
import { tool } from "../../src/tool.js"
|
||||
import { expectWeatherToolLoop, runWeatherToolLoop, weatherToolLoopRequest } from "../recorded-scenarios.js"
|
||||
@@ -37,6 +37,20 @@ for (const item of [
|
||||
env: "VENICE_API_KEY",
|
||||
model: Venice.configure({ apiKey: process.env.VENICE_API_KEY ?? "fixture" }).responses("openai-gpt-54-mini"),
|
||||
},
|
||||
{
|
||||
provider: "fireworks",
|
||||
env: "FIREWORKS_API_KEY",
|
||||
freeform: false,
|
||||
model: Fireworks.configure({ apiKey: process.env.FIREWORKS_API_KEY ?? "fixture" }).responses(
|
||||
"accounts/fireworks/models/gpt-oss-120b",
|
||||
),
|
||||
},
|
||||
{
|
||||
provider: "groq",
|
||||
env: "GROQ_API_KEY",
|
||||
freeform: false,
|
||||
model: Groq.configure({ apiKey: process.env.GROQ_API_KEY ?? "fixture" }).responses("openai/gpt-oss-20b"),
|
||||
},
|
||||
]) {
|
||||
const recorded = recordedTests({
|
||||
prefix: `${item.provider}-responses`,
|
||||
@@ -72,6 +86,8 @@ for (const item of [
|
||||
}),
|
||||
)
|
||||
|
||||
if (item.freeform === false) continue
|
||||
|
||||
recorded.effect.with("calls a freeform text tool", { tags: ["tool", "freeform"] }, () =>
|
||||
Effect.gen(function* () {
|
||||
const response = yield* LLMClient.generate(
|
||||
@@ -89,3 +105,4 @@ for (const item of [
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user