@@ -16,10 +16,12 @@ def __init__(self):
1616 self .settings_dict = Settings ().get_dict ()
1717
1818 self .interpreter = Interpreter (self .status_queue )
19+
20+ self .llm = None
1921 try :
2022 self .llm = LLM ()
2123 except OpenAIError as _ :
22- self .status_queue .put (" Set your OpenAPI API Key in Settings and Restart the App" )
24+ self .status_queue .put (' Set your OpenAPI API Key in Settings and Restart the App' )
2325
2426 def execute_user_request (self , user_request : str ) -> None :
2527 self .stop_previous_request ()
@@ -41,41 +43,47 @@ def execute(self, user_request: str, step_num: int = 0) -> Optional[str]:
4143 Also, it is needed because the LLM we are using doesn't have a stateful/assistant mode.
4244 """
4345 self .interrupt_execution = False
46+
47+ if not self .llm :
48+ status = 'Set your OpenAPI API Key in Settings and Restart the App'
49+ self .status_queue .put (status )
50+ return status
51+
4452 try :
4553 instructions : dict [str , Any ] = self .llm .get_instructions_for_objective (user_request , step_num )
4654
4755 if instructions == {}:
4856 # Sometimes LLM sends malformed JSON response, in that case retry once more.
49- instructions = self .llm .get_instructions_for_objective (user_request + " Please reply in valid JSON" ,
57+ instructions = self .llm .get_instructions_for_objective (user_request + ' Please reply in valid JSON' ,
5058 step_num )
5159
52- for step in instructions [" steps" ]:
60+ for step in instructions [' steps' ]:
5361 if self .interrupt_execution :
54- self .status_queue .put (" Interrupted" )
62+ self .status_queue .put (' Interrupted' )
5563 self .interrupt_execution = False
56- return " Interrupted"
64+ return ' Interrupted'
5765
5866 success = self .interpreter .process_command (step )
5967
6068 if not success :
61- return " Unable to execute the request"
69+ return ' Unable to execute the request'
6270
6371 except Exception as e :
64- self .status_queue .put (f"Exception Unable to execute the request - { e } " )
65- return f"Unable to execute the request - { e } "
72+ status = f'Exception Unable to execute the request - { e } '
73+ self .status_queue .put (status )
74+ return status
6675
67- if instructions [" done" ]:
76+ if instructions [' done' ]:
6877 # Communicate Results
69- self .status_queue .put (instructions [" done" ])
78+ self .status_queue .put (instructions [' done' ])
7079 self .play_ding_on_completion ()
71-
72- return instructions ["done" ]
80+ return instructions ['done' ]
7381 else :
7482 # if not done, continue to next phase
75- self .status_queue .put (" Fetching further instructions based on current state" )
83+ self .status_queue .put (' Fetching further instructions based on current state' )
7684 return self .execute (user_request , step_num + 1 )
7785
7886 def play_ding_on_completion (self ):
7987 # Play ding sound to signal completion
80- if 'play_ding_on_completion' in self .settings_dict and self . settings_dict [ 'play_ding_on_completion' ] :
88+ if self .settings_dict . get ( 'play_ding_on_completion' ) :
8189 print ('\a ' )
0 commit comments