Skip to content

Commit adb0c37

Browse files
committed
feature: add e2e tests for new supported image formats
1 parent de035a2 commit adb0c37

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { CreateRequest, ProgressResponse } from './interfaces.js'
1212

1313
const sharp = _sharp.default
1414

15-
const IMAGE_EXTENSIONS_TO_CONVERT = ['webp', 'avif', 'gif', 'svg', 'tiff']
15+
const IMAGE_EXTENSIONS_TO_CONVERT = ['webp', 'avif', 'gif', 'svg', 'tiff', 'tif']
1616
export class Ollama extends OllamaBrowser {
1717
async encodeImage(image: Uint8Array | Buffer | string): Promise<string> {
1818
if (typeof image !== 'string') {

test/e2e-image-formats.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
})

test/mocks/images/200w.gif

93.2 KB
Loading
78.9 KB
Binary file not shown.

test/mocks/images/house.svg

Lines changed: 37 additions & 0 deletions
Loading

test/mocks/images/julia.tif

457 KB
Binary file not shown.

0 commit comments

Comments
 (0)