Skip to content

Commit

Permalink
Add streaming support (#20)
Browse files Browse the repository at this point in the history
* refactor: better error handling and response parsing for ROS2 tools, add blacklist where applicable.

* feat(ros2): add ros2 topic echo tool.

* chore: bump version to 1.0.4, update CHANGELOG.md

* chore: bump langchain versions.

* Simplified within_bounds function by removing redundant 'elif' condition. Improved code readability and maintainability. (#13)

* Add unit tests and CI. (#14)

* feat(tests): add unit tests for most tools and the ROSATools class.
* fix: passing a blacklist into any of the tools no longer overrides the blacklist passed into the ROSA constructor. They are concatenated instead.
* feat(CI): add ci workflow.
* fix: properly filter out blacklisted topics and nodes.
* feat(tests): add ros2 tests.
* feat(ci): update humble jobs.
* feat(ci): finalize initial version of ci.

* feat(tests): add stubs for additional test classes.

* docs: update README

* chore: bump version to 1.0.5

* fix typos (#17)

* Add streaming support (#19)

* chore: remove verbose logging where it isn't required.

* chore: remove unnecessary apt installations.

* fix: minor typo

* chore: update gitignore

* chore: update PR template

* Update turtle agent demo to support streaming responses.

* feat(streaming): add the ability to stream responses from ROSA.

* feat(demo): update demo script, apply formatting.

* feat(demo): update demo TUI, fix bounds checking in turtle tools.

* feat(demo): clean up Docker demo, add another example of adding tools to the agent.

* docs: update README.

* docs: update README.

* Update README.md

* chore: minor formating and linting.

* chore: switch setup configuration to use pyproject.toml

* feat(demo): properly implement streaming REPL interface.

* chore: bump version to 1.0.6

* chore: specify version in CHANGELOG.

---------

Co-authored-by: Kejun Liu <[email protected]>
Co-authored-by: Kejun Liu <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent daf74bc commit d22eb90
Show file tree
Hide file tree
Showing 21 changed files with 674 additions and 335 deletions.
5 changes: 4 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
## Purpose
- Clear, easy-to-understand sentences outlining the purpose of the PR

## Proposed Changes
- [ADD] ...
- [CHANGE] ...
- [REMOVE] ...
- [FIX] ...

## Issues
- Links to relevant issues
- Example: issue-XYZ

## Testing
- Provide some proof you've tested your changes
- Example: test results available at ...
- Example: tested on operating system ...
- Example: tested on operating system ...
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
python-version: '>=3.9 <4.0'

- name: Install dependencies
run: pip install setuptools wheel twine
run: pip install build twine

- name: Build package
run: python setup.py sdist bdist_wheel
run: python -m build

- name: Publish package
env:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.idea
.vscode
src/jpl_rosa.egg-info
build/
dist/
__pycache__/
__pycache__/
docs
.DS_Store
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.6]

### Added

* Implemented streaming capability for ROSA responses
* Added `pyproject.toml` for modern Python packaging
* Implemented asynchronous operations in TurtleAgent for better responsiveness

### Changed

* Updated Dockerfile for improved build process and development mode support
* Refactored TurtleAgent class for better modularity and streaming support
* Improved bounds checking for turtle movements
* Updated demo script for better cross-platform support and X11 forwarding
* Renamed `set_debuging` to `set_debugging` in system tools

### Fixed

* Corrected typos and improved documentation in various files
* Fixed potential issues with turtle movement calculations

### Removed

* Removed unnecessary logging statements from turtle tools

## [1.0.5]

### Added
Expand Down
65 changes: 28 additions & 37 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,43 @@
FROM osrf/ros:noetic-desktop as rosa-ros1
FROM osrf/ros:noetic-desktop AS rosa-ros1
LABEL authors="Rob Royce"

ENV DEBIAN_FRONTEND=noninteractive
ENV HEADLESS=false
ARG DEVELOPMENT=false

# Install linux packages
RUN apt-get update && apt-get install -y \
ros-$(rosversion -d)-turtlesim \
locales \
lsb-release \
git \
subversion \
nano \
terminator \
xterm \
wget \
curl \
htop \
gnome-terminal \
libssl-dev \
build-essential \
dbus-x11 \
software-properties-common \
build-essential \
ssh \
ros-$(rosversion -d)-turtlesim
xvfb \
python3.9 \
python3-pip

# RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y python3.9
RUN apt-get update && apt-get install -y python3-pip
RUN python3 -m pip install -U python-dotenv catkin_tools
RUN python3.9 -m pip install -U jpl-rosa>=1.0.5

# Configure ROS
RUN rosdep update
RUN echo "source /opt/ros/noetic/setup.bash" >> /root/.bashrc
RUN echo "export ROSLAUNCH_SSH_UNKNOWN=1" >> /root/.bashrc
RUN rosdep update && \
echo "source /opt/ros/noetic/setup.bash" >> /root/.bashrc && \
echo "alias start='catkin build && source devel/setup.bash && roslaunch turtle_agent agent.launch'" >> /root/.bashrc && \
echo "export ROSLAUNCH_SSH_UNKNOWN=1" >> /root/.bashrc

COPY . /app/
WORKDIR /app/

# Uncomment this line to test with local ROSA package
# RUN python3.9 -m pip install --user -e .
# Modify the RUN command to use ARG
RUN /bin/bash -c 'if [ "$DEVELOPMENT" = "true" ]; then \
python3.9 -m pip install --user -e .; \
else \
python3.9 -m pip install -U jpl-rosa>=1.0.5; \
fi'

# Run roscore in the background, then run `rosrun turtlesim turtlesim_node` in a new terminal, finally run main.py in a new terminal
CMD /bin/bash -c 'source /opt/ros/noetic/setup.bash && \
roscore & \
sleep 2 && \
rosrun turtlesim turtlesim_node > /dev/null & \
sleep 3 && \
echo "" && \
echo "Run \`catkin build && source devel/setup.bash && roslaunch turtle_agent agent\` to launch the ROSA-TurtleSim demo." && \
/bin/bash'
CMD ["/bin/bash", "-c", "source /opt/ros/noetic/setup.bash && \
roscore > /dev/null 2>&1 & \
sleep 5 && \
if [ \"$HEADLESS\" = \"false\" ]; then \
rosrun turtlesim turtlesim_node & \
else \
xvfb-run -a -s \"-screen 0 1920x1080x24\" rosrun turtlesim turtlesim_node & \
fi && \
sleep 5 && \
echo \"Run \\`start\\` to build and launch the ROSA-TurtleSim demo.\" && \
/bin/bash"]
88 changes: 47 additions & 41 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,65 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# This script is used to launch the ROSA demo in Docker
# This script launches the ROSA demo in Docker

# Check if the user has docker installed
# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo "Docker is not installed. Please install docker and try again."
echo "Error: Docker is not installed. Please install Docker and try again."
exit 1
fi

# Set default headless mode
HEADLESS=${HEADLESS:-false}
DEVELOPMENT=${DEVELOPMENT:-false}

# Get the platform
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" == "Linux" ]; then
platform='linux'
elif [ "$unamestr" == "Darwin" ]; then
platform='mac'
elif [ "$unamestr" == "Windows" ]; then
platform='win'
fi
# Enable X11 forwarding based on OS
case "$(uname)" in
Linux)
echo "Enabling X11 forwarding for Linux..."
export DISPLAY=:0
xhost +local:docker
;;
Darwin)
echo "Enabling X11 forwarding for macOS..."
ip=$(ifconfig en0 | awk '$1=="inet" {print $2}')
export DISPLAY=$ip:0
xhost + $ip
;;
MINGW*|CYGWIN*|MSYS*)
echo "Enabling X11 forwarding for Windows..."
export DISPLAY=host.docker.internal:0
;;
*)
echo "Error: Unsupported operating system."
exit 1
;;
esac

