添加 Copilot 聊天流式响应接口及测试

This commit is contained in:
2026-03-24 11:22:00 +08:00
parent 21dd393aee
commit c184610035
6 changed files with 141 additions and 24 deletions
@@ -8,9 +8,8 @@ from fastapi import APIRouter, Depends, Request, status
from fastapi.responses import StreamingResponse
from pydantic import BaseModel, Field
from app.auth.dependencies import get_current_active_user
from app.auth.keycloak_dependencies import get_current_keycloak_username
from app.core.config import settings
from app.domain.schemas.user import UserInDB
router = APIRouter()
@@ -32,7 +31,7 @@ def _sse_event(event: str, data: dict) -> str:
async def copilot_chat_stream(
payload: CopilotChatStreamRequest,
request: Request,
current_user: UserInDB = Depends(get_current_active_user),
username: str = Depends(get_current_keycloak_username),
):
timeout = httpx.Timeout(
connect=10.0,
@@ -55,7 +54,7 @@ async def copilot_chat_stream(
body = {
"message": payload.message,
"conversationId": payload.conversation_id,
"userId": current_user.username,
"userId": username,
}
try:
+17 -17
View File
@@ -312,23 +312,23 @@ async def valve_isolation_endpoint(
- affected_nodes: 受影响的节点列表
- isolatable: 是否可以有效隔离
"""
result = {
"accident_element": "P461309",
"accident_elements": ["P461309"],
"affected_nodes": [
"J316629_A",
"J317037_B",
"J317060_B",
"J408189_B",
"J499996",
"J524940",
"J535933",
"J58841",
],
"isolatable": True,
"must_close_valves": ["210521658", "V12974", "V12986", "V12993"],
"optional_valves": [],
}
# result = {
# "accident_element": "P461309",
# "accident_elements": ["P461309"],
# "affected_nodes": [
# "J316629_A",
# "J317037_B",
# "J317060_B",
# "J408189_B",
# "J499996",
# "J524940",
# "J535933",
# "J58841",
# ],
# "isolatable": True,
# "must_close_valves": ["210521658", "V12974", "V12986", "V12993"],
# "optional_valves": [],
# }
result = analyze_valve_isolation(network, accident_element, disabled_valves)
return result
+2 -2
View File
@@ -1,6 +1,7 @@
from fastapi import APIRouter
from app.api.v1.endpoints import (
auth,
copilot,
project,
simulation,
scada,
@@ -18,7 +19,6 @@ from app.api.v1.endpoints import (
user_management, # 新增:用户管理
audit, # 新增:审计日志
meta,
copilot_chat,
)
from app.api.v1.endpoints.network import (
general,
@@ -113,4 +113,4 @@ api_router.include_router(project_data.router, tags=["Project Data"])
api_router.include_router(extension.router, tags=["Extension"])
# Copilot Chat
api_router.include_router(copilot_chat.router, prefix="/copilot", tags=["Copilot"])
api_router.include_router(copilot.router, prefix="/copilot", tags=["Copilot"])