-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvision.ts
37 lines (32 loc) · 926 Bytes
/
vision.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import GigaChat from 'gigachat';
import * as dotenv from 'dotenv';
import * as path from 'node:path';
import { Agent } from 'node:https';
import fs from 'node:fs';
dotenv.config();
const httpsAgent = new Agent({
rejectUnauthorized: false,
});
async function main() {
const client = new GigaChat({
timeout: 600,
model: 'GigaChat-Pro',
httpsAgent: httpsAgent,
});
const filePath = path.resolve(__dirname, '../media/cat.jpg');
const buffer = fs.readFileSync(filePath);
const file = new File([buffer], 'image.jpg', { type: 'image/jpeg' });
const uploadedFile = await client.uploadFile(file);
const response = await client.chat({
messages: [
{
role: 'user',
content: 'Какой окрас у котенка на фото?',
attachments: [uploadedFile.id],
},
],
temperature: 0.1,
});
console.log(response.choices[0]?.message.content);
}
main();