Skip to content

Commit

Permalink
remove backticks from the executable command line string.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Sep 14, 2024
1 parent 4934113 commit b5d412a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ros2ai/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions ros2ai/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('`', '')
3 changes: 2 additions & 1 deletion ros2ai/verb/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions scripts/verification.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit b5d412a

Please sign in to comment.