-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (39 loc) · 1.87 KB
/
main.py
File metadata and controls
50 lines (39 loc) · 1.87 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
import json
import os
from src.agent.capability import MatchingCapability
from src.main import AgentWorker
from src.agent.capability_worker import CapabilityWorker
# =============================================================================
# BASIC ADVISOR
# A simple daily life advisor that asks for a problem, generates advice
# using the LLM, and collects feedback.
# =============================================================================
INTRO_PROMPT = "Hi! I'm your daily life advisor. Tell me about a problem you're facing."
FEEDBACK_PROMPT = " Are you satisfied with the advice?"
FINAL_PROMPT = "Thank you for using the daily life advisor. Goodbye!"
class BasicAdvisorCapability(MatchingCapability):
worker: AgentWorker = None
capability_worker: CapabilityWorker = None
#{{register_capability}}
def call(self, worker: AgentWorker):
self.worker = worker
self.capability_worker = CapabilityWorker(self.worker)
self.worker.session_tasks.create(self.give_advice())
async def give_advice(self):
# Introduce the advisor and ask for the user's problem
await self.capability_worker.speak(INTRO_PROMPT)
# Wait for the user to describe their problem
user_problem = await self.capability_worker.user_response()
# Generate a solution using the LLM
solution_prompt = (
f"The user has the following problem: {user_problem}. "
"Provide a helpful solution in just 1 or 2 sentences."
)
solution = self.capability_worker.text_to_text_response(solution_prompt)
# Speak the solution and ask for feedback
user_feedback = await self.capability_worker.run_io_loop(
solution + FEEDBACK_PROMPT
)
# Thank the user and exit
await self.capability_worker.speak(FINAL_PROMPT)
self.capability_worker.resume_normal_flow()