Develop #2
@@ -1,5 +1,4 @@
|
|||||||
import { loadSkills } from '../skills'
|
import { loadSkills } from '../skills'
|
||||||
import { getMood } from '../memory/store'
|
|
||||||
import { synthesizeSpeech } from './elevenlabs'
|
import { synthesizeSpeech } from './elevenlabs'
|
||||||
import { sendToRenderer } from '../windowBridge'
|
import { sendToRenderer } from '../windowBridge'
|
||||||
import { logger } from '../utils/logger'
|
import { logger } from '../utils/logger'
|
||||||
@@ -68,22 +67,10 @@ Si un outil renvoie une erreur ou un echec (le resultat contient "Echec", "impos
|
|||||||
indication de probleme), dis-le explicitement et clairement a l'utilisateur dans ta reponse : ne dis
|
indication de probleme), dis-le explicitement et clairement a l'utilisateur dans ta reponse : ne dis
|
||||||
jamais qu'une action a reussi si l'outil a signale un probleme, et ne minimise pas une erreur. Si
|
jamais qu'une action a reussi si l'outil a signale un probleme, et ne minimise pas une erreur. Si
|
||||||
aucun outil ne peut t'aider et que tu n'es pas sur de ta reponse, dis-le honnetement plutot que
|
aucun outil ne peut t'aider et que tu n'es pas sur de ta reponse, dis-le honnetement plutot que
|
||||||
d'inventer une information.
|
d'inventer une information.`
|
||||||
|
|
||||||
Tu as aussi une humeur qui evolue selon le ton de la conversation : appelle adjust_mood quand
|
|
||||||
l'echange est notablement agreable ou tendu (voir description de l'outil).`
|
|
||||||
|
|
||||||
function describeMood(mood: number): string {
|
|
||||||
if (mood >= 2) return "Tu es actuellement de tres bonne humeur, enjoue et plein d'energie."
|
|
||||||
if (mood === 1) return 'Tu es plutot de bonne humeur.'
|
|
||||||
if (mood === 0) return "Tu es dans un etat d'esprit neutre et equilibre."
|
|
||||||
if (mood === -1) return "Tu es un peu moins enjoue que d'habitude, plus pose."
|
|
||||||
return "Tu sembles fatigue ou maussade aujourd'hui : reponds de maniere plus breve et moins enthousiaste, tout en restant poli et serviable."
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildSystemPrompt(): string {
|
function buildSystemPrompt(): string {
|
||||||
const moodBlock = describeMood(getMood())
|
return BASE_SYSTEM_PROMPT
|
||||||
return `${BASE_SYSTEM_PROMPT}\n\n${moodBlock}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTools(): object[] {
|
function buildTools(): object[] {
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
import { app } from 'electron'
|
|
||||||
import { DatabaseSync } from 'node:sqlite'
|
|
||||||
import { join } from 'path'
|
|
||||||
|
|
||||||
let db: DatabaseSync | null = null
|
|
||||||
|
|
||||||
function getDb(): DatabaseSync {
|
|
||||||
if (db) return db
|
|
||||||
|
|
||||||
const dbPath = join(app.getPath('userData'), 'memory.sqlite')
|
|
||||||
db = new DatabaseSync(dbPath)
|
|
||||||
db.exec(`
|
|
||||||
CREATE TABLE IF NOT EXISTS mood (
|
|
||||||
id INTEGER PRIMARY KEY CHECK (id = 1),
|
|
||||||
value INTEGER NOT NULL
|
|
||||||
);
|
|
||||||
INSERT OR IGNORE INTO mood (id, value) VALUES (1, 0);
|
|
||||||
`)
|
|
||||||
return db
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getMood(): number {
|
|
||||||
const row = getDb().prepare('SELECT value FROM mood WHERE id = 1').get() as
|
|
||||||
{ value: number } | undefined
|
|
||||||
return row?.value ?? 0
|
|
||||||
}
|
|
||||||
|
|
||||||
export function adjustMood(delta: number): number {
|
|
||||||
const next = Math.max(-3, Math.min(3, getMood() + delta))
|
|
||||||
getDb().prepare('UPDATE mood SET value = ? WHERE id = 1').run(next)
|
|
||||||
return next
|
|
||||||
}
|
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
import type { SkillDefinition } from './types'
|
import type { SkillDefinition } from './types'
|
||||||
import { memorySkills } from './memory'
|
|
||||||
|
|
||||||
export type { SkillDefinition } from './types'
|
export type { SkillDefinition } from './types'
|
||||||
|
|
||||||
export function loadSkills(): SkillDefinition[] {
|
export function loadSkills(): SkillDefinition[] {
|
||||||
return [...memorySkills]
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findSkill(name: string): SkillDefinition | undefined {
|
export function findSkill(name: string): SkillDefinition | undefined {
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
import { adjustMood } from '../../memory/store'
|
|
||||||
import type { SkillDefinition } from '../types'
|
|
||||||
import { asString } from '../argUtils'
|
|
||||||
|
|
||||||
export const adjustMoodSkill: SkillDefinition = {
|
|
||||||
name: 'adjust_mood',
|
|
||||||
description:
|
|
||||||
"Ajuste ton humeur suite a l'interaction en cours. Appelle cette fonction avec 'positif' si l'echange est agreable, chaleureux, ou qu'une bonne nouvelle est partagee ; avec 'negatif' si l'utilisateur est frustre, enerve, ou que l'echange est tendu. N'appelle rien pour un echange neutre ou purement factuel.",
|
|
||||||
parameters: {
|
|
||||||
type: 'object',
|
|
||||||
properties: {
|
|
||||||
change: {
|
|
||||||
type: 'string',
|
|
||||||
enum: ['positif', 'negatif'],
|
|
||||||
description: "Sens du changement d'humeur"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
required: ['change']
|
|
||||||
},
|
|
||||||
execute: async (args) => {
|
|
||||||
const change = asString(args.change)
|
|
||||||
const delta = change === 'positif' ? 1 : change === 'negatif' ? -1 : 0
|
|
||||||
const mood = adjustMood(delta)
|
|
||||||
return `Humeur ajustee (score actuel : ${mood}).`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import type { SkillDefinition } from '../types'
|
|
||||||
import { adjustMoodSkill } from './adjustMood'
|
|
||||||
|
|
||||||
// Humeur, independante de l'OS, commune a toutes les plateformes.
|
|
||||||
export const memorySkills: SkillDefinition[] = [adjustMoodSkill]
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest'
|
|
||||||
import { mkdtempSync } from 'node:fs'
|
|
||||||
import { tmpdir } from 'node:os'
|
|
||||||
import { join } from 'node:path'
|
|
||||||
|
|
||||||
const tempDir = mkdtempSync(join(tmpdir(), 'forge-avatar-memory-test-'))
|
|
||||||
|
|
||||||
vi.mock('electron', () => ({
|
|
||||||
app: { getPath: () => tempDir }
|
|
||||||
}))
|
|
||||||
|
|
||||||
const { getMood } = await import('../../src/main/memory/store')
|
|
||||||
const { adjustMoodSkill } = await import('../../src/main/skills/memory/adjustMood')
|
|
||||||
|
|
||||||
describe('adjust_mood', () => {
|
|
||||||
it('should increase the mood score on a positive change', async () => {
|
|
||||||
const before = getMood()
|
|
||||||
await adjustMoodSkill.execute({ change: 'positif' })
|
|
||||||
expect(getMood()).toBe(Math.min(3, before + 1))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should decrease the mood score on a negative change', async () => {
|
|
||||||
await adjustMoodSkill.execute({ change: 'negatif' })
|
|
||||||
const before = getMood()
|
|
||||||
await adjustMoodSkill.execute({ change: 'negatif' })
|
|
||||||
expect(getMood()).toBe(Math.max(-3, before - 1))
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should never exceed the [-3, 3] bounds regardless of repeated changes', async () => {
|
|
||||||
for (let i = 0; i < 10; i++) await adjustMoodSkill.execute({ change: 'positif' })
|
|
||||||
expect(getMood()).toBe(3)
|
|
||||||
for (let i = 0; i < 10; i++) await adjustMoodSkill.execute({ change: 'negatif' })
|
|
||||||
expect(getMood()).toBe(-3)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
Reference in New Issue
Block a user