33from datetime import timedelta
44from typing import List , Optional
55
6- from fastapi import APIRouter , Form , HTTPException , Query , Request , Response , UploadFile
6+ from fastapi import APIRouter , Form , HTTPException , Path , Query , Request , Response , UploadFile
77from fastapi .responses import StreamingResponse
88from sqlbot_xpack .file_utils import SQLBotFileUtils
99from sqlmodel import select
1010
11+ from apps .swagger .i18n import PLACEHOLDER_PREFIX
1112from apps .system .crud .assistant import get_assistant_info
1213from apps .system .crud .assistant_manage import dynamic_upgrade_cors , save
1314from apps .system .models .system_model import AssistantModel
1920from common .core .sqlbot_cache import clear_cache
2021from common .utils .utils import get_origin_from_referer , origin_match_domain
2122
22- router = APIRouter (tags = ["system/assistant " ], prefix = "/system/assistant" )
23+ router = APIRouter (tags = ["system_assistant " ], prefix = "/system/assistant" )
2324
2425
25- @router .get ("/info/{id}" )
26+ @router .get ("/info/{id}" , include_in_schema = False )
2627async def info (request : Request , response : Response , session : SessionDep , trans : Trans , id : int ) -> AssistantModel :
2728 if not id :
2829 raise Exception ('miss assistant id' )
@@ -42,7 +43,7 @@ async def info(request: Request, response: Response, session: SessionDep, trans:
4243 return db_model
4344
4445
45- @router .get ("/app/{appId}" )
46+ @router .get ("/app/{appId}" , include_in_schema = False )
4647async def getApp (request : Request , response : Response , session : SessionDep , trans : Trans , appId : str ) -> AssistantModel :
4748 if not appId :
4849 raise Exception ('miss assistant appId' )
@@ -61,7 +62,7 @@ async def getApp(request: Request, response: Response, session: SessionDep, tran
6162 return db_model
6263
6364
64- @router .get ("/validator" , response_model = AssistantValidator )
65+ @router .get ("/validator" , response_model = AssistantValidator , include_in_schema = False )
6566async def validator (session : SessionDep , id : int , virtual : Optional [int ] = Query (None )):
6667 if not id :
6768 raise Exception ('miss assistant id' )
@@ -86,8 +87,8 @@ async def validator(session: SessionDep, id: int, virtual: Optional[int] = Query
8687 return AssistantValidator (True , True , True , access_token )
8788
8889
89- @router .get ('/picture/{file_id}' )
90- async def picture (file_id : str ):
90+ @router .get ('/picture/{file_id}' , summary = f" { PLACEHOLDER_PREFIX } assistant_picture_api" , description = f" { PLACEHOLDER_PREFIX } assistant_picture_api" )
91+ async def picture (file_id : str = Path ( description = "file_id" ) ):
9192 file_path = SQLBotFileUtils .get_file_path (file_id = file_id )
9293 if not os .path .exists (file_path ):
9394 raise HTTPException (status_code = 404 , detail = "File not found" )
@@ -104,7 +105,7 @@ def iterfile():
104105 return StreamingResponse (iterfile (), media_type = media_type )
105106
106107
107- @router .patch ('/ui' )
108+ @router .patch ('/ui' , summary = f" { PLACEHOLDER_PREFIX } assistant_ui_api" , description = f" { PLACEHOLDER_PREFIX } assistant_ui_api" )
108109async def ui (session : SessionDep , data : str = Form (), files : List [UploadFile ] = []):
109110 json_data = json .loads (data )
110111 uiSchema = AssistantUiSchema (** json_data )
@@ -152,26 +153,26 @@ async def clear_ui_cache(id: int):
152153 pass
153154
154155
155- @router .get ("" , response_model = list [AssistantModel ])
156+ @router .get ("" , response_model = list [AssistantModel ], summary = f" { PLACEHOLDER_PREFIX } assistant_grid_api" , description = f" { PLACEHOLDER_PREFIX } assistant_grid_api" )
156157async def query (session : SessionDep ):
157158 list_result = session .exec (select (AssistantModel ).where (AssistantModel .type != 4 ).order_by (AssistantModel .name ,
158159 AssistantModel .create_time )).all ()
159160 return list_result
160161
161162
162- @router .get ("/advanced_application" , response_model = list [AssistantModel ])
163+ @router .get ("/advanced_application" , response_model = list [AssistantModel ], include_in_schema = False )
163164async def query_advanced_application (session : SessionDep ):
164165 list_result = session .exec (select (AssistantModel ).where (AssistantModel .type == 1 ).order_by (AssistantModel .name ,
165166 AssistantModel .create_time )).all ()
166167 return list_result
167168
168169
169- @router .post ("" )
170+ @router .post ("" , summary = f" { PLACEHOLDER_PREFIX } assistant_create_api" , description = f" { PLACEHOLDER_PREFIX } assistant_create_api" )
170171async def add (request : Request , session : SessionDep , creator : AssistantBase ):
171172 await save (request , session , creator )
172173
173174
174- @router .put ("" )
175+ @router .put ("" , summary = f" { PLACEHOLDER_PREFIX } assistant_update_api" , description = f" { PLACEHOLDER_PREFIX } assistant_update_api" )
175176@clear_cache (namespace = CacheNamespace .EMBEDDED_INFO , cacheName = CacheName .ASSISTANT_INFO , keyExpression = "editor.id" )
176177async def update (request : Request , session : SessionDep , editor : AssistantDTO ):
177178 id = editor .id
@@ -185,18 +186,18 @@ async def update(request: Request, session: SessionDep, editor: AssistantDTO):
185186 dynamic_upgrade_cors (request = request , session = session )
186187
187188
188- @router .get ("/{id}" , response_model = AssistantModel )
189- async def get_one (session : SessionDep , id : int ):
189+ @router .get ("/{id}" , response_model = AssistantModel , summary = f" { PLACEHOLDER_PREFIX } assistant_query_api" , description = f" { PLACEHOLDER_PREFIX } assistant_query_api" )
190+ async def get_one (session : SessionDep , id : int = Path ( description = "ID" ) ):
190191 db_model = await get_assistant_info (session = session , assistant_id = id )
191192 if not db_model :
192193 raise ValueError (f"AssistantModel with id { id } not found" )
193194 db_model = AssistantModel .model_validate (db_model )
194195 return db_model
195196
196197
197- @router .delete ("/{id}" )
198+ @router .delete ("/{id}" , response_model = AssistantModel , summary = f" { PLACEHOLDER_PREFIX } assistant_del_api" , description = f" { PLACEHOLDER_PREFIX } assistant_del_api" )
198199@clear_cache (namespace = CacheNamespace .EMBEDDED_INFO , cacheName = CacheName .ASSISTANT_INFO , keyExpression = "id" )
199- async def delete (request : Request , session : SessionDep , id : int ):
200+ async def delete (request : Request , session : SessionDep , id : int = Path ( description = "ID" ) ):
200201 db_model = session .get (AssistantModel , id )
201202 if not db_model :
202203 raise ValueError (f"AssistantModel with id { id } not found" )
0 commit comments