-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
92 lines (83 loc) · 2.82 KB
/
Copy pathmain.py
File metadata and controls
92 lines (83 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""Credential-free headless conversation through the complete injected engine."""
from __future__ import annotations
import asyncio
import json
from datetime import UTC, datetime, timedelta
from affect_kernel import (
AffectEngine,
AffectState,
GateResult,
MemoryCandidate,
PADMood,
)
from affect_kernel.adapters import (
InMemoryStateStore,
ScriptedModelAdapter,
StaticMemoryRetriever,
)
async def main() -> None:
conversation_id = "headless-demo"
store = InMemoryStateStore(
states={conversation_id: AffectState(mood=PADMood(0.1, 0.05, 0.0))}
)
model = ScriptedModelAdapter(
gates=[
GateResult(intent="CURIOSITY", should_respond=True, should_retrieve=True),
GateResult(
intent="VULNERABILITY", should_respond=True, should_retrieve=False
),
GateResult(intent="CURIOSITY", should_respond=True, should_retrieve=False),
],
responses=[
(
"That thread still has some pull. ",
"A fresh attempt can change its shape.",
),
("A rough page can still be evidence that you returned.",),
("Wanting to try tomorrow is the part worth carrying forward.",),
],
)
retriever = StaticMemoryRetriever(
[
MemoryCandidate(
id="demo-memory",
text="The user has been learning to sketch.",
distance=0.18,
timestamp=(datetime.now(UTC) - timedelta(days=2)).isoformat(),
significance=0.6,
)
]
)
engine = AffectEngine(
model=model,
store=store,
retriever=retriever,
conversation_id=conversation_id,
base_prompt="You are a thoughtful synthetic companion in a local demonstration.",
)
turns = (
"I picked up my sketchbook again.",
"The first page looks terrible.",
"Still, I want to try again tomorrow.",
)
print("Initial presence:")
print(json.dumps((await engine.presence()).to_dict(), indent=2))
for index, message in enumerate(turns, start=1):
print(f"\nTurn {index} — User: {message}")
print("Companion: ", end="", flush=True)
result = await engine.turn(
message,
on_token=lambda chunk: print(chunk, end="", flush=True),
)
print()
evidence = [memory.candidate.id for memory in result.memories]
mood = result.mood
print(
f"State: intent={result.intent}, "
f"PAD=({mood.valence:.4f}, {mood.arousal:.4f}, {mood.dominance:.4f}), "
f"evidence={evidence or 'none'}"
)
presence = await engine.presence()
print(f"Presence: {presence.line} ({presence.mode})")
if __name__ == "__main__":
asyncio.run(main())