Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configure AI model with gpt-4o by default. #32

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ros2ai/api/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

ROS_OPENAI_API_KEY_ENV_VAR = 'OPENAI_API_KEY'

ROS_OPENAI_DEFAULT_MODEL = 'gpt-4'
ROS_OPENAI_DEFAULT_MODEL = 'gpt-4o'
ROS_OPENAI_MODEL_NAME_ENV_VAR = 'OPENAI_MODEL_NAME'

ROS_OPENAI_DEFAULT_ENDPOINT = 'https://api.openai.com/v1'
Expand All @@ -31,7 +31,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 commands only without any comments.'
'provides executable command string only without any comments or code blocks.'

# Temperature controls the consistency for behavior. (range 0.0 - 2.0)
# The lower the temperature is, the more deterministic behavior that OpenAI does.
Expand Down
27 changes: 27 additions & 0 deletions ros2ai/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,30 @@ def get_ros_distro() -> str:
print('ROS_DISTRO env value is not set.')
return None
return distro.lower()

def truncate_before_substring(*, original, substring) -> str:
"""
Truncates a string by removing anything before a specified substring,
and removes the newline character at the end if it exists.

:original: original string to be truncated.
:substring: substring before which the string should be truncated.
:return: string with anything before the specified substring removed,
or the original string if the substring is not found.
"""
index = original.find(substring)
if index != -1:
# If found, truncate the string before the substring and return
truncated = original[index:]

# Find the index of newline character in the truncated text
newline_index = truncated.find('\n')
if newline_index != -1:
# If newline character exists, truncate the string after the newline character
truncated = truncated[:newline_index]

return truncated

else:
# If the substring is not found, return the original text
return original
6 changes: 4 additions & 2 deletions ros2ai/verb/exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from ros2ai.api import add_global_arguments
from ros2ai.api.utils import run_executable
from ros2ai.api.utils import run_executable, truncate_before_substring
from ros2ai.api.openai import ChatCompletionClient, ChatCompletionParameters
from ros2ai.api.utils import get_ros_distro
from ros2ai.verb import VerbExtension
Expand Down Expand Up @@ -58,4 +58,6 @@ def main(self, *, args):
client.call(completion_params)
if (args.debug is True):
client.print_all()
run_executable(command = client.get_result())
command_str = truncate_before_substring(
original = client.get_result(), substring = 'ros2')
run_executable(command = command_str)
Loading