-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_client.py
More file actions
204 lines (166 loc) · 5.94 KB
/
example_client.py
File metadata and controls
204 lines (166 loc) · 5.94 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
"""
Simple example client to interact with Acharya API
"""
import requests
import json
from typing import Optional
class AcharyaClient:
"""Simple client for Acharya API."""
def __init__(self, base_url: str = "http://localhost:8000"):
"""Initialize client."""
self.base_url = base_url
self.session_id: Optional[str] = None
self.student_id: Optional[int] = None
def start_conversation(
self,
name: str,
email: str,
conversation_type: str = "profiling"
) -> dict:
"""Start a new conversation."""
response = requests.post(
f"{self.base_url}/api/conversation/start",
json={
"student_name": name,
"student_email": email,
"conversation_type": conversation_type
}
)
response.raise_for_status()
data = response.json()
self.session_id = data["session_id"]
print(f"\n[Chanakya]: {data['message']}\n")
return data
def send_message(self, message: str, use_voice: bool = False) -> dict:
"""Send a message in the conversation."""
if not self.session_id:
raise ValueError("No active session. Start a conversation first.")
response = requests.post(
f"{self.base_url}/api/conversation/continue",
json={
"session_id": self.session_id,
"message": message,
"use_voice": use_voice
}
)
response.raise_for_status()
data = response.json()
print(f"\n[Chanakya]: {data['message']}\n")
if data.get("extracted_data"):
print(f"[Extracted Data]: {json.dumps(data['extracted_data'], indent=2)}\n")
return data
def interactive_session(self):
"""Run an interactive conversation session."""
print("=" * 60)
print("Acharya - AI Career Mentor")
print("=" * 60)
name = input("Enter your name: ")
email = input("Enter your email: ")
self.start_conversation(name, email)
print("Type 'quit' to end the conversation\n")
while True:
user_input = input("[You]: ")
if user_input.lower() in ['quit', 'exit', 'bye']:
print("\n[Acharya]: Thank you for the conversation! Keep learning and growing!")
break
if not user_input.strip():
continue
self.send_message(user_input)
def generate_roadmap(
self,
student_id: int,
career_goal: str,
timeline_months: int = 12
) -> dict:
"""Generate a career roadmap."""
response = requests.post(
f"{self.base_url}/api/roadmap/generate",
json={
"student_id": student_id,
"career_goal": career_goal,
"current_level": "beginner",
"target_level": "professional",
"timeline_months": timeline_months
}
)
response.raise_for_status()
data = response.json()
print(f"\n✓ Career Roadmap Generated!")
print(f"Career Goal: {career_goal}")
print(f"Timeline: {timeline_months} months")
print(f"Milestones: {data['milestones_count']}")
print(f"Resources: {data['resources_count']}")
print(f"Projects: {data['projects_count']}")
print(f"\nDownload PDF: {self.base_url}{data['pdf_url']}\n")
return data
def start_simulation(
self,
student_id: int,
career_role: str,
scenario_type: str = "interview"
) -> dict:
"""Start a career simulation."""
response = requests.post(
f"{self.base_url}/api/simulation/start",
json={
"student_id": student_id,
"career_role": career_role,
"scenario_type": scenario_type
}
)
response.raise_for_status()
data = response.json()
print(f"\n=== Career Simulation: {career_role} ===")
print(f"Scenario Type: {scenario_type}\n")
print(f"[Scenario]:\n{data['scenario']}\n")
return data
def respond_to_simulation(
self,
simulation_id: int,
response_text: str
) -> dict:
"""Submit response to simulation."""
response = requests.post(
f"{self.base_url}/api/simulation/respond",
json={
"simulation_id": simulation_id,
"student_response": response_text
}
)
response.raise_for_status()
data = response.json()
print(f"\n[Mentor Feedback]:\n{data['feedback']}\n")
print(f"Score: {data['score']}/100\n")
return data
def main():
"""Example usage."""
client = AcharyaClient()
print("\n" + "="*60)
print("Acharya API Client - Example Usage")
print("="*60 + "\n")
# Example 1: Interactive conversation
print("Example 1: Starting interactive conversation...\n")
client.interactive_session()
# Uncomment below for more examples:
# # Example 2: Generate roadmap
# print("\nExample 2: Generating career roadmap...\n")
# client.generate_roadmap(
# student_id=1,
# career_goal="Software Engineer",
# timeline_months=12
# )
# # Example 3: Career simulation
# print("\nExample 3: Starting career simulation...\n")
# sim = client.start_simulation(
# student_id=1,
# career_role="Product Manager",
# scenario_type="meeting"
# )
#
# response = input("\n[Your Response]: ")
# client.respond_to_simulation(
# simulation_id=sim["simulation_id"],
# response_text=response
# )
if __name__ == "__main__":
main()