This service project is only for developer quick experience and demonstration purposes. Do not use in production environment. Production environment services need to be developed by developers.
This server provides APIs for managing IoT devices and conversational AI agents, built with Python and supporting real-time communication via Agora RTC.
- 🎙️ Real-time voice communication
- 🤖 Conversational AI integration
- 🔐 Secure token generation
- 📦 Easy deployment options
- 📊 Comprehensive logging
- Python 3.7+
- Required packages:
requests flask pyjwt
- Clone this repository
- Install dependencies:
pip install -r requirements.txtCreate a config.json file with the following structure and explanations:
{
// Agora related configuration
"app_id": "YOUR_AGORA_APP_ID", // Agora App ID
"app_certificate": "YOUR_AGORA_APP_CERTIFICATE", // Agora App Certificate
// Customer authentication information
"customer_key": "YOUR_CUSTOMER_KEY", // Customer Key
"customer_secret": "YOUR_CUSTOMER_SECRET", // Customer Secret
// Automatic Speech Recognition (ASR) configuration
"asr": {
"language": "zh-CN" // Recognition language, default Chinese (supports Chinese-English mixed)
},
// System parameters configuration
"parameters": {
"output_audio_codec": "G722" // RTC streaming audio codec format, supported formats: "PCMU" "PCMA" "G722" "OPUS" "OPUSFB"
"transcript": { // Subtitle feature parameter configuration
"enable": false // Disable subtitle feature
}
},
// Text-to-Speech (TTS) configuration
"tts": {
"vendor": "YOUR_TTS_VENDOR", // TTS service provider
"params": {
}
},
// Session timeout configuration
"idle_timeout": 30, // Session timeout (seconds)
// Large Language Model (LLM) configuration
"llm": {
"url": "YOUR_LLM_API_URL", // LLM service URL
"params": {
"model": "YOUR_LLM_MODEL" // Model used
},
"api_key": "YOUR_LLM_API_KEY", // LLM service API key
"system_messages": [ // System preset messages
{
"role": "system",
"content": "You are a helpful chatbot."
}
],
"max_history": 10, // Maximum history records
"greeting_message": "Hello, I'm your AI assistant. How can I help you?", // Greeting message
"failure_message": "Sorry, I am unable to answer your question..." // Failure message
}
}For more detailed parameter configuration, see: https://doc.shengwang.cn/doc/convoai/restful/convoai/operations/start-agent
Start the server with:
python3 main.pyThe server will run on port 5001 by default.
https://your-domain.com/api/v1
All requests require an Authorization header:
Authorization: Bearer <access_token>Register a new device and generate RTC token
Request body:
{
"channel_name": "DEVICE_ID",
"uid": DEVICE_USER_ID
}Start a conversational AI agent
Request body:
{
"channel_name": "DEVICE_ID",
"uid": DEVICE_USER_ID,
"agent_uid": AGENT_USER_ID
}Stop a conversational AI agent
Request body:
{
"agent_id": "AGENT_ID"
}Logs are written to stdout with the following format:
[timestamp] [level] - [message]
Log levels:
- DEBUG: Detailed debug information
- INFO: General operational messages
- WARNING: Indicates potential issues
- ERROR: Errors that need attention
- CRITICAL: Critical system failures
- Always keep your Agora credentials secure
- Use HTTPS in production environments
- Regularly rotate your access tokens
- Implement rate limiting for API endpoints
This project is licensed under the MIT License - see the LICENSE file for details.
import requests
# Generate RTC token
response = requests.post(
"https://your-domain.com/device",
json={"channel_name": "12345", "uid": 1}
)
print(response.json())