feat(tests): use Qwen2.5 (Ollama) for invoice extraction tests and add helpers for model management; normalize dates and coerce numeric fields
This commit is contained in:
@@ -295,3 +295,66 @@ export async function ensurePaddleOcrVlFull(): Promise<boolean> {
|
||||
}
|
||||
return ensureService(IMAGES.paddleocrVlFull);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure an Ollama model is pulled and available
|
||||
* Uses the MiniCPM container (which runs Ollama) to pull the model
|
||||
*/
|
||||
export async function ensureOllamaModel(modelName: string): Promise<boolean> {
|
||||
const OLLAMA_URL = 'http://localhost:11434';
|
||||
|
||||
console.log(`\n[Ollama] Ensuring model: ${modelName}`);
|
||||
|
||||
// Check if model exists
|
||||
try {
|
||||
const response = await fetch(`${OLLAMA_URL}/api/tags`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
const models = data.models || [];
|
||||
const exists = models.some((m: { name: string }) =>
|
||||
m.name === modelName || m.name.startsWith(modelName.split(':')[0])
|
||||
);
|
||||
|
||||
if (exists) {
|
||||
console.log(`[Ollama] Model already available: ${modelName}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
console.log(`[Ollama] Cannot check models, Ollama may not be running`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pull the model
|
||||
console.log(`[Ollama] Pulling model: ${modelName} (this may take a while)...`);
|
||||
try {
|
||||
const response = await fetch(`${OLLAMA_URL}/api/pull`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ name: modelName, stream: false }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
console.log(`[Ollama] Model pulled successfully: ${modelName}`);
|
||||
return true;
|
||||
} else {
|
||||
console.log(`[Ollama] Failed to pull model: ${response.status}`);
|
||||
return false;
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(`[Ollama] Error pulling model: ${err}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure Qwen2.5 7B model is available (for text-only JSON extraction)
|
||||
*/
|
||||
export async function ensureQwen25(): Promise<boolean> {
|
||||
// First ensure the Ollama service (MiniCPM container) is running
|
||||
const ollamaOk = await ensureMiniCpm();
|
||||
if (!ollamaOk) return false;
|
||||
|
||||
// Then ensure the Qwen2.5 model is pulled
|
||||
return ensureOllamaModel('qwen2.5:7b');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user