Refactor backend configuration management and update environment settings
- Replace the `config.py` module with a new `settings.py` to streamline environment variable management, focusing on database, CORS, and TURN settings. - Update references throughout the backend codebase to use the new `settings` module instead of the deprecated `config`. - Modify the `.env.example` file to reflect the new configuration approach, indicating that model provider credentials should be maintained separately. - Enhance the `AssistantConfig` model to clarify the source of runtime connection information, ensuring it is injected from model resources rather than relying on defaults from the environment. - Introduce new user scripts for audio and video management in the Tampermonkey environment, enhancing WebRTC capabilities.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
"""assistant_id → 运行时配置(把真 key 在服务端组装好)。
|
||||
|
||||
浏览器只传 assistant_id;真 key 在这里从 model_resources 取出注入。
|
||||
助手按 capability binding 引用资源;取不到则回退该能力默认资源,再回退 .env。
|
||||
助手按 capability binding 引用资源;取不到则回退该能力默认资源。
|
||||
"""
|
||||
|
||||
import config
|
||||
from db.models import Assistant, AssistantModelBinding, ModelResource
|
||||
from models import AssistantConfig
|
||||
from sqlalchemy import select
|
||||
@@ -63,14 +62,14 @@ async def _agent_resource_for(
|
||||
).scalar_one_or_none()
|
||||
|
||||
|
||||
def _value(resource: ModelResource | None, key: str, default):
|
||||
def _value(resource: ModelResource | None, key: str, default=""):
|
||||
if not resource:
|
||||
return default
|
||||
value = (resource.values or {}).get(key, default)
|
||||
return default if value is None else value
|
||||
|
||||
|
||||
def _secret(resource: ModelResource | None, key: str, default: str) -> str:
|
||||
def _secret(resource: ModelResource | None, key: str, default: str = "") -> str:
|
||||
if not resource:
|
||||
return default
|
||||
return str((resource.secrets or {}).get(key) or default)
|
||||
@@ -148,19 +147,15 @@ async def resolve_runtime_config(
|
||||
agent_interface_type=(agent_resource.interface_type if agent_resource else ""),
|
||||
agent_values=(agent_resource.values or {}) if agent_resource else {},
|
||||
agent_secrets=(agent_resource.secrets or {}) if agent_resource else {},
|
||||
# 运行时连接信息(真 key + url):模型资源优先,否则 .env 兜底
|
||||
llm_api_key=_secret(llm_resource, "apiKey", config.LLM_API_KEY),
|
||||
llm_base_url=str(_value(llm_resource, "apiUrl", config.LLM_BASE_URL)),
|
||||
vision_llm_api_key=_secret(
|
||||
vision_resource, "apiKey", config.LLM_API_KEY
|
||||
),
|
||||
vision_llm_base_url=str(
|
||||
_value(vision_resource, "apiUrl", config.LLM_BASE_URL)
|
||||
),
|
||||
stt_api_key=_secret(stt_resource, "apiKey", config.STT_API_KEY),
|
||||
stt_base_url=str(_value(stt_resource, "apiUrl", config.STT_BASE_URL)),
|
||||
tts_api_key=_secret(tts_resource, "apiKey", config.TTS_API_KEY),
|
||||
tts_base_url=str(_value(tts_resource, "apiUrl", config.TTS_BASE_URL)),
|
||||
# 运行时连接信息(真 key + url):来自模型资源,不再从 .env 兜底。
|
||||
llm_api_key=_secret(llm_resource, "apiKey"),
|
||||
llm_base_url=str(_value(llm_resource, "apiUrl")),
|
||||
vision_llm_api_key=_secret(vision_resource, "apiKey"),
|
||||
vision_llm_base_url=str(_value(vision_resource, "apiUrl")),
|
||||
stt_api_key=_secret(stt_resource, "apiKey"),
|
||||
stt_base_url=str(_value(stt_resource, "apiUrl")),
|
||||
tts_api_key=_secret(tts_resource, "apiKey"),
|
||||
tts_base_url=str(_value(tts_resource, "apiUrl")),
|
||||
realtime_api_key=_secret(realtime_resource, "apiKey", ""),
|
||||
realtime_base_url=str(_value(realtime_resource, "apiUrl", "")),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user