Enhance AssistantConfig and pipeline for FastGPT integration
- Add new fields in AssistantConfig for FastGPT connection details, including `fastgpt_api_url`, `fastgpt_api_key`, and `fastgpt_app_id`. - Update the pipeline to utilize the new FastGPT configuration, ensuring proper integration with external services. - Introduce type handling for different assistant types, including support for realtime modes and external brain management. - Refactor frontend components to include hints for FastGPT configuration inputs, improving user guidance during setup.
This commit is contained in:
@@ -11,7 +11,12 @@ from uuid import uuid4
|
||||
import config
|
||||
from loguru import logger
|
||||
from models import AssistantConfig
|
||||
from services.pipecat.service_factory import create_realtime_service, create_services
|
||||
from services.brains import build_brain
|
||||
from services.pipecat.service_factory import (
|
||||
create_realtime_service,
|
||||
create_stt,
|
||||
create_tts,
|
||||
)
|
||||
from services.workflow_engine import WorkflowEngine
|
||||
|
||||
from pipecat.adapters.schemas.function_schema import FunctionSchema
|
||||
@@ -207,13 +212,23 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
只要有 .input() / .output() / event_handler 即可。
|
||||
cfg: 助手配置(随请求内联传入)。
|
||||
"""
|
||||
logger.info(f"启动管线: assistant={cfg.name} mode={cfg.runtimeMode}")
|
||||
logger.info(f"启动管线: assistant={cfg.name} type={cfg.type} mode={cfg.runtimeMode}")
|
||||
|
||||
# 大脑:按类型决定 LLM 槽/开场白/上下文归属。每通电话一个实例(可持会话状态)。
|
||||
brain = build_brain(cfg)
|
||||
if (
|
||||
cfg.runtimeMode == "realtime"
|
||||
and "realtime" not in brain.spec.supported_runtime_modes
|
||||
):
|
||||
logger.warning(f"类型 {cfg.type} 不支持 realtime,回退 cascade")
|
||||
cfg.runtimeMode = "pipeline"
|
||||
|
||||
if cfg.runtimeMode == "realtime":
|
||||
await run_realtime_pipeline(transport, cfg)
|
||||
return
|
||||
|
||||
stt, llm, tts = create_services(cfg)
|
||||
stt = create_stt(cfg)
|
||||
tts = create_tts(cfg)
|
||||
|
||||
# ---- workflow 图引擎(可选)----
|
||||
# 有节点图时按图驱动:开场白/系统提示来自起始节点,每轮回复后按条件路由。
|
||||
@@ -240,11 +255,17 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
logger.info(
|
||||
f"工作流模式启用: 起始节点={engine.name(wf_state['current'])}"
|
||||
)
|
||||
else:
|
||||
elif brain.spec.owns_context:
|
||||
greeting = cfg.greeting
|
||||
system_content = cfg.prompt
|
||||
else:
|
||||
# 外部托管(fastgpt 等):开场白来自对方后台,系统提示/上下文不归我们维护
|
||||
greeting = await brain.greeting(cfg)
|
||||
system_content = ""
|
||||
|
||||
context = LLMContext(messages=[{"role": "system", "content": system_content}])
|
||||
# LLM 槽由大脑提供:内部类型=OpenAI 兼容服务;fastgpt=包 SDK 的伪 LLM。
|
||||
llm = brain.build_llm(cfg, context)
|
||||
user_aggregator = LLMUserAggregator(
|
||||
context,
|
||||
params=LLMUserAggregatorParams(
|
||||
@@ -539,7 +560,9 @@ async def run_pipeline(transport, cfg: AssistantConfig) -> None:
|
||||
@transport.event_handler("on_client_connected")
|
||||
async def on_client_connected(_transport, _client):
|
||||
if greeting:
|
||||
context.add_message({"role": "assistant", "content": greeting})
|
||||
# 外部托管类型的上下文由对方服务端维护,开场白不写入本地 context
|
||||
if brain.spec.owns_context:
|
||||
context.add_message({"role": "assistant", "content": greeting})
|
||||
await worker.queue_frame(TTSSpeakFrame(greeting, append_to_context=False))
|
||||
# 工作流:点亮当前(开始)节点。开始节点即首个会话节点。
|
||||
if workflow_active:
|
||||
|
||||
@@ -132,16 +132,6 @@ def create_tts(cfg: AssistantConfig):
|
||||
)
|
||||
|
||||
|
||||
def create_services(cfg: AssistantConfig):
|
||||
logger.info(
|
||||
f"创建服务: stt={cfg.stt_interface_type}/{cfg.asr or config.STT_MODEL} "
|
||||
f"llm={cfg.model or config.LLM_MODEL} "
|
||||
f"tts={cfg.tts_interface_type}/{cfg.tts_model or config.TTS_MODEL} "
|
||||
f"voice={cfg.voice or config.TTS_VOICE}"
|
||||
)
|
||||
return create_stt(cfg), create_llm(cfg), create_tts(cfg)
|
||||
|
||||
|
||||
def create_realtime_service(cfg: AssistantConfig):
|
||||
"""Create a speech-to-speech service that owns STT, LLM, and TTS."""
|
||||
if cfg.realtime_interface_type == "stepfun-realtime":
|
||||
|
||||
Reference in New Issue
Block a user