You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (!experimental_attachments) {
return new Response(JSON.stringify({ error: 'No image provided' }), {
status: 400,
headers: { 'Content-Type': 'application/json' },
});
}
const result = await streamObject({
schema: ItemSchema,
model: openaiSDK('gpt-4o'),
maxTokens: 1000,
maxRetries: 3,
messages: [
{
role: 'system',
content: `You are an AI assistant specialized in detecting and listing items from images.
Provide accurate information on all items visible in the image below.`,
},
{
role: 'user',
content: [
{
type: 'text',
text: `Analyze the image and list all visible items,
be very detailed. And if you see multiple items that are similar write them all down.
`,
},
{
type: 'image',
image: experimental_attachments[0],
},
],
},
],
});
return result.toTextStreamResponse();
`
`
if i have an index in the type
image: experimental_attachments[0], then this is working,
But i want to pass a list of images and analyze them and the response.
Has anyone a good solution or were i can read up on this?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi.
I have been struggling with this a while and maybe somebody have some idea on how to solve it :)
as the title says, I want to analyze a batch of images and return the response.
This is my route.
`import { streamObject } from 'ai';
import { openai as openaiSDK } from '@ai-sdk/openai';
import { ItemSchema } from '@/app/types/schema';
export const maxDuration = 300; // 5 minutes
export async function POST(req: Request) {
try {
const { experimental_attachments }: { experimental_attachments: string[] } = await req.json();
} catch (error) {
console.error('Error detecting inventory items:', error);
return new Response(
JSON.stringify({
error: 'Failed to detect inventory items',
detail: error instanceof Error ? error.message : String(error),
}),
{ status: 500, headers: { 'Content-Type': 'application/json' } },
);
}
}
`
if i have an index in the type
image: experimental_attachments[0], then this is working,
But i want to pass a list of images and analyze them and the response.
Has anyone a good solution or were i can read up on this?
Beta Was this translation helpful? Give feedback.
All reactions