P1: robust JSON structured output (markdown fence cleanup, structured-output instruction, subAgent excluded from base schema to prevent gemma4:E4B silence); P2: bge-m3 embeddings via Ollama + cosine search; full pipeline verified on gemma4:E4B
This commit is contained in:
1 parent
a6fde100ca
commit
89b73db8a4
2 files changed
+77
-5
No files matched your search
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Интеграционный тест полного пайплайна (P1).
|
||||
* Проверка: LLM (gemma4:E4B) → parseSparkOutput → memory → consolidation.
|
||||
* Spark X2.5-4B в этом Ollama не грузится (unknown architecture), поэтому
|
||||
* временно используем gemma4:E4B.
|
||||
*/
|
||||
import { SparkLLMClient } from './src/mind.js';
|
||||
import { MemorySystem } from './src/memory.js';
|
||||
import { OllamaEmbeddingClient } from './src/embedding.js';
|
||||
import { DEFAULT_PERSONA } from './src/persona.js';
|
||||
|
||||
(async () => {
|
||||
const llm = new SparkLLMClient('http://localhost:11434', 'gemma4:E4B');
|
||||
const embedding = new OllamaEmbeddingClient('http://localhost:11434');
|
||||
const memory = new MemorySystem(10, embedding);
|
||||
|
||||
const systemPrompt = 'Ты ассистент. Отвечай JSON: {thoughts, emotion:{valence,arousal}, decision:{reply, subAgent}}';
|
||||
const context = 'Ты думал про Yandex Direct. Напиши мысли и решение.';
|
||||
|
||||
console.log('[test] LLM generate...');
|
||||
const result = await llm.generate(context, systemPrompt);
|
||||
console.log('[test] thoughts:', JSON.stringify(result.thoughts));
|
||||
console.log('[test] emotion:', JSON.stringify(result.emotion));
|
||||
console.log('[test] decision:', JSON.stringify(result.decision));
|
||||
|
||||
// Raw-запрос, чтобы увидеть что реально вернула модель
|
||||
const raw = await fetch('http://localhost:11434/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
model: 'gemma4:E4B',
|
||||
response_format: { type: 'json_object' },
|
||||
messages: [
|
||||
{ role: 'system', content: 'Отвечай только JSON: {thoughts, emotion:{valence,arousal}, decision:{reply}}' },
|
||||
{ role: 'user', content: context },
|
||||
],
|
||||
temperature: 0.7,
|
||||
max_tokens: 512,
|
||||
}),
|
||||
});
|
||||
const rawText = await (await raw.json()).choices?.[0]?.message?.content ?? '';
|
||||
console.log('[test] RAW:', JSON.stringify(rawText));
|
||||
|
||||
console.log('[test] addThought...');
|
||||
memory.addThought(result.thoughts);
|
||||
|
||||
console.log('[test] consolidation...');
|
||||
await memory.consolidate(memory.recentThoughts());
|
||||
console.log('[test] long-term size:', memory['longTerm'].length);
|
||||
|
||||
console.log('[test] OK — полный пайплайн работает');
|
||||
})();
|
||||
Reference in new issue
Block a user