1717from assemblyline_ui .api .base import api_login , make_api_response , make_subapi_blueprint , stream_file_response
1818from assemblyline_ui .config import ALLOW_ZIP_DOWNLOADS , ALLOW_RAW_DOWNLOADS , FILESTORE , STORAGE , config , \
1919 CLASSIFICATION as Classification , ARCHIVESTORE
20- from assemblyline_ui .helper .ai import AiApiException , summarize_code_snippet as ai_code , summarized_al_submission
20+ from assemblyline_ui .helper .ai import APIException , EmptyAIResponse , \
21+ summarize_code_snippet as ai_code , summarized_al_submission
2122from assemblyline_ui .helper .result import format_result
2223from assemblyline_ui .helper .user import load_user_settings
2324from assemblyline .datastore .collection import Index
@@ -325,7 +326,10 @@ def summarized_results(sha256, **kwargs):
325326 /api/v4/file/ai/123456...654321/
326327
327328 Result example:
328- <AI summary of the AL results>
329+ {
330+ "content": <AI summary of the AL results>,
331+ "truncated": false
332+ }
329333 """
330334 if not config .ui .ai .enabled :
331335 return make_api_response ({}, "AI Support is disabled on this system." , 400 )
@@ -341,7 +345,7 @@ def summarized_results(sha256, **kwargs):
341345 # TODO: Caching maybe?
342346 ai_summary = summarized_al_submission (data )
343347 return make_api_response (ai_summary )
344- except AiApiException as e :
348+ except ( APIException , EmptyAIResponse ) as e :
345349 return make_api_response ("" , str (e ), 400 )
346350
347351
@@ -365,7 +369,10 @@ def summarize_code_snippet(sha256, **kwargs):
365369 /api/v4/file/code_summary/123456...654321/
366370
367371 Result example:
368- <AI summary of the code snippet>
372+ {
373+ "content": <AI summary of the code snippet>,
374+ "truncated": false
375+ }
369376 """
370377 if not config .ui .ai .enabled :
371378 return make_api_response ({}, "AI Support is disabled on this system." , 400 )
@@ -406,7 +413,7 @@ def summarize_code_snippet(sha256, **kwargs):
406413 # TODO: Caching maybe?
407414 ai_summary = ai_code (data )
408415 return make_api_response (ai_summary )
409- except AiApiException as e :
416+ except ( APIException , EmptyAIResponse ) as e :
410417 return make_api_response ("" , str (e ), 400 )
411418 else :
412419 return make_api_response ({}, "You are not allowed to view this file." , 403 )
0 commit comments