Skip to content

Commit a9d6da6

Browse files
committed
test
1 parent fc44837 commit a9d6da6

File tree

7 files changed

+35
-37
lines changed

7 files changed

+35
-37
lines changed

docker-compose.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ services:
1616
APP_FRONTEND_URL: ${APP_FRONTEND_URL}
1717
BODY_PARSER_JSON_LIMIT: ${BODY_PARSER_JSON_LIMIT}
1818
ELASTIC_URL: ${ELASTIC_URL}
19-
# VLM: Uncomment to use Ollama running on host machine
2019
OLLAMA_BASE_URL: http://host.docker.internal:11434
2120
ports:
2221
- "${APP_PORT}:3000"
2322
expose:
2423
- "${APP_PORT}"
25-
# VLM: Uncomment to use Ollama running on host machine
2624
extra_hosts:
2725
- host.docker.internal:host-gateway
2826
depends_on:

src/compare/libs/vlm/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Set project's image comparison to `vlm` with config:
4141
}
4242
```
4343

44-
Optional custom prompt:
44+
Optional custom prompt (replaces default system prompt):
4545
```json
4646
{
4747
"model": "llava:7b",
@@ -50,11 +50,15 @@ Optional custom prompt:
5050
}
5151
```
5252

53+
**Note:** The `prompt` field replaces the entire system prompt. If omitted, a default system prompt is used that focuses on semantic differences while ignoring rendering artifacts.
54+
5355
## Recommended Models
5456

5557
| Model | Size | Speed | Accuracy | Best For |
5658
|-------|------|-------|----------|----------|
57-
| `llava:7b` | 4.7GB | ⚡⚡ | ⭐⭐⭐ | **Recommended** - best balance |
59+
| `llava:7b` | 4.7GB | ⚡⚡ | ⭐⭐⭐ | **Recommended** - best balance (minimal) |
60+
| `qwen3-vl:8b` | ~8GB | ⚡⚡ | ⭐⭐⭐ | Minimal model option |
61+
| `gemma3:latest` | ~ | ⚡⚡ | ⭐⭐⭐ | Minimal model option |
5862
| `llava:13b` | 8GB || ⭐⭐⭐⭐ | Best accuracy |
5963
| `moondream` | 1.7GB | ⚡⚡⚡ | ⭐⭐ | Fast, may hallucinate |
6064
| `minicpm-v` | 5.5GB | ⚡⚡ | ⭐⭐⭐ | Good alternative |
@@ -63,16 +67,23 @@ Optional custom prompt:
6367

6468
| Option | Type | Default | Description |
6569
|--------|------|---------|-------------|
66-
| `model` | string | `moondream` | Ollama vision model name |
67-
| `prompt` | string | `""` | Custom context prepended to system prompt |
68-
| `temperature` | number | `0.1` | Lower = more consistent results |
70+
| `model` | string | `llava:7b` | Ollama vision model name |
71+
| `prompt` | string | System prompt (see below) | Custom prompt for image comparison |
72+
| `temperature` | number | `0.1` | Lower = more consistent results (0.0-1.0) |
6973

7074
## How It Works
7175

7276
1. VLM analyzes both images semantically
73-
2. Returns `YES` (pass) or `NO` (fail) based on meaningful differences
74-
3. Ignores technical differences (anti-aliasing, sub-pixel, minor spacing)
75-
4. Provides description of differences found
77+
2. Returns JSON with `{"identical": true/false, "description": "..."}`
78+
3. `identical: true` = images match (pass), `identical: false` = differences found (fail)
79+
4. Ignores technical differences (anti-aliasing, shadows, 1-2px shifts)
80+
5. Provides description of differences found
81+
82+
### Default System Prompt
83+
84+
The default prompt instructs the model to:
85+
- **CHECK** for: data changes, missing/added elements, state changes, structural differences
86+
- **IGNORE**: rendering artifacts, anti-aliasing, shadows, minor pixel shifts
7687

7788
## API Endpoints
7889

@@ -83,10 +94,3 @@ GET /ollama/models
8394
# Compare two images (for testing)
8495
POST /ollama/compare?model=llava:7b&prompt=<prompt>&temperature=0.1
8596
```
86-
87-
**Example:**
88-
```bash
89-
curl -X POST "http://localhost:3000/ollama/compare?model=llava:7b&prompt=Are%20these%20images%20the%20same&temperature=0.1" \
90-
-F "images=@baseline.png" \
91-
-F "images=@comparison.png"
92-
```

src/compare/libs/vlm/ollama.controller.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { Controller, Get, Post, Query, HttpException, HttpStatus, UseInterceptors, UploadedFiles } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Query,
6+
HttpException,
7+
HttpStatus,
8+
UseInterceptors,
9+
UploadedFiles,
10+
} from '@nestjs/common';
211
import { FilesInterceptor } from '@nestjs/platform-express';
312
import { ApiTags, ApiConsumes, ApiBody } from '@nestjs/swagger';
413
import { OllamaService } from './ollama.service';

src/compare/libs/vlm/ollama.service.spec.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ describe('OllamaService', () => {
5252
text: () => Promise.resolve('Internal Server Error'),
5353
});
5454

55-
await expect(
56-
service.generate({ model: 'llava', prompt: 'Test' })
57-
).rejects.toThrow('Ollama API returned status 500');
55+
await expect(service.generate({ model: 'llava', prompt: 'Test' })).rejects.toThrow(
56+
'Ollama API returned status 500'
57+
);
5858
});
5959

6060
it('should throw error when OLLAMA_BASE_URL is not configured', async () => {
@@ -65,9 +65,7 @@ describe('OllamaService', () => {
6565
} as any;
6666
const newService = new OllamaService(mockConfigService);
6767

68-
await expect(
69-
newService.generate({ model: 'llava', prompt: 'Test' })
70-
).rejects.toThrow('OLLAMA_BASE_URL');
68+
await expect(newService.generate({ model: 'llava', prompt: 'Test' })).rejects.toThrow('OLLAMA_BASE_URL');
7169
});
7270
});
7371

src/compare/libs/vlm/ollama.service.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { Injectable, Logger } from '@nestjs/common';
22
import { ConfigService } from '@nestjs/config';
3-
import {
4-
OllamaGenerateRequest,
5-
OllamaGenerateResponse,
6-
OllamaModel,
7-
OllamaModelsResponse,
8-
} from './ollama.types';
3+
import { OllamaGenerateRequest, OllamaGenerateResponse, OllamaModel, OllamaModelsResponse } from './ollama.types';
94

105
@Injectable()
116
export class OllamaService {
@@ -60,4 +55,3 @@ export class OllamaService {
6055
}
6156
}
6257
}
63-

src/compare/libs/vlm/ollama.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,3 @@ export interface OllamaModel {
3838
export interface OllamaModelsResponse {
3939
models: OllamaModel[];
4040
}
41-

src/compare/libs/vlm/vlm.service.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ import { NO_BASELINE_RESULT } from '../consts';
66
import { DEFAULT_CONFIG, VlmService } from './vlm.service';
77
import { OllamaService } from './ollama.service';
88

9-
const initService = async ({
10-
getImageMock = jest.fn(),
11-
saveImageMock = jest.fn(),
12-
ollamaGenerateMock = jest.fn(),
13-
}) => {
9+
const initService = async ({ getImageMock = jest.fn(), saveImageMock = jest.fn(), ollamaGenerateMock = jest.fn() }) => {
1410
const module: TestingModule = await Test.createTestingModule({
1511
providers: [
1612
VlmService,

0 commit comments

Comments
 (0)