diff --git a/ros2ai/api/constants.py b/ros2ai/api/constants.py index a7b5235..447e057 100644 --- a/ros2ai/api/constants.py +++ b/ros2ai/api/constants.py @@ -26,8 +26,12 @@ # However note that the system message is optional and the model’s behavior without a system message # is likely to be similar to using a generic message such as "You are a helpful assistant." # TODO@fujitatomoya: ROS_DISTRO would be better to assistant setting. -ROLE_SYSTEM_QUERY_DEFAULT = 'You are a ROS 2 helpful assistant.' -ROLE_SYSTEM_EXEC_DEFAULT = 'You are a ROS 2 command line executor, provides executable commands only without any comments.' +ROLE_SYSTEM_QUERY_DEFAULT = \ + 'You are a Robot Operating System version 2 (as known as ROS2) {} distribution ' \ + '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.' # Temperature controls the consistency for behavior. (range 0.0 - 2.0) # The lower the temperature is, the more deterministic behavior that OpenAI does. diff --git a/ros2ai/api/utils.py b/ros2ai/api/utils.py index 8541c3c..e83839b 100644 --- a/ros2ai/api/utils.py +++ b/ros2ai/api/utils.py @@ -14,6 +14,7 @@ import signal import subprocess +import os def run_command(*, command, argv = None, prefix = None): """ @@ -56,3 +57,15 @@ def run_executable(*, command, argv = None, prefix=None): if -process.returncode in signal.valid_signals(): print(signal.strsignal(-process.returncode)) return process.returncode + +def get_ros_distro() -> str: + """ + Fetch ROS_DISTRO environmental variable. + + :return: string of distribution name. + """ + distro = os.environ.get('ROS_DISTRO') + if not distro: + print('ROS_DISTRO env value is not set.') + return None + return distro.lower() diff --git a/ros2ai/verb/exec.py b/ros2ai/verb/exec.py index f457a3d..223348e 100644 --- a/ros2ai/verb/exec.py +++ b/ros2ai/verb/exec.py @@ -15,6 +15,7 @@ from ros2ai.api import add_global_arguments from ros2ai.api.utils import run_executable from ros2ai.api.openai import ChatCompletionClient, ChatCompletionParameters +from ros2ai.api.utils import get_ros_distro from ros2ai.verb import VerbExtension import ros2ai.api.constants as constants @@ -43,8 +44,12 @@ def main(self, *, args): if (request == ''): print('Please insert your request! (I am not AI)') + distro = get_ros_distro() + if distro is None: + distro = 'rolling' # fallback to rolling in default + system_role = constants.ROLE_SYSTEM_EXEC_DEFAULT.format(distro) user_request = [ - {"role": "system", "content": f"{constants.ROLE_SYSTEM_EXEC_DEFAULT}"}, + {"role": "system", "content": f"{system_role}"}, {"role": "user", "content": f"{request}"} ] diff --git a/ros2ai/verb/query.py b/ros2ai/verb/query.py index 55186b3..05336c3 100644 --- a/ros2ai/verb/query.py +++ b/ros2ai/verb/query.py @@ -14,6 +14,7 @@ from ros2ai.api import add_global_arguments from ros2ai.api.openai import ChatCompletionClient, ChatCompletionParameters +from ros2ai.api.utils import get_ros_distro from ros2ai.verb import VerbExtension import ros2ai.api.constants as constants @@ -47,8 +48,12 @@ def main(self, *, args): if (sentence == ''): print('Dont be shy, put some questions! (I am not AI)') + distro = get_ros_distro() + if distro is None: + distro = 'rolling' # fallback to rolling in default + system_role = constants.ROLE_SYSTEM_QUERY_DEFAULT.format(distro) user_messages = [ - {"role": "system", "content": f"{constants.ROLE_SYSTEM_QUERY_DEFAULT}"}, + {"role": "system", "content": f"{system_role}"}, {"role": "user", "content": f"{sentence}"} ]