-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_app.py
More file actions
executable file
·66 lines (48 loc) · 1.59 KB
/
Copy pathsimple_app.py
File metadata and controls
executable file
·66 lines (48 loc) · 1.59 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
#!/usr/bin/env python3
"""
Simple Reflexive Python app demonstrating reflexive.chat()
This shows how to use the Python SDK to add AI capabilities to your app.
Run in two ways:
1. Via Reflexive CLI (recommended):
reflexive --debug simple_app.py
2. Standalone with spawned CLI:
python simple_app.py
"""
import reflexive
import time
# Option 1: Detect CLI mode automatically
# When run with `reflexive simple_app.py`, this connects to parent
# When run standalone, chat() won't work unless spawn_cli=True
r = reflexive.make_reflexive({
'spawn_cli': True, # Set to True to spawn CLI in background
'debug': True, # Enable debugger
'port': 3099
})
print("🐍 Reflexive Python Example")
print("=" * 50)
print()
# Track some state
counter = 0
for i in range(5):
counter += 1
# Update state (visible to AI)
r.set_state('counter', counter)
r.set_state('iteration', i + 1)
r.set_state('timestamp', time.time())
# Log activity
r.log('info', f'Processing iteration {i + 1}')
print(f"Iteration {i + 1}: counter = {counter}")
# Ask AI for insights
if i == 2:
print("\n" + "=" * 50)
print("Asking AI to analyze the counter...")
response = r.chat("What is the current value of counter? Explain what the app is doing.")
print(f"\n🤖 AI Response:\n{response}\n")
print("=" * 50 + "\n")
time.sleep(1)
print("\n✅ Done!")
print(f"Final counter: {counter}")
# One more AI interaction
print("\nAsking AI for a final summary...")
summary = r.chat("Summarize what this app did. Be brief.")
print(f"\n🤖 Summary:\n{summary}")