Add fastgpt as seperate assistant mode
This commit is contained in:
@@ -133,6 +133,7 @@ class Assistant(Base):
|
||||
config_mode: Mapped[str] = mapped_column(String(32), default="platform")
|
||||
api_url: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
api_key: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
app_id: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
# 模型关联
|
||||
llm_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
asr_model_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
|
||||
@@ -129,6 +129,9 @@ def _ensure_assistant_schema(db: Session) -> None:
|
||||
if "asr_interim_enabled" not in columns:
|
||||
db.execute(text("ALTER TABLE assistants ADD COLUMN asr_interim_enabled BOOLEAN DEFAULT 0"))
|
||||
altered = True
|
||||
if "app_id" not in columns:
|
||||
db.execute(text("ALTER TABLE assistants ADD COLUMN app_id VARCHAR(255)"))
|
||||
altered = True
|
||||
|
||||
if altered:
|
||||
db.commit()
|
||||
@@ -297,7 +300,7 @@ def _resolve_runtime_metadata(db: Session, assistant: Assistant) -> tuple[Dict[s
|
||||
|
||||
config_mode = str(assistant.config_mode or "platform").strip().lower()
|
||||
|
||||
if config_mode in {"dify", "fastgpt"}:
|
||||
if config_mode == "dify":
|
||||
metadata["services"]["llm"] = {
|
||||
"provider": "openai",
|
||||
"model": "",
|
||||
@@ -308,6 +311,19 @@ def _resolve_runtime_metadata(db: Session, assistant: Assistant) -> tuple[Dict[s
|
||||
warnings.append(f"External LLM API URL is empty for mode: {assistant.config_mode}")
|
||||
if not (assistant.api_key or "").strip():
|
||||
warnings.append(f"External LLM API key is empty for mode: {assistant.config_mode}")
|
||||
elif config_mode == "fastgpt":
|
||||
metadata["services"]["llm"] = {
|
||||
"provider": "fastgpt",
|
||||
"model": "fastgpt",
|
||||
"apiKey": assistant.api_key,
|
||||
"baseUrl": assistant.api_url,
|
||||
}
|
||||
if (assistant.app_id or "").strip():
|
||||
metadata["services"]["llm"]["appId"] = assistant.app_id
|
||||
if not (assistant.api_url or "").strip():
|
||||
warnings.append(f"FastGPT API URL is empty for mode: {assistant.config_mode}")
|
||||
if not (assistant.api_key or "").strip():
|
||||
warnings.append(f"FastGPT API key is empty for mode: {assistant.config_mode}")
|
||||
elif assistant.llm_model_id:
|
||||
llm = db.query(LLMModel).filter(LLMModel.id == assistant.llm_model_id).first()
|
||||
if llm:
|
||||
@@ -450,6 +466,7 @@ def assistant_to_dict(assistant: Assistant) -> dict:
|
||||
"configMode": assistant.config_mode,
|
||||
"apiUrl": assistant.api_url,
|
||||
"apiKey": assistant.api_key,
|
||||
"appId": assistant.app_id,
|
||||
"llmModelId": assistant.llm_model_id,
|
||||
"asrModelId": assistant.asr_model_id,
|
||||
"embeddingModelId": assistant.embedding_model_id,
|
||||
@@ -472,6 +489,7 @@ def _apply_assistant_update(assistant: Assistant, update_data: dict) -> None:
|
||||
"generatedOpenerEnabled": "generated_opener_enabled",
|
||||
"apiUrl": "api_url",
|
||||
"apiKey": "api_key",
|
||||
"appId": "app_id",
|
||||
"llmModelId": "llm_model_id",
|
||||
"asrModelId": "asr_model_id",
|
||||
"embeddingModelId": "embedding_model_id",
|
||||
@@ -666,6 +684,7 @@ def create_assistant(data: AssistantCreate, db: Session = Depends(get_db)):
|
||||
config_mode=data.configMode,
|
||||
api_url=data.apiUrl,
|
||||
api_key=data.apiKey,
|
||||
app_id=data.appId,
|
||||
llm_model_id=data.llmModelId,
|
||||
asr_model_id=data.asrModelId,
|
||||
embedding_model_id=data.embeddingModelId,
|
||||
|
||||
@@ -298,6 +298,7 @@ class AssistantBase(BaseModel):
|
||||
configMode: str = "platform"
|
||||
apiUrl: Optional[str] = None
|
||||
apiKey: Optional[str] = None
|
||||
appId: Optional[str] = None
|
||||
# 模型关联
|
||||
llmModelId: Optional[str] = None
|
||||
asrModelId: Optional[str] = None
|
||||
@@ -330,6 +331,7 @@ class AssistantUpdate(BaseModel):
|
||||
configMode: Optional[str] = None
|
||||
apiUrl: Optional[str] = None
|
||||
apiKey: Optional[str] = None
|
||||
appId: Optional[str] = None
|
||||
llmModelId: Optional[str] = None
|
||||
asrModelId: Optional[str] = None
|
||||
embeddingModelId: Optional[str] = None
|
||||
|
||||
@@ -29,6 +29,7 @@ class TestAssistantAPI:
|
||||
assert data["generatedOpenerEnabled"] is False
|
||||
assert data["asrInterimEnabled"] is False
|
||||
assert data["botCannotBeInterrupted"] is False
|
||||
assert data["appId"] is None
|
||||
assert "id" in data
|
||||
assert data["callCount"] == 0
|
||||
|
||||
@@ -419,3 +420,21 @@ class TestAssistantAPI:
|
||||
assert metadata["greeting"] == ""
|
||||
assert metadata["bargeIn"]["enabled"] is False
|
||||
assert metadata["bargeIn"]["minDurationMs"] == 900
|
||||
|
||||
def test_fastgpt_app_id_persists_and_flows_to_runtime(self, client, sample_assistant_data):
|
||||
sample_assistant_data.update({
|
||||
"configMode": "fastgpt",
|
||||
"apiUrl": "https://cloud.fastgpt.cn/api",
|
||||
"apiKey": "fastgpt-key",
|
||||
"appId": "app-fastgpt-123",
|
||||
})
|
||||
assistant_resp = client.post("/api/assistants", json=sample_assistant_data)
|
||||
assert assistant_resp.status_code == 200
|
||||
assistant_id = assistant_resp.json()["id"]
|
||||
assert assistant_resp.json()["appId"] == "app-fastgpt-123"
|
||||
|
||||
runtime_resp = client.get(f"/api/assistants/{assistant_id}/runtime-config")
|
||||
assert runtime_resp.status_code == 200
|
||||
metadata = runtime_resp.json()["sessionStartMetadata"]
|
||||
assert metadata["services"]["llm"]["provider"] == "fastgpt"
|
||||
assert metadata["services"]["llm"]["appId"] == "app-fastgpt-123"
|
||||
|
||||
Reference in New Issue
Block a user