# Enable X11 forwarding for mac and linux
if [ "$platform" == "mac" ] || [ "$platform" == "linux" ]; then
echo "Enabling X11 forwarding..."
export DISPLAY=host.docker.internal:0
xhost +
elif [ "$platform" == "win" ]; then
# Windows support is experimental
echo "The ROSA-TurtleSim demo has not been tested on Windows. It may not work as expected."
read -p "Do you want to continue? (y/n): " confirm
if [ "$confirm" != "y" ]; then
echo "Please check back later for Windows support."
exit 0
fi
export DISPLAY=host.docker.internal:0
# Check if X11 forwarding is working
if ! xset q &>/dev/null; then
echo "Error: X11 forwarding is not working. Please check your X11 server and try again."
exit 1
fi

# Build the docker image
echo "Building the docker image..."
docker build -t rosa -f Dockerfile .
# Build and run the Docker container
CONTAINER_NAME="rosa-turtlesim-demo"
echo "Building the $CONTAINER_NAME Docker image..."
docker build --build-arg DEVELOPMENT=$DEVELOPMENT -t $CONTAINER_NAME -f Dockerfile . || { echo "Error: Docker build failed"; exit 1; }

# Run the docker container
echo "Running the docker container..."
docker run -it --rm --name rosa \
-e DISPLAY=$DISPLAY \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v ./src:/app/src \
-v ./data:/root/data \
--network host \
rosa
echo "Running the Docker container..."
docker run -it --rm --name $CONTAINER_NAME \
-e DISPLAY=$DISPLAY \
-e HEADLESS=$HEADLESS \
-e DEVELOPMENT=$DEVELOPMENT \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v "$PWD/src":/app/src \
-v "$PWD/tests":/app/tests \
--network host \
$CONTAINER_NAME

