From b5d412a2c95755abf510d89bbea8597c56e854f8 Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Fri, 13 Sep 2024 17:06:12 -0700 Subject: [PATCH] remove backticks from the executable command line string. Signed-off-by: Tomoya Fujita --- ros2ai/api/constants.py | 2 +- ros2ai/api/utils.py | 9 +++++++++ ros2ai/verb/exec.py | 3 ++- scripts/verification.sh | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ros2ai/api/constants.py b/ros2ai/api/constants.py index b6e89b1..282015d 100644 --- a/ros2ai/api/constants.py +++ b/ros2ai/api/constants.py @@ -36,7 +36,7 @@ 'professional assistant who can provide helpful answers against any questions.' ROLE_SYSTEM_EXEC_DEFAULT = \ 'You are a Robot Operating System 2 (as known as ROS2) {} distribution command line executor, ' \ - 'provides executable command string only without any comments or code blocks.' + 'provides executable command string only without any comments or code blocks or backticks.' ROLE_SYSTEM_ENV_VAR = 'OPENAI_ROLE_SYSTEM' # Temperature controls the consistency for behavior. (range 0.0 - 2.0) diff --git a/ros2ai/api/utils.py b/ros2ai/api/utils.py index c82b781..23c2d52 100644 --- a/ros2ai/api/utils.py +++ b/ros2ai/api/utils.py @@ -109,3 +109,12 @@ def truncate_before_substring(*, original, substring) -> str: else: # If the substring is not found, return the original text return original + +def remove_backticks(string) -> str: + """ + Removes all backticks from a given string. + + :string: The input string. + :return: The string without backticks. + """ + return string.replace('`', '') diff --git a/ros2ai/verb/exec.py b/ros2ai/verb/exec.py index 020dd19..cbe1960 100644 --- a/ros2ai/verb/exec.py +++ b/ros2ai/verb/exec.py @@ -16,7 +16,7 @@ from ros2ai.api.config import get_role_system from ros2ai.api.constants import ROLE_SYSTEM_EXEC_DEFAULT from ros2ai.api.openai import ChatCompletionClient, ChatCompletionParameters -from ros2ai.api.utils import get_ros_distro, run_executable, truncate_before_substring +from ros2ai.api.utils import get_ros_distro, run_executable, truncate_before_substring, remove_backticks from ros2ai.verb import VerbExtension @@ -73,6 +73,7 @@ def main(self, *, args): print(f"System role:\n{system_role}") command_str = truncate_before_substring( original = client.get_result(), substring = 'ros2') + command_str = remove_backticks(command_str) if not args.dry_run: run_executable(command = command_str) else: diff --git a/scripts/verification.sh b/scripts/verification.sh index e653765..ddf1f90 100755 --- a/scripts/verification.sh +++ b/scripts/verification.sh @@ -30,6 +30,7 @@ command_list=( "ros2 ai query \"say hello\"" "ros2 ai query \"say hello\" -nv" "ros2 ai query \"say hello\" -m gpt-4 -u https://api.openai.com/v1 -t 100" + #"ros2 ai query \"say hello\" -m llama3.1 -u http://localhost:11434/v1 -t 100" "ros2 ai exec \"give me all topics\"" "ros2 ai exec \"give me all topics\" --dry-run" "ros2 ai exec \"give me all topics\" -d"