11#!/usr/bin/python3
22# Copyright SUSE LLC
3- # ruff: noqa: BLE001, E501, S404, S603, T201, TRY300 , TRY400
3+ # ruff: noqa: ANN401, BLE001, C901, D103, E501, FA102, FBT001, FURB118, PLR0913, PLR0914, PLR0915, PLR0917, PLR2004, S404, S603, T201, TRY400
44"""Investigates an openQA job failure using an LLM."""
55
66import json
@@ -65,7 +65,7 @@ def post_comment(base_url: str, job_id: str, comment: str) -> None:
6565 log .error ("Failed to post comment: %s" , e .stderr )
6666
6767
68- def setup_logging (verbose : int , quiet : bool ) -> None : # noqa: FBT001
68+ def setup_logging (verbose : int , quiet : bool ) -> None :
6969 if quiet :
7070 level = logging .ERROR
7171 elif verbose >= 2 :
@@ -102,6 +102,7 @@ def _perform_investigation(
102102 dry : bool ,
103103 llm_url : str ,
104104 llm_model : str ,
105+ timeout : int ,
105106) -> None :
106107 # Check for existing LLM investigation comments
107108 comments = fetch_json (client , f"{ base_url } /api/v1/jobs/{ job_id } /comments" , default = [])
@@ -218,7 +219,7 @@ Provide exactly 3 sentences answering:
218219 }
219220
220221 try :
221- res = client .post (llm_url , json = req , timeout = 300 )
222+ res = client .post (llm_url , json = req , timeout = timeout )
222223 res .raise_for_status ()
223224 res_json = res .json ()
224225 llm_response = res_json ["choices" ][0 ]["message" ]["content" ]
@@ -262,6 +263,9 @@ def investigate(
262263 help = "Force another analysis even if an LLM comment already exists or if the job passed/softfailed" ,
263264 ),
264265 ] = False ,
266+ timeout : Annotated [int , typer .Option ("--timeout" , help = "Timeout for LLM API requests in seconds" )] = int (
267+ os .environ .get ("LLM_TIMEOUT" , "600" )
268+ ),
265269) -> None :
266270 setup_logging (verbose , quiet )
267271 base_url , job_id = parse_job_url (job_url )
@@ -274,7 +278,7 @@ def investigate(
274278 llm_model = os .environ .get ("LLM_MODEL" , "gemma-4-26B-A4B-it" )
275279
276280 with httpx .Client (headers = {"User-Agent" : USER_AGENT }) as client :
277- _perform_investigation (client , base_url , job_id , force , dry , llm_url , llm_model )
281+ _perform_investigation (client , base_url , job_id , force , dry , llm_url , llm_model , timeout )
278282
279283
280284if __name__ == "__main__" :
0 commit comments