diff --git a/README.md b/README.md
index db58441..de9896e 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 --break-system-packages
+ pip install openai ollama validators --break-system-packages
```
> [!NOTE]
@@ -60,7 +60,7 @@ https://github.com/fujitatomoya/ros2ai/assets/43395114/2af4fd44-2ccf-472c-9153-c
- `iron` / `humble`
```bash
- pip install openai ollama
+ pip install openai ollama validators
```
### Build
diff --git a/docker/Dockerfile b/docker/Dockerfile
index e60274c..e2bc418 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; \
+ pip install openai ollama validators; \
elif [ "$ROS_DISTRO" = "iron" ]; then \
- pip install openai ollama; \
+ pip install openai ollama validators; \
else \
- pip install openai ollama --break-system-packages; \
+ pip install openai ollama validators --break-system-packages; \
fi
# Build and source colcon workspace
diff --git a/package.xml b/package.xml
index 16c54ca..fe40ae9 100644
--- a/package.xml
+++ b/package.xml
@@ -15,6 +15,8 @@
curl
python3-openai-pip
+ python3-ollama-pip
+ python3-validotors-pip
ros2cli
ament_copyright
diff --git a/ros2ai/api/config.py b/ros2ai/api/config.py
index 55e5e11..cfc9e61 100644
--- a/ros2ai/api/config.py
+++ b/ros2ai/api/config.py
@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import validators
import os
import ros2ai.api.constants as constants
@@ -36,7 +37,6 @@ def get_ai_model() -> str:
"""
model_name = os.environ.get(constants.ROS_OPENAI_MODEL_NAME_ENV_VAR)
if not model_name:
- print('AI model is not set, defaults to ' + constants.ROS_OPENAI_DEFAULT_MODEL)
return constants.ROS_OPENAI_DEFAULT_MODEL
else:
return model_name
@@ -48,12 +48,16 @@ def get_endpoint_url() -> str:
:return: string of OpenAI API service endpoint URL, could be None.
"""
url = os.environ.get(constants.ROS_OPENAI_ENDPOINT_ENV_VAR)
- # TODO(@fujitatomoya):check if that is valid url before return.
- if not url:
- print('AI model is not set, defaults to ' + constants.ROS_OPENAI_DEFAULT_ENDPOINT)
+ url_valid = False
+ try:
+ url_valid = validators.url(url)
+ except Exception as e:
+ print(f"Error validating URL: {e}")
return constants.ROS_OPENAI_DEFAULT_ENDPOINT
- else:
+ if url and url_valid:
return url
+ else:
+ return constants.ROS_OPENAI_DEFAULT_ENDPOINT
def get_temperature() -> float:
"""
diff --git a/scripts/github_workflows.sh b/scripts/github_workflows.sh
index a732c55..3486f2d 100755
--- a/scripts/github_workflows.sh
+++ b/scripts/github_workflows.sh
@@ -41,9 +41,9 @@ 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 --break-system-packages
+ pip install openai ollama validators --break-system-packages
else
- pip install openai ollama
+ pip install openai ollama validators
fi
#apt install -y ros-${ROS_DISTRO}-desktop --no-install-recommends
cd $there