From d22aa63757f66f5b13318f63608493b771d0608e Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Tue, 17 Dec 2024 21:49:11 -0800 Subject: [PATCH 1/3] use 127.0.0.1 instead of localhost that is invalid URL by validator. Signed-off-by: Tomoya Fujita --- README.md | 4 ++-- ros2ai/api/__init__.py | 2 +- ros2ai/api/config.py | 1 + ros2ai/api/constants.py | 2 +- scripts/verification.sh | 7 ++++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 44aaa30..efbd627 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ User need to choose either of them is used by `ros2ai` as following configuratio | :----------------------| :-------------------------- | :--------------------- | | OPENAI_API_KEY | None. | Required for OpenAI | | OPENAI_MODEL_NAME | 'gpt-4o' | AI model to be used. e.g) llama3.1 (Ollama) | -| OPENAI_ENDPOINT | 'https://api.openai.com/v1' | API endpoint URL. e.g) http://localhost:11434/v1 (Ollama) | +| OPENAI_ENDPOINT | 'https://api.openai.com/v1' | API endpoint URL. e.g) http://127.0.0.1:11434/v1 (Ollama) | | OPENAI_TEMPERATURE | 0.5 | [OpenAI temperature](https://platform.openai.com/docs/guides/text-generation/how-should-i-set-the-temperature-parameter) | > [!NOTE] @@ -136,7 +136,7 @@ User need to choose either of them is used by `ros2ai` as following configuratio ### Ollama unset OPENAI_API_KEY export OPENAI_MODEL_NAME=llama3.1 - export OPENAI_ENDPOINT=http://localhost:11434/v1 + export OPENAI_ENDPOINT=http://127.0.0.1:11434/v1 ``` - `status` to check OpenAI API key is valid. diff --git a/ros2ai/api/__init__.py b/ros2ai/api/__init__.py index 25e225a..22741e4 100644 --- a/ros2ai/api/__init__.py +++ b/ros2ai/api/__init__.py @@ -69,7 +69,7 @@ def curl_get_request(url, headers=None) -> Tuple[bool, Optional[List[str]]]: return False, None -# curl http://localhost:11434/api/tags +# curl http://127.0.0.1:11434/api/tags def ollama_get_models(url, headers=None) -> Tuple[bool, Optional[List[str]]]: # only supports basic curl subprocess command curl_cmd = ["curl", url] diff --git a/ros2ai/api/config.py b/ros2ai/api/config.py index cfc9e61..0a09027 100644 --- a/ros2ai/api/config.py +++ b/ros2ai/api/config.py @@ -50,6 +50,7 @@ def get_endpoint_url() -> str: url = os.environ.get(constants.ROS_OPENAI_ENDPOINT_ENV_VAR) url_valid = False try: + # this returns ValidationError with `http://localhost:11434/v1` url_valid = validators.url(url) except Exception as e: print(f"Error validating URL: {e}") diff --git a/ros2ai/api/constants.py b/ros2ai/api/constants.py index 282015d..bb2dd82 100644 --- a/ros2ai/api/constants.py +++ b/ros2ai/api/constants.py @@ -21,7 +21,7 @@ ROS_OPENAI_MODEL_NAME_ENV_VAR = 'OPENAI_MODEL_NAME' ROS_OPENAI_DEFAULT_ENDPOINT = 'https://api.openai.com/v1' -ROS_OLLAMA_DEFAULT_ENDPOINT = 'http://localhost:11434/v1' +ROS_OLLAMA_DEFAULT_ENDPOINT = 'http://127.0.0.1:11434/v1' ROS_OPENAI_ENDPOINT_ENV_VAR = 'OPENAI_ENDPOINT' diff --git a/scripts/verification.sh b/scripts/verification.sh index dd1d010..1beab7a 100755 --- a/scripts/verification.sh +++ b/scripts/verification.sh @@ -12,7 +12,7 @@ # User Setting # ################ -# ROS setting should be done before calling this scripts, fallking back to defaults. +# ROS setting should be done before calling this scripts, falling back to defaults. ROS_VERSION="${ROS_VERSION:-2}" ROS_PYTHON_VERSION="${ROS_PYTHON_VERSION:-3}" ROS_AUTOMATIC_DISCOVERY_RANGE="${ROS_AUTOMATIC_DISCOVERY_RANGE:-SUBNET}" @@ -29,8 +29,9 @@ command_list=( "ros2 ai query -h" "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" + # TODO(@fujitatomoya): use environmental variable instead. + #"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://127.0.0.1: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" From e0e7e40e40950c6b54dd174093a9211bf12b2ffb Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Tue, 17 Dec 2024 22:02:18 -0800 Subject: [PATCH 2/3] add '--ignore-installed' with pip install for github workflow. Signed-off-by: Tomoya Fujita --- scripts/github_workflows.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/github_workflows.sh b/scripts/github_workflows.sh index 3486f2d..8364b7a 100755 --- a/scripts/github_workflows.sh +++ b/scripts/github_workflows.sh @@ -41,7 +41,7 @@ function install_prerequisites () { # TODO@fujitatomoya: should install openai via package.xml apt install -y pip if [ $UBUNTU_VERSION == "24.04" ]; then - pip install openai ollama validators --break-system-packages + pip install openai ollama validators --break-system-packages --ignore-installed else pip install openai ollama validators fi From 1d875719798a402f7751f0f546f51fa7f6c31f83 Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Tue, 17 Dec 2024 22:05:08 -0800 Subject: [PATCH 3/3] add '--ignore-installed' to other distribution and docs. Signed-off-by: Tomoya Fujita --- README.md | 4 ++-- docker/Dockerfile | 6 +++--- scripts/github_workflows.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index efbd627..21088ca 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ https://github.com/fujitatomoya/ros2ai/assets/43395114/2af4fd44-2ccf-472c-9153-c - `rolling` / `jazzy` ```bash - pip install openai ollama validators --break-system-packages + pip install openai ollama validators --break-system-packages --ignore-installed ``` > [!NOTE] @@ -60,7 +60,7 @@ https://github.com/fujitatomoya/ros2ai/assets/43395114/2af4fd44-2ccf-472c-9153-c - `iron` / `humble` ```bash - pip install openai ollama validators + pip install openai ollama validators --ignore-installed ``` ### Build diff --git a/docker/Dockerfile b/docker/Dockerfile index e2bc418..4824b50 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -39,11 +39,11 @@ RUN apt-get update \ # Adapt pip install option based on distro (technically ubuntu version) RUN if [ "$ROS_DISTRO" = "humble" ]; then \ - pip install openai ollama validators; \ + pip install openai ollama validators --ignore-installed; \ elif [ "$ROS_DISTRO" = "iron" ]; then \ - pip install openai ollama validators; \ + pip install openai ollama validators --ignore-installed; \ else \ - pip install openai ollama validators --break-system-packages; \ + pip install openai ollama validators --break-system-packages --ignore-installed; \ fi # Build and source colcon workspace diff --git a/scripts/github_workflows.sh b/scripts/github_workflows.sh index 8364b7a..1ddd80e 100755 --- a/scripts/github_workflows.sh +++ b/scripts/github_workflows.sh @@ -43,7 +43,7 @@ function install_prerequisites () { if [ $UBUNTU_VERSION == "24.04" ]; then pip install openai ollama validators --break-system-packages --ignore-installed else - pip install openai ollama validators + pip install openai ollama validators --ignore-installed fi #apt install -y ros-${ROS_DISTRO}-desktop --no-install-recommends cd $there