1+ import { describe , it , expect } from 'vitest'
2+ import { Ollama } from '../src/index'
3+ import path from 'path'
4+ import { fileURLToPath } from 'url'
5+ import { dirname } from 'path'
6+
7+
8+ async function describeImage ( imageName : string ) {
9+ const __filename = fileURLToPath ( import . meta. url )
10+ const __dirname = dirname ( __filename )
11+ const instance = new Ollama ( )
12+ const imagePath = path . resolve ( __dirname , `./mocks/images/${ imageName } ` )
13+ const response = await instance . chat ( {
14+ model : 'llama3.2-vision' ,
15+ messages : [ { role : 'user' , content : 'what is this?' , images : [ imagePath ] } ] ,
16+ } )
17+ return response . message . content ;
18+ }
19+
20+ const testConfig = {
21+ timeout : 5 * 60 * 1000 , // 5 minutes
22+ retry : 3 ,
23+ }
24+
25+ describe ( 'Ollama | Nodejs | Vision image formats' , ( ) => {
26+ it ( 'support ".webp" image recognition' , testConfig , async ( ) => {
27+ const result = await describeImage ( 'WebP-Gradient.webp' )
28+ expect ( result . toLowerCase ( ) ) . toContain ( 'gradient' )
29+ } )
30+
31+ it ( 'support ".gif" image recognition' , testConfig , async ( ) => {
32+ const result = await describeImage ( '200w.gif' )
33+ expect ( result . toLowerCase ( ) ) . toContain ( 'cat' )
34+ } )
35+
36+ it ( 'support ".avif" image recognition' , testConfig , async ( ) => {
37+ const result = await describeImage ( 'fox.profile0.8bpc.yuv420.avif' )
38+ expect ( result . toLowerCase ( ) ) . toContain ( 'fox' )
39+ } )
40+
41+ it ( 'support ".tiff/.tif" image recognition' , testConfig , async ( ) => {
42+ const result = await describeImage ( 'julia.tif' )
43+ expect ( result . toLowerCase ( ) ) . toContain ( 'julia' )
44+ } )
45+
46+ it ( 'support ".svg" image recognition' , testConfig , async ( ) => {
47+ const result = await describeImage ( 'house.svg' )
48+ expect ( result . toLowerCase ( ) ) . toContain ( 'house' )
49+ } )
50+ } )
0 commit comments