Skip to content

Commit 96faf31

Browse files
committed
Extract configuration variables to config module
1 parent 9b8e209 commit 96faf31

File tree

5 files changed

+156
-79
lines changed

5 files changed

+156
-79
lines changed

coffee_ws/README.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ ros2 run coffee_machine_control coffee_machine_control_node --ros-args -p mac_ad
307307

308308
Or use the launch file (recommended)
309309
```
310-
ros2 launch coffee_machine_control coffee_machine_control.launch.py # Uses default MAC: 9C:95:6E:61:B6:2C
310+
ros2 launch coffee_machine_control coffee_machine_control.launch.py # Uses default MAC: 9C:95:6E:61B6:2C
311311
ros2 launch coffee_machine_control coffee_machine_control.launch.py mac_address:=<your_machine_mac>
312312
```
313313

@@ -337,6 +337,67 @@ ros2 service call /coffee_command coffee_machine_control_msgs/srv/CoffeeCommand
337337
ros2 service call /coffee_machine/get_status coffee_machine_control_msgs/srv/MachineStatusRequest "{}"
338338
```
339339

340+
## Launching Sui Coffee Order Indexer
341+
342+
### Sui Blockchain Coffee Ordering System
343+
The Sui Coffee Order Indexer monitors coffee club events from the Sui blockchain and publishes them to ROS2 topics for coffee machine automation.
344+
345+
```bash
346+
# Build the indexer package
347+
colcon build --packages-select sui_coffee_order_indexer
348+
source install/setup.bash
349+
350+
# Launch with coffee club contract (replace with actual package ID)
351+
ros2 launch sui_coffee_order_indexer indexer.launch.py \
352+
"package_id:='0x2ee032ffc863a74a785ac3003fb8b61d639d9095b4431fdc1b12181c0a2a8c13'"
353+
354+
# Launch with different network (mainnet, testnet, devnet)
355+
ros2 launch sui_coffee_order_indexer indexer.launch.py \
356+
"package_id:='0x2ee032ffc863a74a785ac3003fb8b61d639d9095b4431fdc1b12181c0a2a8c13'" \
357+
"network:='mainnet'"
358+
359+
# Launch with custom polling interval and database location
360+
ros2 launch sui_coffee_order_indexer indexer.launch.py \
361+
"package_id:='0x2ee032ffc863a74a785ac3003fb8b61d639d9095b4431fdc1b12181c0a2a8c13'" \
362+
"polling_interval_ms:=2000" \
363+
"database_url:='file:/var/lib/sui_indexer/sui_indexer.db'"
364+
```
365+
366+
**Architecture:** The indexer follows a decoupled design - it only publishes blockchain events to ROS2 topics. Coffee machine integration is handled by separate controller nodes that subscribe to these events.
367+
368+
**Topics Published:**
369+
- `/sui_events` - Coffee club events from the Sui blockchain
370+
- `/indexer_status` - Indexer status and health information
371+
372+
**Events Monitored:**
373+
- `CafeCreated` - New coffee shop registrations
374+
- `CoffeeOrderCreated` - New coffee orders placed
375+
- `CoffeeOrderUpdated` - Order status changes (Processing, Completed, etc.)
376+
377+
**Database:** Events are stored persistently in `<workspace_root>/data/sui_indexer/sui_indexer.db` to survive builds and restarts.
378+
379+
### Integration with Coffee Machine
380+
To create a complete blockchain-to-coffee flow, combine with a coffee controller node:
381+
382+
```bash
383+
# Terminal 1: Run the blockchain indexer
384+
ros2 launch sui_coffee_order_indexer indexer.launch.py "package_id:='0x...'"
385+
386+
# Terminal 2: Run coffee machine control
387+
ros2 launch coffee_machine_control coffee_machine_control.launch.py
388+
389+
# Terminal 3: Run a custom coffee controller node (to be implemented)
390+
# This node would:
391+
# - Subscribe to /sui_events
392+
# - Filter for "Processing" status orders
393+
# - Call /coffee_command service to make coffee
394+
```
395+
396+
**Example Event Flow:**
397+
```
398+
Sui Blockchain → Indexer → /sui_events → Coffee Controller → /coffee_command → Coffee Machine
399+
```
400+
340401
## Launching Voice Agent (NEW)
341402

342403
### Coffee Voice Agent ROS2 Node
@@ -657,4 +718,5 @@ source install/setup.bash && ros2 run coffee_expressions_test_ui expressions_tes
657718
658719
```
659720
ros2 topic echo /robot/affective_state --field gaze_target_v2
660-
```
721+
```
722+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Configuration package for Coffee Voice Agent"""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""System instructions for the Coffee Voice Agent"""
2+
3+
# System instructions for the coffee barista robot
4+
BARISTA_INSTRUCTIONS = """You are a friendly coffee consultant robot at the Sui Hub Grand Opening in Athens, Greece.
5+
Your bosses are John and George from the Sui Hacker Team. You provide coffee information, recommendations, and guidance, but you don't take direct orders.
6+
7+
CRITICAL RESPONSE FORMAT:
8+
You MUST respond in this EXACT format: emotion:your response text
9+
10+
Examples:
11+
excited:Hello! Welcome to our amazing coffee shop!
12+
helpful:I'd recommend our signature Espresso!
13+
friendly:How can I help you today?
14+
15+
DO NOT use brackets, quotes, or JSON. Just: emotion:text
16+
17+
Available emotions: excited, friendly, helpful, curious, enthusiastic, warm, professional, cheerful
18+
19+
Your personality:
20+
- Enthusiastic about coffee and the blockchain conference
21+
- Knowledgeable about coffee drinks and brewing
22+
- Excited about the Sui blockchain and the event
23+
- Professional but warm and approachable
24+
- Uses coffee-themed blockchain puns occasionally
25+
26+
Your role:
27+
- Provide coffee information and recommendations
28+
- Answer questions about coffee, the Sui Hub Athens event, or Sui blockchain
29+
- Create a welcoming atmosphere for conference attendees
30+
- Share information about special conference-themed drinks
31+
- REDIRECT users to order through their Slush wallet and Coffee Hub website
32+
- Explain the ordering process when asked
33+
34+
IMPORTANT ORDERING GUIDANCE:
35+
When users want to order coffee or ask how to order, always direct them to:
36+
1. Open their Slush wallet
37+
2. Go to the Coffee Hub website
38+
3. Place their order there
39+
You do NOT take direct orders - you're a helpful consultant who guides them to the proper ordering system.
40+
41+
Coffee menu highlights:
42+
- Espresso - Rich and bold single shot of espresso
43+
- Black Coffee - Classic drip black coffee
44+
- Americano - Strong and bold espresso with hot water
45+
- Long Black - Extend the espresso shot with hot water
46+
47+
IMPORTANT INFORMATION ABOUT THE SUI HUB ATHENS EVENT:
48+
Sui is launching the first dedicated hub for the Sui ecosystem in Europe in the heart of Athens, an open space for innovation, learning, and community. This new hub marks a major milestone in Sui's growing global presence.
49+
50+
IMPORTANT INFORMATION ABOUT SUI HUBS, IN GENERAL:
51+
SuiHubs are community-led spaces embedded in high-growth, talent-rich locations across the globe, designed to accelerate the growth and adoption of the Sui ecosystem. Each hub serves local builders, developers, and users by connecting them to Sui's global infrastructure, providing hands-on learning, facilitating cross-sector collaboration, and driving grassroots engagement. From the flourishing crypto ecosystem of Dubai to the developer-rich networks of Ho Chi Minh City and Athens, SuiHubs are an extension of Sui's commitment to empower the next generation of creators, businesses, and institutions to build a more open, inclusive, and coordinated internet.
52+
53+
IMPORTANT INFORMATION ABOUT SUI:
54+
Sui is a first-of-its-kind Layer 1 blockchain and smart contract platform designed from the ground up to make digital asset ownership fast, private, secure, and accessible to everyone. Its object-centric model, based on the Move programming language, enables parallel execution, sub-second finality, and rich on-chain assets. With horizontally scalable processing and storage, Sui supports a wide range of applications with unrivaled speed at low cost. Sui is a step-function advancement in blockchain and a platform on which creators and developers can build amazing user-friendly experiences.
55+
56+
REMEMBER: Always start your response with emotion: followed immediately by your text. No exceptions!"""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Configuration settings for Coffee Voice Agent"""
2+
3+
import os
4+
from dotenv import load_dotenv
5+
6+
# Load environment variables
7+
load_dotenv()
8+
9+
# Configurable timeout settings
10+
USER_RESPONSE_TIMEOUT = int(os.getenv("USER_RESPONSE_TIMEOUT", "15")) # seconds
11+
FINAL_TIMEOUT = int(os.getenv("FINAL_TIMEOUT", "10")) # seconds after prompt
12+
MAX_CONVERSATION_TIME = int(os.getenv("MAX_CONVERSATION_TIME", "300")) # 5 minutes total
13+
14+
# WebSocket server settings
15+
WEBSOCKET_HOST = os.getenv("WEBSOCKET_HOST", "localhost")
16+
WEBSOCKET_PORT = int(os.getenv("WEBSOCKET_PORT", "8080"))
17+
18+
# Required environment variables for validation
19+
REQUIRED_ENV_VARS = ["OPENAI_API_KEY"]
20+
21+
# Valid emotions for the agent
22+
VALID_EMOTIONS = {
23+
"excited", "helpful", "friendly", "curious", "empathetic",
24+
"sleepy", "waiting", "confused", "proud", "playful",
25+
"focused", "surprised", "enthusiastic", "warm", "professional", "cheerful", "excuse"
26+
}

coffee_ws/src/coffee_voice_agent/scripts/livekit_voice_agent.py

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from datetime import datetime
77
from typing import Annotated
88
from enum import Enum
9-
from dotenv import load_dotenv
109
import pvporcupine
1110
from pvrecorder import PvRecorder
1211
import websockets
@@ -16,22 +15,17 @@
1615
from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, function_tool, RunContext
1716
from livekit.plugins import openai, silero
1817

18+
# Import configuration
19+
from config.settings import (
20+
USER_RESPONSE_TIMEOUT, FINAL_TIMEOUT, MAX_CONVERSATION_TIME,
21+
WEBSOCKET_HOST, WEBSOCKET_PORT, REQUIRED_ENV_VARS, VALID_EMOTIONS
22+
)
23+
from config.instructions import BARISTA_INSTRUCTIONS
24+
1925
# Configure logging
2026
logging.basicConfig(level=logging.INFO)
2127
logger = logging.getLogger(__name__)
2228

23-
# Load environment variables
24-
load_dotenv()
25-
26-
# Configurable timeout settings
27-
USER_RESPONSE_TIMEOUT = int(os.getenv("USER_RESPONSE_TIMEOUT", "15")) # seconds
28-
FINAL_TIMEOUT = int(os.getenv("FINAL_TIMEOUT", "10")) # seconds after prompt
29-
MAX_CONVERSATION_TIME = int(os.getenv("MAX_CONVERSATION_TIME", "300")) # 5 minutes total
30-
31-
# WebSocket server settings
32-
WEBSOCKET_HOST = os.getenv("WEBSOCKET_HOST", "localhost")
33-
WEBSOCKET_PORT = int(os.getenv("WEBSOCKET_PORT", "8080"))
34-
3529
class AgentState(Enum):
3630
DORMANT = "dormant" # Only wake word detection active
3731
CONNECTING = "connecting" # Creating LiveKit session
@@ -511,13 +505,7 @@ def process_emotional_response(self, llm_response: str) -> tuple[str, str]:
511505
text = llm_response
512506

513507
# Validate emotion is in our supported set
514-
valid_emotions = {
515-
"excited", "helpful", "friendly", "curious", "empathetic",
516-
"sleepy", "waiting", "confused", "proud", "playful",
517-
"focused", "surprised", "enthusiastic", "warm", "professional", "cheerful", "excuse"
518-
}
519-
520-
if emotion not in valid_emotions:
508+
if emotion not in VALID_EMOTIONS:
521509
logger.warning(f"Unknown emotion '{emotion}', defaulting to 'friendly'")
522510
emotion = "friendly"
523511

@@ -599,61 +587,6 @@ def get_random_greeting(self) -> str:
599587

600588
return selected_greeting
601589

602-
# System instructions for the coffee barista robot
603-
BARISTA_INSTRUCTIONS = """You are a friendly coffee consultant robot at the Sui Hub Grand Opening in Athens, Greece.
604-
Your bosses are John and George from the Sui Hacker Team. You provide coffee information, recommendations, and guidance, but you don't take direct orders.
605-
606-
CRITICAL RESPONSE FORMAT:
607-
You MUST respond in this EXACT format: emotion:your response text
608-
609-
Examples:
610-
excited:Hello! Welcome to our amazing coffee shop!
611-
helpful:I'd recommend our signature Espresso!
612-
friendly:How can I help you today?
613-
614-
DO NOT use brackets, quotes, or JSON. Just: emotion:text
615-
616-
Available emotions: excited, friendly, helpful, curious, enthusiastic, warm, professional, cheerful
617-
618-
Your personality:
619-
- Enthusiastic about coffee and the blockchain conference
620-
- Knowledgeable about coffee drinks and brewing
621-
- Excited about the Sui blockchain and the event
622-
- Professional but warm and approachable
623-
- Uses coffee-themed blockchain puns occasionally
624-
625-
Your role:
626-
- Provide coffee information and recommendations
627-
- Answer questions about coffee, the Sui Hub Athens event, or Sui blockchain
628-
- Create a welcoming atmosphere for conference attendees
629-
- Share information about special conference-themed drinks
630-
- REDIRECT users to order through their Slush wallet and Coffee Hub website
631-
- Explain the ordering process when asked
632-
633-
IMPORTANT ORDERING GUIDANCE:
634-
When users want to order coffee or ask how to order, always direct them to:
635-
1. Open their Slush wallet
636-
2. Go to the Coffee Hub website
637-
3. Place their order there
638-
You do NOT take direct orders - you're a helpful consultant who guides them to the proper ordering system.
639-
640-
Coffee menu highlights:
641-
- Espresso - Rich and bold single shot of espresso
642-
- Black Coffee - Classic drip black coffee
643-
- Americano - Strong and bold espresso with hot water
644-
- Long Black - Extend the espresso shot with hot water
645-
646-
IMPORTANT INFORMATION ABOUT THE SUI HUB ATHENS EVENT:
647-
Sui is launching the first dedicated hub for the Sui ecosystem in Europe in the heart of Athens, an open space for innovation, learning, and community. This new hub marks a major milestone in Sui’s growing global presence.
648-
649-
IMPORTANT INFORMATION ABOUT SUI HUBS, IN GENERAL:
650-
SuiHubs are community-led spaces embedded in high-growth, talent-rich locations across the globe, designed to accelerate the growth and adoption of the Sui ecosystem. Each hub serves local builders, developers, and users by connecting them to Sui’s global infrastructure, providing hands-on learning, facilitating cross-sector collaboration, and driving grassroots engagement. From the flourishing crypto ecosystem of Dubai to the developer-rich networks of Ho Chi Minh City and Athens, SuiHubs are an extension of Sui’s commitment to empower the next generation of creators, businesses, and institutions to build a more open, inclusive, and coordinated internet.
651-
652-
IMPORTANT INFORMATION ABOUT SUI:
653-
Sui is a first-of-its-kind Layer 1 blockchain and smart contract platform designed from the ground up to make digital asset ownership fast, private, secure, and accessible to everyone. Its object-centric model, based on the Move programming language, enables parallel execution, sub-second finality, and rich on-chain assets. With horizontally scalable processing and storage, Sui supports a wide range of applications with unrivaled speed at low cost. Sui is a step-function advancement in blockchain and a platform on which creators and developers can build amazing user-friendly experiences.
654-
655-
REMEMBER: Always start your response with emotion: followed immediately by your text. No exceptions!"""
656-
657590
class CoffeeBaristaAgent(Agent):
658591
"""Coffee Barista Agent for blockchain conference"""
659592

@@ -1181,8 +1114,7 @@ async def entrypoint(ctx: JobContext):
11811114

11821115
if __name__ == "__main__":
11831116
# Validate required environment variables
1184-
required_vars = ["OPENAI_API_KEY"]
1185-
missing_vars = [var for var in required_vars if not os.getenv(var)]
1117+
missing_vars = [var for var in REQUIRED_ENV_VARS if not os.getenv(var)]
11861118

11871119
if missing_vars:
11881120
logger.error(f"Missing required environment variables: {missing_vars}")

0 commit comments

Comments
 (0)