diff --git a/src/index.ts b/src/index.ts index 91457ce..0f0459b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,7 +12,7 @@ import type { CreateRequest, ProgressResponse } from './interfaces.js' const sharp = _sharp.default -const IMAGE_EXTENSIONS_TO_CONVERT = ['webp', 'avif', 'gif', 'svg', 'tiff'] +const IMAGE_EXTENSIONS_TO_CONVERT = ['webp', 'avif', 'gif', 'svg', 'tiff', 'tif'] export class Ollama extends OllamaBrowser { async encodeImage(image: Uint8Array | Buffer | string): Promise { if (typeof image !== 'string') { diff --git a/test/e2e-image-formats.spec.ts b/test/e2e-image-formats.spec.ts new file mode 100644 index 0000000..49f0527 --- /dev/null +++ b/test/e2e-image-formats.spec.ts @@ -0,0 +1,49 @@ +import { describe, it, expect } from 'vitest' +import { Ollama } from '../src/index' +import path from 'path' +import { fileURLToPath } from 'url' +import { dirname } from 'path' + + +async function describeImage(imageName: string) { + const __filename = fileURLToPath(import.meta.url) + const __dirname = dirname(__filename) + const instance = new Ollama() + const imagePath = path.resolve(__dirname, `./mocks/images/${imageName}`) + const response = await instance.chat({ + model: 'llama3.2-vision', + messages: [{ role: 'user', content: 'what is this?', images: [imagePath] }], + }) + return response.message.content; +} + +const testConfig = { + timeout: 5 * 60 * 1000, // 5 minutes +} + +describe('Ollama | Nodejs | Vision image formats', () => { + it('support ".webp" image recognition', testConfig, async () => { + const result = await describeImage('WebP-Gradient.webp') + expect(result.toLowerCase()).toContain('gradient') + }) + + it('support ".gif" image recognition', testConfig, async () => { + const result = await describeImage('200w.gif') + expect(result.toLowerCase()).toContain('cat') + }) + + it('support ".avif" image recognition', testConfig, async () => { + const result = await describeImage('fox.profile0.8bpc.yuv420.avif') + expect(result.toLowerCase()).toContain('fox') + }) + + it('support ".tiff/.tif" image recognition', testConfig, async () => { + const result = await describeImage('julia.tif') + expect(result.toLowerCase()).toContain('julia') + }) + + it('support ".svg" image recognition', testConfig, async () => { + const result = await describeImage('house.svg') + expect(result.toLowerCase()).toContain('house') + }) +}) \ No newline at end of file diff --git a/test/mocks/images/200w.gif b/test/mocks/images/200w.gif new file mode 100644 index 0000000..b347d2e Binary files /dev/null and b/test/mocks/images/200w.gif differ diff --git a/test/mocks/images/fox.profile0.8bpc.yuv420.avif b/test/mocks/images/fox.profile0.8bpc.yuv420.avif new file mode 100644 index 0000000..2bae4c7 Binary files /dev/null and b/test/mocks/images/fox.profile0.8bpc.yuv420.avif differ diff --git a/test/mocks/images/house.svg b/test/mocks/images/house.svg new file mode 100644 index 0000000..9714661 --- /dev/null +++ b/test/mocks/images/house.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/mocks/images/julia.tif b/test/mocks/images/julia.tif new file mode 100644 index 0000000..94ff2d2 Binary files /dev/null and b/test/mocks/images/julia.tif differ