Skip to content

Commit

Permalink
chat: comment and stability fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rmackay9 committed Dec 8, 2023
1 parent 06cfc7a commit 7072876
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions MAVProxy/modules/mavproxy_chat/chat_openai.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 7072876

Please sign in to comment.