# Disable X11 forwarding
xhost -

exit 0
exit 0
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "jpl-rosa"
version = "1.0.6"
description = "ROSA: the Robot Operating System Agent"
readme = "README.md"
authors = [{ name = "Rob Royce", email = "[email protected]" }]
license = { file = "LICENSE" }
classifiers = [
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
]
keywords = ["Robotics", "Data Science", "Machine Learning", "Data Engineering", "Data Infrastructure", "Data Analysis"]
requires-python = ">=3.9, <4"
dependencies = [
"PyYAML==6.0.1",
"python-dotenv>=1.0.1",
"langchain==0.2.14",
"langchain-community==0.2.12",
"langchain-core==0.2.34",
"langchain-openai==0.1.22",
"langchain-ollama",
"pydantic",
"pyinputplus",
"azure-identity",
"cffi",
"rich",
"pillow>=10.4.0",
"numpy>=1.21.2",
]

[project.urls]
"Homepage" = "https://github.com/nasa-jpl/rosa"
"Bug Tracker" = "https://github.com/nasa-jpl/rosa/issues"

[tool.setuptools.packages.find]
where = ["src"]
54 changes: 2 additions & 52 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pathlib
from distutils.core import setup

from setuptools import find_packages

here = pathlib.Path(__file__).parent.resolve()
long_description = (here / "README.md").read_text(encoding="utf-8")
rosa_packages = find_packages(where="src")

setup(
name="jpl-rosa",
version="1.0.5",
license="Apache 2.0",
description="ROSA: the Robot Operating System Agent",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/nasa-jpl/rosa",
author="Rob Royce",
author_email="[email protected]",
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Natural Language :: English",
"Operating System :: Unix",
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
keywords="Robotics, Data Science, Machine Learning, Data Engineering, Data Infrastructure, Data Analysis",
package_dir={"": "src"},
packages=rosa_packages,
python_requires=">=3.9, <4",
install_requires=[
"PyYAML==6.0.1",
"python-dotenv>=1.0.1",
"langchain==0.2.14",
"langchain-community==0.2.12",
"langchain-core==0.2.34",
"langchain-openai==0.1.22",
"pydantic",
"pyinputplus",
"azure-identity",
"cffi",
"rich",
"pillow>=10.4.0",
"numpy>=1.21.2",
],
project_urls={ # Optional
"Bug Reports": "https://github.com/nasa-jpl/rosa/issues",
"Source": "https://github.com/nasa-jpl/rosa",
},
)
if __name__ == "__main__":
setup()
6 changes: 6 additions & 0 deletions src/rosa/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,10 @@ def __str__(self):
"You must use your math tools to perform calculations. Failing to do this may result in a catastrophic "
"failure of the system. You must never perform calculations manually or assume you know the correct answer. ",
),
(
"system",
"When you see <ROSA_INSTRUCTIONS> tags, you must follow the instructions inside of them. "
"These instructions are instructions for how to use ROS tools to complete a task. "
"You must follow these instructions IN ALL CASES. ",
),
]
Loading

0 comments on commit d22eb90

Please sign in to comment.