fix(advisor): Compliance-Advisor auf prod reparieren — RAG via ai-sdk (bge-m3) + OVH-LLM
CI / detect-changes (push) Successful in 6s
CI / branch-name (push) Has been skipped
CI / secret-scan (push) Has been skipped
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / build-sha-integrity (push) Successful in 7s
CI / validate-canonical-controls (push) Successful in 6s
CI / loc-budget (push) Successful in 19s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m4s
CI / test-go (push) Successful in 58s
CI / iace-gt-coverage (push) Successful in 16s
CI / test-python-backend (push) Has been skipped
CI / test-python-document-crawler (push) Has been skipped
CI / test-python-dsms-gateway (push) Has been skipped
CI / detect-changes (push) Successful in 6s
CI / branch-name (push) Has been skipped
CI / secret-scan (push) Has been skipped
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / build-sha-integrity (push) Successful in 7s
CI / validate-canonical-controls (push) Successful in 6s
CI / loc-budget (push) Successful in 19s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 3m4s
CI / test-go (push) Successful in 58s
CI / iace-gt-coverage (push) Successful in 16s
CI / test-python-backend (push) Has been skipped
CI / test-python-document-crawler (push) Has been skipped
CI / test-python-dsms-gateway (push) Has been skipped
Der Floating-Compliance-Advisor war auf prod kaputt (502): RAG ging ueber rag-service:8097 (auf prod nicht vorhanden) und der Chat ueber OLLAMA_URL=ollama-embed (embedding-only, kein qwen2.5vl). - RAG laeuft jetzt ueber die ai-compliance-sdk /sdk/v1/rag/search (bge-m3, prod-erreichbar) statt rag-service -> profitiert vom reicheren Embedding. (lib/sdk/agents/advisor-rag.ts) - LLM-Kaskade: OVH/LiteLLM (gpt-oss-120b) zuerst, Ollama als Dev-Fallback. (lib/sdk/agents/advisor-llm.ts; OVH-Env via orca-infra admin-Block) - ai-sdk: bp_compliance_recht in AllowedCollections ergaenzt (Whitelist war inkonsistent — die Fehlermeldung listete es bereits als erlaubt). - Route auf die Module umgestellt (duenn); Controls-Augmentation unveraendert. - Tests: advisor-rag + advisor-llm. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Tests fuer die LLM-Stream-Parser des Advisors (Ollama-NDJSON + OVH/OpenAI-SSE).
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { parseOllamaLine, parseSSELine } from '../advisor-llm'
|
||||
|
||||
describe('parseOllamaLine', () => {
|
||||
it('extrahiert message.content', () => {
|
||||
expect(parseOllamaLine('{"message":{"content":"Hallo"}}')).toBe('Hallo')
|
||||
})
|
||||
it('ignoriert leere/kaputte Zeilen', () => {
|
||||
expect(parseOllamaLine('')).toBeNull()
|
||||
expect(parseOllamaLine(' ')).toBeNull()
|
||||
expect(parseOllamaLine('not-json')).toBeNull()
|
||||
expect(parseOllamaLine('{"message":{}}')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('parseSSELine', () => {
|
||||
it('extrahiert choices[0].delta.content aus data:-Zeilen', () => {
|
||||
expect(parseSSELine('data: {"choices":[{"delta":{"content":"Hi"}}]}')).toBe('Hi')
|
||||
})
|
||||
it('ignoriert [DONE], Nicht-data-Zeilen und kaputtes JSON', () => {
|
||||
expect(parseSSELine('data: [DONE]')).toBeNull()
|
||||
expect(parseSSELine('event: message')).toBeNull()
|
||||
expect(parseSSELine('')).toBeNull()
|
||||
expect(parseSSELine('data: {bad json')).toBeNull()
|
||||
expect(parseSSELine('data: {"choices":[{"delta":{}}]}')).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,75 @@
|
||||
/**
|
||||
* Tests fuer die Advisor-RAG-Suche (ai-sdk, bge-m3).
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
|
||||
const mockFetch = vi.fn()
|
||||
vi.stubGlobal('fetch', mockFetch)
|
||||
|
||||
describe('advisor-rag', () => {
|
||||
let mod: typeof import('../advisor-rag')
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.resetModules()
|
||||
mockFetch.mockReset()
|
||||
mod = await import('../advisor-rag')
|
||||
})
|
||||
|
||||
describe('mapSdkResults', () => {
|
||||
it('mappt ai-sdk-Felder auf {content, source, score}', () => {
|
||||
const out = mod.mapSdkResults([
|
||||
{ text: 'Art. 35 DSGVO ...', regulation_short: 'DSGVO', score: 0.91 },
|
||||
])
|
||||
expect(out).toEqual([{ content: 'Art. 35 DSGVO ...', source: 'DSGVO', score: 0.91 }])
|
||||
})
|
||||
|
||||
it('faellt auf regulation_name/code zurueck und filtert leere Inhalte', () => {
|
||||
const out = mod.mapSdkResults([
|
||||
{ text: '', regulation_short: 'X' },
|
||||
{ text: 'Inhalt', regulation_name: 'BDSG' },
|
||||
{ text: 'Inhalt2', regulation_code: 'EU_2016_679' },
|
||||
])
|
||||
expect(out).toEqual([
|
||||
{ content: 'Inhalt', source: 'BDSG', score: 0 },
|
||||
{ content: 'Inhalt2', source: 'EU_2016_679', score: 0 },
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('queryAdvisorRAG', () => {
|
||||
it('fragt alle 6 Collections ab und formatiert die Treffer', async () => {
|
||||
mockFetch.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ results: [{ text: 'Inhalt A', regulation_short: 'DSGVO', score: 0.9 }] }),
|
||||
})
|
||||
const result = await mod.queryAdvisorRAG('Was ist eine DSFA?')
|
||||
expect(result).toContain('[Quelle 1: DSGVO]')
|
||||
expect(result).toContain('Inhalt A')
|
||||
expect(mockFetch).toHaveBeenCalledTimes(mod.COMPLIANCE_COLLECTIONS.length)
|
||||
})
|
||||
|
||||
it('ruft die ai-sdk /sdk/v1/rag/search mit collection + top_k auf', async () => {
|
||||
mockFetch.mockResolvedValue({ ok: true, json: async () => ({ results: [] }) })
|
||||
await mod.queryAdvisorRAG('test')
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
expect.stringContaining('/sdk/v1/rag/search'),
|
||||
expect.objectContaining({ method: 'POST' }),
|
||||
)
|
||||
const body = JSON.parse(mockFetch.mock.calls[0][1].body)
|
||||
expect(body).toMatchObject({ query: 'test', top_k: 3 })
|
||||
expect(mod.COMPLIANCE_COLLECTIONS).toContain(body.collection)
|
||||
})
|
||||
|
||||
it('liefert leeren String wenn das RAG-Backend nicht erreichbar ist (graceful)', async () => {
|
||||
mockFetch.mockRejectedValue(new Error('connection refused'))
|
||||
const result = await mod.queryAdvisorRAG('test')
|
||||
expect(result).toBe('')
|
||||
})
|
||||
|
||||
it('umfasst genau die 6 Compliance-Collections', () => {
|
||||
expect(mod.COMPLIANCE_COLLECTIONS).toHaveLength(6)
|
||||
expect(mod.COMPLIANCE_COLLECTIONS).toContain('bp_compliance_recht')
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user