Skip to content

Parsed reasoning support for Groq adapter #5233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iipanda opened this issue Mar 16, 2025 · 1 comment · Fixed by #5273
Closed

Parsed reasoning support for Groq adapter #5233

iipanda opened this issue Mar 16, 2025 · 1 comment · Fixed by #5273
Labels
ai/provider enhancement New feature or request

Comments

@iipanda
Copy link

iipanda commented Mar 16, 2025

Feature Description

Groq supports reasoning models like Deepseek, and it has the option to return the reasoning process, but when using tool calling it is returned in a separate field and not in the response text directly, which is not supported right now by the adapter.

Use Cases

No response

Additional context

No response

@iipanda iipanda added the enhancement New feature or request label Mar 16, 2025
@iipanda iipanda changed the title Tool calling and reasoning support for Groq adapter Parsed reasoning support for Groq adapter Mar 16, 2025
@iipanda
Copy link
Author

iipanda commented Mar 16, 2025

The current workaround is applying this patch to the @ai-sdk/groq package:

diff --git a/dist/index.js b/dist/index.js
index b7f9db25763efa16a976b261efd17e00fde0e08d..43c4f52e76f60b5ba414ef78c2bb3beb65708d36 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -468,6 +468,12 @@ var GroqChatLanguageModel = class {
                 textDelta: delta.content
               });
             }
+            if (delta.reasoning != null) {
+              controller.enqueue({
+                type: "reasoning",
+                textDelta: delta.reasoning
+              });
+            }
             if (delta.tool_calls != null) {
               for (const toolCallDelta of delta.tool_calls) {
                 const index = toolCallDelta.index;
@@ -610,6 +616,7 @@ var groqChatChunkSchema = import_zod2.z.union([
         delta: import_zod2.z.object({
           role: import_zod2.z.enum(["assistant"]).nullish(),
           content: import_zod2.z.string().nullish(),
+          reasoning: import_zod2.z.string().nullish(),
           tool_calls: import_zod2.z.array(
             import_zod2.z.object({
               index: import_zod2.z.number(),
diff --git a/dist/index.mjs b/dist/index.mjs
index a17ca758f75089f645e5a9e3a3492373bf68724e..0545f57fb07996ecae298c5ccfc0767780f5ee2a 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -459,6 +459,12 @@ var GroqChatLanguageModel = class {
                 textDelta: delta.content
               });
             }
+            if (delta.reasoning != null) {
+              controller.enqueue({
+                type: "reasoning",
+                textDelta: delta.reasoning
+              });
+            }
             if (delta.tool_calls != null) {
               for (const toolCallDelta of delta.tool_calls) {
                 const index = toolCallDelta.index;
@@ -601,6 +607,7 @@ var groqChatChunkSchema = z2.union([
         delta: z2.object({
           role: z2.enum(["assistant"]).nullish(),
           content: z2.string().nullish(),
+          reasoning: z2.string().nullish(),
           tool_calls: z2.array(
             z2.object({
               index: z2.number(),

And adding a custom fetch function to the Groq provider:

const groq = createGroq({
  fetch: (url, options) => {
    if (options?.body) {
      const body = JSON.parse(options.body as string)
      if (body?.model === DEEPSEEK_MODEL) {
        body.reasoning_format = "parsed"
        options.body = JSON.stringify(body)
      }
    }

    return fetch(url, options)
  },
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai/provider enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants