forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathai_chat.nula
More file actions
45 lines (38 loc) · 1.19 KB
/
Copy pathai_chat.nula
File metadata and controls
45 lines (38 loc) · 1.19 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
// AI Chat — conversation loop with the LLM built-in effect.
// An agent actor maintains conversation memory and queries the
// inference provider via `perform Inference.ask`. Requires the
// `ai-runtime` feature (enabled by default).
//
// Run with: nulang examples/ai_chat.nula
actor ChatAgent {
state history: String = ""
state turn: Int = 0
behavior ask(prompt: String) {
self.turn = self.turn + 1
// Query the inference provider directly
let reply = perform Inference.ask(prompt)
self.history = self.history + "\nQ: " + prompt + "\nA: " + reply
perform IO.print(
"[Turn " + perform Int.to_string(self.turn) + "] " + reply
)
}
behavior summarize() {
let summary = perform Inference.ask(
"Summarize this conversation:\n" + self.history
)
perform IO.print("Summary: " + summary)
}
behavior reset() {
self.history = ""
self.turn = 0
perform IO.print("Conversation reset")
}
}
fn main() {
let bot = spawn ChatAgent {}
bot ! ask("What is the capital of France?")
bot ! ask("What is its population?")
bot ! summarize()
bot ! reset()
0
}