Browse Source

feat: forward provider options from model config (#202)

Co-authored-by: Dax Raad <[email protected]>
Josh 8 months ago
parent
commit
9991352663

+ 2 - 0
packages/opencode/src/provider/models.ts

@@ -13,6 +13,7 @@ export namespace ModelsDev {
       attachment: z.boolean(),
       reasoning: z.boolean(),
       temperature: z.boolean(),
+      tool_call: z.boolean(),
       cost: z.object({
         input: z.number(),
         output: z.number(),
@@ -24,6 +25,7 @@ export namespace ModelsDev {
         output: z.number(),
       }),
       id: z.string(),
+      options: z.record(z.any()),
     })
     .openapi({
       ref: "Model.Info",

+ 13 - 7
packages/opencode/src/provider/provider.ts

@@ -161,13 +161,19 @@ export namespace Provider {
           attachment: model.attachment ?? existing?.attachment ?? false,
           reasoning: model.reasoning ?? existing?.reasoning ?? false,
           temperature: model.temperature ?? existing?.temperature ?? false,
-          cost: model.cost ??
-            existing?.cost ?? {
-              input: 0,
-              output: 0,
-              inputCached: 0,
-              outputCached: 0,
-            },
+          tool_call: model.tool_call ?? existing?.tool_call ?? true,
+          cost: {
+            ...existing?.cost,
+            ...model.cost,
+            input: 0,
+            output: 0,
+            cache_read: 0,
+            cache_write: 0,
+          },
+          options: {
+            ...existing?.options,
+            ...model.options,
+          },
           limit: model.limit ??
             existing?.limit ?? {
               context: 0,

+ 3 - 3
packages/opencode/src/session/index.ts

@@ -262,6 +262,7 @@ export namespace Session {
     if (msgs.length === 0 && !session.parentID) {
       generateText({
         maxTokens: input.providerID === "google" ? 1024 : 20,
+        providerOptions: model.info.options,
         messages: [
           ...SystemPrompt.title(input.providerID).map(
             (x): CoreMessage => ({
@@ -507,6 +508,7 @@ export namespace Session {
       toolCallStreaming: true,
       abortSignal: abort.signal,
       maxSteps: 1000,
+      providerOptions: model.info.options,
       messages: [
         ...system.map(
           (x): CoreMessage => ({
@@ -521,9 +523,7 @@ export namespace Session {
         ProviderTransform.message(msg, i, input.providerID, input.modelID),
       ),
       temperature: model.info.temperature ? 0 : undefined,
-      tools: {
-        ...tools,
-      },
+      tools: model.info.tool_call === false ? undefined : tools,
       model: model.language,
     })
     try {