-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmulti_llm_usage.py
More file actions
230 lines (181 loc) · 7.41 KB
/
Copy pathmulti_llm_usage.py
File metadata and controls
230 lines (181 loc) · 7.41 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""Example: Using Empathy Framework with Different LLMs
This shows how to use the EmpathyLLM wrapper with multiple providers
without needing to create custom wizards.
The framework automatically handles:
- Multi-LLM support (Claude, GPT-4, Gemini, local models)
- Empathy level progression (1-5)
- Conversation state and patterns
- Anticipatory predictions
"""
import asyncio
import os
from empathy_llm_toolkit.core import EmpathyLLM
async def example_claude_usage():
"""Example: Using Claude with Empathy Framework"""
print("=" * 60)
print("EXAMPLE 1: Claude (Anthropic) - Level 4 Anticipatory")
print("=" * 60)
# Initialize with Claude
llm = EmpathyLLM(
provider="anthropic",
target_level=4, # Level 4 Anticipatory
api_key=os.getenv("ANTHROPIC_API_KEY"),
use_prompt_caching=True, # Claude-specific feature
use_thinking=True, # Claude-specific feature
)
# Simple interaction - automatically uses appropriate empathy level
response = await llm.interact(
user_id="developer_123",
user_input="I'm building a Python web API with Flask. What should I consider?",
context={"project_type": "web_api", "language": "python"},
)
print(f"\nLevel Used: {response['level_used']} - {response['level_description']}")
print(f"Response: {response['content'][:200]}...")
print(f"\nMetadata: {response['metadata']}")
# As you continue interacting, the framework learns and progresses to higher levels
response2 = await llm.interact(
user_id="developer_123",
user_input="Now I need to add authentication",
context={"previous_topic": "flask_api"},
)
print("\n--- Second Interaction ---")
print(f"Level Used: {response2['level_used']}")
print(f"Proactive: {response2['proactive']}")
print(f"Response: {response2['content'][:200]}...")
async def example_openai_usage():
"""Example: Using OpenAI GPT-4 with Empathy Framework"""
print("\n" + "=" * 60)
print("EXAMPLE 2: OpenAI GPT-4 - Level 3 Proactive")
print("=" * 60)
llm = EmpathyLLM(
provider="openai",
target_level=3, # Level 3 Proactive
api_key=os.getenv("OPENAI_API_KEY"),
model="gpt-4-turbo-preview",
)
response = await llm.interact(
user_id="data_scientist_456",
user_input="Help me analyze this dataset for anomalies",
context={"dataset_size": "10000 rows", "domain": "finance"},
)
print(f"\nLevel Used: {response['level_used']} - {response['level_description']}")
print(f"Response: {response['content'][:200]}...")
async def example_local_model_usage():
"""Example: Using local Ollama model with Empathy Framework"""
print("\n" + "=" * 60)
print("EXAMPLE 3: Local Model (Ollama) - Level 2 Guided")
print("=" * 60)
llm = EmpathyLLM(
provider="local",
target_level=2, # Level 2 Guided
model="llama2",
endpoint="http://localhost:11434", # Ollama default
)
response = await llm.interact(
user_id="privacy_user_789",
user_input="I need help with my code but want to keep it private",
context={"privacy_required": True},
)
print(f"\nLevel Used: {response['level_used']} - {response['level_description']}")
print(f"Response: {response['content'][:200]}...")
print("\nNote: Running locally - zero cost, complete privacy")
async def example_switching_providers():
"""Example: Switching between providers dynamically"""
print("\n" + "=" * 60)
print("EXAMPLE 4: Dynamic Provider Switching")
print("=" * 60)
# Use Claude for complex reasoning
claude_llm = EmpathyLLM(
provider="anthropic",
target_level=4,
api_key=os.getenv("ANTHROPIC_API_KEY"),
)
# Use GPT-4 for fast responses
_openai_llm = EmpathyLLM(provider="openai", target_level=3, api_key=os.getenv("OPENAI_API_KEY"))
# Use local model for sensitive data
_local_llm = EmpathyLLM(provider="local", target_level=2, model="llama2")
print("\nProviders initialized:")
print(" ✓ Claude - for complex Level 4 anticipatory tasks")
print(" ✓ GPT-4 - for fast Level 3 proactive responses")
print(" ✓ Local - for privacy-sensitive Level 2 guided help")
# Route to appropriate provider based on task
task = "Predict potential security vulnerabilities in my codebase"
print(f"\nTask: {task}")
print("→ Routing to Claude (best for anticipatory predictions)")
response = await claude_llm.interact(
user_id="security_team",
user_input=task,
context={"codebase_size": "large", "security_critical": True},
)
print(f"Level Used: {response['level_used']}")
print(f"Proactive: {response['proactive']}")
async def example_pro_tier_features():
"""Example: Pro Tier features with Claude"""
print("\n" + "=" * 60)
print("EXAMPLE 5: Pro Tier Features (Powered by Claude)")
print("=" * 60)
llm = EmpathyLLM(
provider="anthropic",
target_level=4,
api_key=os.getenv("ANTHROPIC_API_KEY"),
use_prompt_caching=True, # 90% cost reduction
use_thinking=True, # Show reasoning process
model="claude-3-5-sonnet-20241022",
)
# Large codebase analysis (200K context)
codebase_files = [
{"path": "app.py", "content": "# Main application\n..."},
{"path": "models.py", "content": "# Database models\n..."},
{"path": "views.py", "content": "# API views\n..."},
# ... hundreds more files fit in 200K context
]
print("\nAnalyzing entire codebase (200K token context)...")
print(f"Files: {len(codebase_files)}")
response = await llm.interact(
user_id="enterprise_dev",
user_input="Analyze my entire codebase for security issues and predict future problems",
context={"codebase_files": codebase_files},
)
print(f"\nLevel Used: {response['level_used']} - {response['level_description']}")
print("Features Used:")
print(" • Extended context: 200K tokens (whole repo)")
print(" • Prompt caching: 90% cost savings on repeated scans")
print(f" • Thinking mode: {response['metadata'].get('thinking', 'N/A')[:100]}...")
print(" • Trajectory analysis: Predicts issues before they happen")
async def main():
"""Run all examples"""
print("\n")
print("╔" + "=" * 58 + "╗")
print("║ Empathy Framework - Multi-LLM Usage Examples ║")
print("╚" + "=" * 58 + "╝")
# Note: These examples require API keys to actually run
# Uncomment the ones you want to try:
# await example_claude_usage()
# await example_openai_usage()
# await example_local_model_usage()
# await example_switching_providers()
# await example_pro_tier_features()
print("\n" + "=" * 60)
print("SETUP INSTRUCTIONS")
print("=" * 60)
print(
"""
To run these examples:
1. Install the framework:
pip install empathy-framework
2. Set API keys (as needed):
export ANTHROPIC_API_KEY="your-key"
export OPENAI_API_KEY="your-key"
3. For local models (optional):
# Install Ollama: https://ollama.ai
ollama run llama2
4. Uncomment examples in main() and run:
python examples/multi_llm_usage.py
PRICING (Pro Tier):
- $99/year includes $300/year Claude API credits
- Claude recommended for Level 4 Anticipatory features
- Free tier: Bring your own API key for any provider
""",
)
if __name__ == "__main__":
asyncio.run(main())