So I'm using Next TS with Vercel AI SDK with Gemini-1.5 Pro Latest, the code works on my local machine but then when deployed on Vercel, the code can only accept text calling but not tool calling with generative UI. I tried to set the max tokens to no avail, can anyone help? This is my code:
export async function continueConversation(
input: string
): Promise<ClientMessage> {
"use server";
const start = Date.now();
const history = getMutableAIState();
console.log(
"Starting continueConversation at:",
new Date(start).toISOString()
);
const result = await streamUI({
maxTokens: 100000,
model: google("models/gemini-1.5-pro-latest"),
system: `
You are a general purpose assistant, you can help the user with a variety of tasks. You can tell jokes, give place and song recommendations, and much more. You are a professional, don't use emote.
`,
messages: [...history.get(), { role: "user", content: input }],
text: ({ content, done }) => {
if (done) {
history.done((messages: ServerMessage[]) => [
...messages,
{ role: "assistant", content },
]);
}
return (
<article className="markdown-container">
<Markdown remarkPlugins={[remarkGfm]}>{content}</Markdown>
</article>
);
},
tools: {
getJoke: {
description:
"A tool when the user wants a joke. The joke should make the user laugh.",
parameters: z.object({
category: z.string().optional().describe("the category of the joke"),
}),
generate: async function* ({ category }) {
yield <LoaderCircle />;
const joke = await generateObject({
model: google("models/gemini-1.5-pro-latest"),
schema: jokeSchema,
prompt: `Generate a joke that will make the user laugh. The joke should be in the category of ${category}. If no category is provided, ask the user for a category.`,
});
return <JokeComponent joke={joke.object} />;
},
},
getPlaces: {
description:
"A tool when the user wants place recommendations based on the location and type.",
parameters: z.object({
location: z.string().describe("the user's location"),
type: z.string().optional().describe("the type of place"),
}),
generate: async function* ({ location, type }) {
yield <LoaderCircle className="loader-circle" />;
const places = await generateObject({
model: google("models/gemini-1.5-pro-latest"),
schema: placeSchema,
prompt: `Generate an array of places to visit in ${location} with the type of ${
type || "any type"
}. The array should contain at least 5 places.`,
});
if (places && places.object && Array.isArray(places.object)) {
return <PlaceComponent place={places.object} />;
} else {
return <p>Something went wrong, please try again later.</p>;
}
},
},
getSongs: {
description:
"A tool when the user wants song recommendations based on the genre.",
parameters: z.object({
genre: z.string().optional().describe("the genre of the song"),
singer: z.string().optional().describe("the singer of the song"),
}),
generate: async function* ({ genre, singer }) {
yield <LoaderCircle />;
const songs = await generateObject({
model: google("models/gemini-1.5-pro-latest"),
schema: songSchema,
prompt: `Generate songs recommendation in the genre of ${
genre || "any genres"
} or by the singer ${
singer || "any singer"
}. Return an array of 3 songs.`,
});
if (songs && songs.object && Array.isArray(songs.object)) {
return <SongComponent song={songs.object} />;
} else {
return <p>Something went wrong, please try again later.</p>;
}
},
},
},
});
const end = Date.now();
const duration = end - start;
console.log(
"Completed continueConversation at:",
new Date(end).toISOString()
);
console.log("Duration (ms):", duration);
if (duration > 5000) {
console.warn("Function execution time exceeded 5 seconds!");
}
return {
id: nanoid(),
role: "assistant",
display: result.value,
};
}
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |