33800 Docs

← Retour

Proposition: NeedFinder passe par AI Orchestrator pour Ollama

Date: 20/01/2026 00:21 Statut: En attente de validation


Contexte

NeedFinder appelle actuellement Ollama directement sur win11:11434 depuis deux fichiers:

L'AI Orchestrator (prod-portainer:5501) dispose déjà d'un executor Ollama fonctionnel (execute_ollama_job) qui:

Problème actuel

NeedFinder (dev-portainer:5200)
        │
        └──► Ollama DIRECT (win11:11434)  ← Bypass du système de queue

Risques:

Solution proposée

NeedFinder (dev-portainer:5200)
        │
        └──► AI Orchestrator (prod-portainer:5501)
                    │
                    └──► Queue Redis → Ollama (win11:11434)

Modifications à apporter

1. Créer un module client orchestrator (src/services/orchestrator-client.ts):

const ORCHESTRATOR_URL = 'http://192.168.1.12:5501';

export async function submitOllamaJob(prompt: string, options?: {
  model?: string;
  temperature?: number;
  maxTokens?: number;
  priority?: number;
}): Promise<string> {
  // 1. Créer le job
  const response = await fetch(`${ORCHESTRATOR_URL}/api/jobs`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      tool_id: 'ollama',
      job_type: 'generate',
      input_params: {
        prompt,
        model: options?.model || 'mistral:latest',
        temperature: options?.temperature || 0.3,
        max_tokens: options?.maxTokens || 500
      },
      priority: options?.priority || 0
    })
  });

  const job = await response.json();
  const jobId = job.id;

  // 2. Polling jusqu'à completion
  while (true) {
    await new Promise(r => setTimeout(r, 1000)); // 1s entre polls

    const statusResp = await fetch(`${ORCHESTRATOR_URL}/api/jobs/${jobId}`);
    const status = await statusResp.json();

    if (status.status === 'completed') {
      return status.output_result?.response || '';
    }
    if (status.status === 'failed') {
      throw new Error(status.error_message || 'Job failed');
    }
  }
}

2. Modifier analyzer.ts:

// AVANT
async function callOllama(prompt: string): Promise<string> {
  const response = await fetch(`${OLLAMA_URL}/api/generate`, {...});
  ...
}

// APRÈS
import { submitOllamaJob } from './orchestrator-client';

async function callOllama(prompt: string): Promise<string> {
  return submitOllamaJob(prompt, {
    model: 'mistral:latest',
    temperature: 0.3,
    maxTokens: 500,
    priority: 0  // Normal priority
  });
}

3. Modifier matcher.ts (même changement)

Fichiers impactés

Fichier Changement
src/services/orchestrator-client.ts NOUVEAU - Client API orchestrator
src/services/analyzer.ts Remplacer callOllama
src/services/matcher.ts Remplacer callOllama
.env / docker-compose.yml Ajouter ORCHESTRATOR_URL

Configuration requise

# NeedFinder .env
ORCHESTRATOR_URL=http://192.168.1.12:5501
# Supprimer: OLLAMA_URL, OLLAMA_MODEL (plus utilisés directement)

Avantages

  1. Centralisation - Toutes les requêtes IA passent par l'orchestrator
  2. Queue partagée - Pas de conflit avec ComfyUI, Fooocus, etc.
  3. Historique - Jobs visibles dans PostgreSQL et dashboard
  4. Monitoring - Stats dans https://dashboard.33800.nowhere84.com/ai-jobs.html

Inconvénients / Points d'attention

  1. Latence ajoutée - Polling au lieu d'appel direct (~1-2s de plus par requête)
  2. Dépendance - Si l'orchestrator est down, NeedFinder ne peut plus analyser
  3. Réseau - Communication dev-portainer → prod-portainer (même LAN, OK)

Alternatives considérées

Option Pros Cons
A. Via Orchestrator (proposé) Centralisation, queue, historique Latence légèrement plus élevée
B. Garder appel direct Rapide, simple Pas de gestion conflits VRAM
C. Déplacer NeedFinder sur PROD Plus proche de l'orchestrator Mélange DEV/PROD

Plan d'exécution

  1. [ ] Créer orchestrator-client.ts sur dev-portainer
  2. [ ] Modifier analyzer.ts pour utiliser le client
  3. [ ] Modifier matcher.ts pour utiliser le client
  4. [ ] Mettre à jour .env et docker-compose.yml
  5. [ ] Rebuild container NeedFinder
  6. [ ] Tester avec /api/analyze et /api/match
  7. [ ] Commit + push GitLab

Validation requise


En attente de ta validation avant exécution.