diff --git a/MAVProxy/modules/mavproxy_chat/chat_openai.py b/MAVProxy/modules/mavproxy_chat/chat_openai.py index 53605d73fd..9f82facb2e 100644 --- a/MAVProxy/modules/mavproxy_chat/chat_openai.py +++ b/MAVProxy/modules/mavproxy_chat/chat_openai.py @@ -1,6 +1,9 @@ ''' AI Chat Module OpenAi interface Randy Mackay, December 2023 + +OpenAI Assistant API: https://platform.openai.com/docs/api-reference/assistants +OpenAI Assistant Playground: https://platform.openai.com/playground ''' from MAVProxy.modules.lib import mp_module @@ -98,6 +101,9 @@ def send_to_assistant(self, text): run_id=self.run.id ) + # print run status to console + print("run status:" + latest_run.status) + # check run status if latest_run.status in ["queued", "in_progress", "cancelling"]: run_done = False @@ -110,8 +116,6 @@ def send_to_assistant(self, text): print ("unrecognised run status" + latest_run.status) run_done = True - print("run status:" + latest_run.status) - print("Run done!") print(latest_run) @@ -157,7 +161,8 @@ def handle_function_call(self, run): return None for tool_call in run.required_action.submit_tool_outputs.tool_calls: - # check function name + + # get current date and time if tool_call.function.name == "get_current_datetime": run_reply = self.client.beta.threads.runs.submit_tool_outputs( thread_id=run.thread_id, @@ -193,10 +198,15 @@ def handle_function_call(self, run): ) return + # send mavlink command_int if tool_call.function.name == "send_mavlink_command_int": print("send_mavlink_command_int received:") print(tool_call) - arguments = json.loads(tool_call.function.arguments) + try: + arguments = json.loads(tool_call.function.arguments) + except: + print("chat::handle_function_call: failed to parse arguments") + return print(arguments) run_reply = self.client.beta.threads.runs.submit_tool_outputs( thread_id=run.thread_id, @@ -208,6 +218,7 @@ def handle_function_call(self, run): ) return + # send mavlink set_position_target_global_int if tool_call.function.name == "send_mavlink_set_position_target_global_int": print("send_mavlink_set_position_target_global_int received:") print(tool_call)