本页还没有译文
本页 4 段还没译成日本語,下面显示的是英文原文。Generate Text with Image Prompt
还没翻译译自英文(ai-sdk.dev)本页 4 段都还没译
Some language models that support vision capabilities accept images as part of the prompt. Here are some of the different formats you can use to include images as input.
URL
import { generateText } from 'ai';
const result = await generateText({
model: 'openai/gpt-4.1',
maxOutputTokens: 512,
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'what are the red things in this image?',
},
{
type: 'file',
mediaType: 'image',
data: new URL(
'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/2024_Solar_Eclipse_Prominences.jpg/720px-2024_Solar_Eclipse_Prominences.jpg',
),
},
],
},
],
});
console.log(result);File Buffer
import { generateText } from 'ai';
import fs from 'fs';
const result = await generateText({
model: 'openai/gpt-4.1',
maxOutputTokens: 512,
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'what are the red things in this image?',
},
{
type: 'file',
mediaType: 'image',
data: fs.readFileSync('./node/attachments/eclipse.jpg', {
encoding: 'base64',
}),
},
],
},
],
});
console.log(result);AI 翻译查看英文原文