Skip to main content

Hunyuan Image-to-Text

Image-to-Text

tip

You can add a custom model hunyuan-custom, and configure the base_url and api key of the Hunyuan large model.

For details, you can refer to the following sample code.

When using image-to-text, the parameters passed differ from those in regular text generation. messages[n].content should be an array, where elements can be objects representing text/images, as shown below:

async function readImage() {
const model = ai.createModel("hunyuan-custom");
const res = await model.streamText({
model: "hunyuan-vision",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "What is the content of the picture below?",
},
{
type: "image_url",
image_url: {
url: "https://cloudcache.tencent-cloud.com/qcloud/ui/portal-set/build/About/images/bg-product-series_87d.png",
},
},
],
},
],
});

for await (let x of res.textStream) {
console.log(x);
}
}

When messages[n].content represents text, the object type is represented as:

interface TextContent {
type: "text", // fixed value
text: string, // text content
}

When messages[n].content represents an image, the object type is represented as:

interface ImageContent {
type: "image_url", // fixed value
image_url: {
url: string, // image URL
},
}