mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
feat: remote aws ec2 container deployment
This commit is contained in:
parent
04d9e3e1bf
commit
d3f152de2e
5 changed files with 89 additions and 64 deletions
31
main/.env.example
Normal file
31
main/.env.example
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# Live Agent Environment Configuration
|
||||||
|
# Copy this file to .env and update the values
|
||||||
|
|
||||||
|
# ==================== S3/MinIO Configuration ====================
|
||||||
|
# For local development with MinIO(compatible with S3)
|
||||||
|
AWS_ACCESS_KEY_ID=minioadmin
|
||||||
|
AWS_SECRET_ACCESS_KEY=minioadmin
|
||||||
|
AWS_REGION=us-east-1
|
||||||
|
S3_BUCKET_NAME=live-agent-files
|
||||||
|
S3_ENDPOINT_URL=
|
||||||
|
S3_PUBLIC_BASE_URL=
|
||||||
|
|
||||||
|
# ==================== Security ====================
|
||||||
|
SECRET_KEY=dev-secret-key-change-in-production
|
||||||
|
|
||||||
|
# ==================== Token Configuration ====================
|
||||||
|
TOKEN_EXPIRE_DAYS=7
|
||||||
|
|
||||||
|
# ==================== Live Agent API Server Configuration ====================
|
||||||
|
# These are optional, defaults are set in settings.py
|
||||||
|
# LIVE_AGENT_API_HOST=0.0.0.0
|
||||||
|
# LIVE_AGENT_API_PORT=8080
|
||||||
|
# LIVE_AGENT_API_DEBUG=False
|
||||||
|
|
||||||
|
# ==================== Database Configuration ====================
|
||||||
|
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/live_agent
|
||||||
|
|
||||||
|
FISH_API_KEY=your-fish-api-key
|
||||||
|
OPENAI_API_KEY=your-openai-key
|
||||||
|
GROQ_API_KEY=your-groq-api-key
|
||||||
|
OPENAI_MODEL=
|
||||||
|
|
@ -8,6 +8,8 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
image: xiaozhi-esp32-server:local
|
image: xiaozhi-esp32-server:local
|
||||||
container_name: xiaozhi-esp32-server
|
container_name: xiaozhi-esp32-server
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
depends_on:
|
depends_on:
|
||||||
xiaozhi-esp32-server-db:
|
xiaozhi-esp32-server-db:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
@ -211,7 +213,7 @@ services:
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
container_name: live-agent-api
|
container_name: live-agent-api
|
||||||
env_file:
|
env_file:
|
||||||
- ./live-agent-api/.env
|
- .env
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql+asyncpg://postgres:postgres@live-agent-postgres:5432/live_agent
|
DATABASE_URL: postgresql+asyncpg://postgres:postgres@live-agent-postgres:5432/live_agent
|
||||||
S3_ENDPOINT_URL: http://live-agent-minio:9000
|
S3_ENDPOINT_URL: http://live-agent-minio:9000
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# Live Agent API Environment Configuration
|
|
||||||
# Copy this file to .env and update the values
|
|
||||||
|
|
||||||
# ==================== S3/MinIO Configuration ====================
|
|
||||||
# For local development with MinIO
|
|
||||||
AWS_ACCESS_KEY_ID=minioadmin
|
|
||||||
AWS_SECRET_ACCESS_KEY=minioadmin
|
|
||||||
AWS_REGION=us-east-1
|
|
||||||
S3_BUCKET_NAME=live-agent-files
|
|
||||||
|
|
||||||
# For production with AWS S3, use your actual credentials:
|
|
||||||
# AWS_ACCESS_KEY_ID=your-aws-access-key
|
|
||||||
# AWS_SECRET_ACCESS_KEY=your-aws-secret-key
|
|
||||||
# AWS_REGION=ap-northeast-1
|
|
||||||
# S3_BUCKET_NAME=your-production-bucket
|
|
||||||
|
|
||||||
# ==================== Security ====================
|
|
||||||
SECRET_KEY=dev-secret-key-change-in-production
|
|
||||||
|
|
||||||
# ==================== Token Configuration ====================
|
|
||||||
TOKEN_EXPIRE_DAYS=7
|
|
||||||
|
|
||||||
# ==================== Server Configuration ====================
|
|
||||||
# These are optional, defaults are set in settings.py
|
|
||||||
# HOST=0.0.0.0
|
|
||||||
# PORT=8080
|
|
||||||
# DEBUG=False
|
|
||||||
|
|
||||||
# ==================== Database Configuration ====================
|
|
||||||
# This is overridden in docker-compose.yml for container environment
|
|
||||||
# For local development without Docker, use:
|
|
||||||
# DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/live_agent
|
|
||||||
|
|
||||||
FISH_API_KEY=your-fish-api-key
|
|
||||||
|
|
||||||
|
|
@ -1,9 +1,51 @@
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import yaml
|
import yaml
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from config.manage_api_client import init_service, get_server_config, get_agent_models
|
from config.manage_api_client import init_service, get_server_config, get_agent_models
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
|
||||||
|
# Environment variable pattern: ${VAR_NAME} or ${VAR_NAME:-default_value}
|
||||||
|
ENV_VAR_PATTERN = re.compile(r'\$\{([^}:]+)(?::-([^}]*))?\}')
|
||||||
|
|
||||||
|
|
||||||
|
def expand_env_vars(config):
|
||||||
|
"""
|
||||||
|
Recursively expand environment variable placeholders in config.
|
||||||
|
|
||||||
|
Supports two formats:
|
||||||
|
- ${VAR_NAME} - Required, raises error if not set
|
||||||
|
- ${VAR_NAME:-default} - Optional, uses default if not set
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
api_key: ${OPENAI_API_KEY}
|
||||||
|
base_url: ${OPENAI_BASE_URL:-https://api.openai.com/v1}
|
||||||
|
"""
|
||||||
|
if isinstance(config, dict):
|
||||||
|
return {k: expand_env_vars(v) for k, v in config.items()}
|
||||||
|
elif isinstance(config, list):
|
||||||
|
return [expand_env_vars(item) for item in config]
|
||||||
|
elif isinstance(config, str):
|
||||||
|
def replace_env_var(match):
|
||||||
|
var_name = match.group(1)
|
||||||
|
default_value = match.group(2) # None if no default specified
|
||||||
|
|
||||||
|
env_value = os.environ.get(var_name)
|
||||||
|
|
||||||
|
if env_value is not None:
|
||||||
|
return env_value
|
||||||
|
elif default_value is not None:
|
||||||
|
return default_value
|
||||||
|
else:
|
||||||
|
# Keep original placeholder if env var not set and no default
|
||||||
|
# This allows optional configs to remain as placeholders
|
||||||
|
return match.group(0)
|
||||||
|
|
||||||
|
return ENV_VAR_PATTERN.sub(replace_env_var, config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_project_dir():
|
def get_project_dir():
|
||||||
"""获取项目根目录"""
|
"""获取项目根目录"""
|
||||||
return os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/"
|
return os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/"
|
||||||
|
|
@ -24,34 +66,19 @@ def load_config():
|
||||||
if cached_config is not None:
|
if cached_config is not None:
|
||||||
return cached_config
|
return cached_config
|
||||||
|
|
||||||
# default_config_path = get_project_dir() + "config.yaml"
|
|
||||||
custom_config_path = get_project_dir() + "custom_config.yaml"
|
custom_config_path = get_project_dir() + "custom_config.yaml"
|
||||||
|
|
||||||
# 加载默认配置
|
# Load environment variables from .env file
|
||||||
# default_config = read_config(default_config_path)
|
|
||||||
config = read_config(custom_config_path)
|
|
||||||
config["read_config_from_live_agent_api"] = True
|
|
||||||
# load environment variables
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
# tts
|
|
||||||
select_tts_module = config["selected_module"]["TTS"]
|
# Read YAML config
|
||||||
if os.environ.get("REGION") == "LOCAL" and select_tts_module == "FishSpeech":
|
config = read_config(custom_config_path)
|
||||||
config["TTS"][select_tts_module]["api_key"] = os.environ.get("FISH_API_KEY")
|
|
||||||
# asr
|
# Expand environment variable placeholders (e.g., ${OPENAI_API_KEY})
|
||||||
select_asr_module = config["selected_module"]["ASR"]
|
config = expand_env_vars(config)
|
||||||
if os.environ.get("REGION") == "LOCAL" and select_asr_module == "GroqASR":
|
|
||||||
config["ASR"][select_asr_module]["api_key"] = os.environ.get("GROQ_API_KEY")
|
config["read_config_from_live_agent_api"] = True
|
||||||
# llm
|
|
||||||
select_llm_module = config["selected_module"]["LLM"]
|
|
||||||
if os.environ.get("REGION") == "LOCAL" and select_llm_module == "GroqLLM":
|
|
||||||
config["LLM"][select_llm_module]["api_key"] = os.environ.get("GROQ_API_KEY")
|
|
||||||
if os.environ.get("REGION") == "LOCAL" and select_llm_module == "OpenaiLLM":
|
|
||||||
config["LLM"][select_llm_module]["api_key"] = os.environ.get("OPENAI_API_KEY")
|
|
||||||
# if custom_config.get("manager-api", {}).get("url"):
|
|
||||||
# config = get_config_from_api(custom_config)
|
|
||||||
# else:
|
|
||||||
# # 合并配置
|
|
||||||
# config = merge_configs(default_config, custom_config)
|
|
||||||
# 初始化目录
|
# 初始化目录
|
||||||
ensure_directories(config)
|
ensure_directories(config)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -416,7 +416,7 @@ ASR:
|
||||||
# 2.创建api-key https://console.groq.com/keys
|
# 2.创建api-key https://console.groq.com/keys
|
||||||
# 3.模型可以选择whisper-large-v3-turbo或whisper-large-v3(distil-whisper-large-v3-en仅支持英语转录)
|
# 3.模型可以选择whisper-large-v3-turbo或whisper-large-v3(distil-whisper-large-v3-en仅支持英语转录)
|
||||||
type: openai
|
type: openai
|
||||||
api_key: your groq api key
|
api_key: ${GROQ_API_KEY}
|
||||||
base_url: https://api.groq.com/openai/v1
|
base_url: https://api.groq.com/openai/v1
|
||||||
model_name: whisper-large-v3-turbo
|
model_name: whisper-large-v3-turbo
|
||||||
output_dir: tmp/
|
output_dir: tmp/
|
||||||
|
|
@ -542,7 +542,7 @@ LLM:
|
||||||
type: openai
|
type: openai
|
||||||
model_name: gpt-4o
|
model_name: gpt-4o
|
||||||
base_url: https://api.openai.com/v1
|
base_url: https://api.openai.com/v1
|
||||||
api_key: your openai api key
|
api_key: ${OPENAI_API_KEY}
|
||||||
OllamaLLM:
|
OllamaLLM:
|
||||||
# 定义LLM API类型
|
# 定义LLM API类型
|
||||||
type: ollama
|
type: ollama
|
||||||
|
|
@ -782,7 +782,7 @@ TTS:
|
||||||
channels: 1
|
channels: 1
|
||||||
rate: 44100
|
rate: 44100
|
||||||
sample_rate: 16000
|
sample_rate: 16000
|
||||||
api_key: "your fish speech api key"
|
api_key: ${FISH_API_KEY}
|
||||||
GPT_SOVITS_V2:
|
GPT_SOVITS_V2:
|
||||||
# 定义TTS API类型
|
# 定义TTS API类型
|
||||||
#启动tts方法:
|
#启动tts方法:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue