Skip to content

Groq Model Was Not Accepted in createDataStreamResponse Function #5282

Closed
@hamzaadil56

Description

@hamzaadil56

Description

I was making a simple RAG chatbot with AI SDK and used createDataStreamResponse function for streaming. At first I used openai model and it worked fine. But When I shifted towards groq model so first there is a typescript error occurred which is as follows:

The expected type comes from property 'model' which is declared here on type 'CallSettings & Prompt & { model: LanguageModelV1; tools?: { addResource: Tool<ZodObject<{ content: ZodString; }, "strip", ZodTypeAny, { ...; }, { ...; }>, string> & { ...; }; getInformation: Tool<...> & { ...; }; } | undefined; ... 17 more ...; _internal?: { ...; } | undefined; }'

On Runtime it gives the following error which occurred when I used GROQ model:

{
  message: "Failed to call a function. Please adjust your prompt. See 'failed_generation' for more details.",
  type: 'invalid_request_error'
}

The above error did not occur when I used the Openai model.

Code example

import { createResource } from "@/lib/actions/resources";
import { openai } from "@ai-sdk/openai";
import { streamText, tool, createDataStreamResponse, smoothStream } from "ai";
import { z } from "zod";
import { findRelevantContent } from "@/lib/ai/embedding";
import { groq } from "@ai-sdk/groq";

// Allow streaming responses up to 30 seconds
export const maxDuration = 30;

export async function POST(req: Request) {
	const { messages } = await req.json();

	return createDataStreamResponse({
		execute: (dataStream) => {
			const result = streamText({
				model: groq("llama-3.3-70b-versatile"),
				system: `You are an ai assistant of Hamza who knows everything about Muhammad Hamza. You gives responses to the user like as if you are Hamza talking to the people using the information you have about Hamza. If the user asks a question about irrelevant to Hamza, then say that you cannot tell anything else other than about Hamza. You are specifically designed to share the information about Hamza."`,
				messages,
				maxSteps: 5,

				experimental_transform: smoothStream({ chunking: "word" }),
				tools: {
					addResource: tool({
						description: `add a resource to your knowledge base.
				  If the user provides a random piece of knowledge unprompted, use this tool without asking for confirmation.`,
						parameters: z.object({
							content: z
								.string()
								.describe(
									"the content or resource to add to the knowledge base"
								),
						}),
						execute: async ({ content }) =>
							createResource({ content }),
					}),
					getInformation: tool({
						description: `get information from your knowledge base to answer questions.`,
						parameters: z.object({
							question: z.string().describe("the users question"),
						}),
						execute: async ({ question }) =>
							findRelevantContent(question),
					}),
				},
			});

			result.consumeStream();

			result.mergeIntoDataStream(dataStream, {
				sendReasoning: true,
			});
		},
		onError: () => {
			return "Oops, an error occured!";
		},
	});
}

AI provider

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions