Hunyuan Large Model User Guide
Image-to-Text Generation
tip
Call createModel
and pass "hunyuan-exp"
or "hunyuan-open"
to create the Hunyuan Large Model, and use "hunyuan-vision"
as the model
parameter passed in when calling streamText
/ generateText
.
For details, please refer to the sample code below.
When using Image-to-Text Generation, the parameters passed differ from those in ordinary dialogue text generation. messages[n].content
is an array, and the elements in the array can be objects representing text/images, as shown below:
async function readImage() {
const model = ai.createModel("hunyuan-exp");
const res = await model.streamText({
model: "hunyuan-vision",
messages: [
{
role: "user",
content: [
{
type: "text",
text: "What is the content of the image 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 expressed as:
interface TextContent {
type: "text", // fixed value
text: string, // Text content
}
When messages[n].content
represents an image, the object type is expressed as:
interface ImageContent {
type: "image_url", // fixed value
image_url: {
url: string, // Image URL
},
}