Skip to content

Commit faee54e

Browse files
authored
refactor: remove rai.utils module (#524)
1 parent 22e9472 commit faee54e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+294
-283
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ rosdep install --from-paths src --ignore-src -r -y
118118
Run the configuration tool to set up your vendor and other settings:
119119
120120
```bash
121-
poetry run streamlit run src/rai_core/rai/utils/configurator.py
121+
poetry run streamlit run src/rai_core/rai/frontend/configurator.py
122122
```
123123
124124
> [!TIP]

docs/debugging_assistant.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ The ROS 2 Debugging Assistant is an interactive tool that helps developers inspe
2222

2323
```sh
2424
source setup_shell.sh
25-
streamlit run src/rai_core/rai/tools/debugging_assistant.py
25+
streamlit run examples/debugging_assistant.py
2626
```
2727

2828
## Usage Examples

docs/developer_guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ from myrobot import robot
132132

133133
from rai.agents.conversational_agent import create_conversational_agent
134134
from rai.agents.state_based import create_state_based_agent
135-
from rai.utils.model_initialization import get_llm_model
135+
from rai import get_llm_model
136136

137137
SYSTEM_PROMPT = "You are a robot with interfaces..."
138138

docs/developer_guide/tools.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ TODO(docs): add link to the BaseAgent docs (regarding distributed setup)
195195
from rai.agents import ReActAgent
196196
from rai.communication import ROS2ARIConnector, ROS2HRIConnector
197197
from rai.tools.ros2 import ROS2Toolkit
198-
from rai.utils import ROS2Context, wait_for_shutdown
198+
from rai.communication.ros2 import ROS2Context
199+
from rai import AgentRunner
199200

200201
@ROS2Context()
201202
def main() -> None:
@@ -206,8 +207,8 @@ def main() -> None:
206207
connectors={"hri": connector},
207208
tools=initialize_tools(connector=ari_connector),
208209
)
209-
agent.run()
210-
wait_for_shutdown([agent])
210+
runner = AgentRunner([agent])
211+
runner.run_and_wait_for_shutdown()
211212

212213
# Example:
213214
# ros2 topic pub /from_human rai_interfaces/msg/HRIMessage "{\"text\": \"What do you see?\"}"
@@ -221,7 +222,7 @@ def main() -> None:
221222
```python
222223
from rai.agents.langchain import create_react_runnable
223224
from langchain.schema import HumanMessage
224-
from rai.utils import ROS2Context, wait_for_shutdown
225+
from rai.communication.ros2 import ROS2Context
225226

226227
@ROS2Context()
227228
def main():

docs/multimodal_messages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Example:
1818

1919
```python
2020
from rai.messages import HumanMultimodalMessage, preprocess_image
21-
from rai.utils.model_initialization import get_llm_model
21+
from rai import get_llm_model
2222

2323
base64_image = preprocess_image('https://raw.githubusercontent.com/RobotecAI/RobotecGPULidar/develop/docs/image/rgl-logo.png')
2424

docs/tracing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ To enable tracing in your RAI application, you need to import the get_tracing_ca
4040
1. First, import the get_tracing_callbacks() function:
4141

4242
```python
43-
from rai.utils.model_initialization import get_tracing_callbacks
43+
from rai import get_tracing_callbacks
4444
```
4545

4646
2. Then, add it to the configuration when invoking your agent or model:

examples/agents/react.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
# See the License for the specific language goveself.rning permissions and
1313
# limitations under the License.
1414

15-
from rai.agents import ReActAgent
16-
from rai.communication.ros2 import ROS2ARIConnector, ROS2HRIConnector
15+
from rai.agents import AgentRunner, ReActAgent
16+
from rai.communication.ros2 import ROS2ARIConnector, ROS2Context, ROS2HRIConnector
1717
from rai.tools.ros2 import ROS2Toolkit
18-
from rai.utils import ROS2Context, wait_for_shutdown
1918

2019

2120
@ROS2Context()
@@ -26,8 +25,8 @@ def main():
2625
connectors={"hri": connector},
2726
tools=ROS2Toolkit(connector=ari_connector).get_tools(),
2827
) # type: ignore
29-
agent.run()
30-
wait_for_shutdown([agent])
28+
runner = AgentRunner([agent])
29+
runner.run_and_wait_for_shutdown()
3130

3231

3332
if __name__ == "__main__":

examples/agriculture-demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import rclpy
1818
from langchain_core.messages import HumanMessage
1919
from langchain_core.runnables import Runnable
20+
from rai import get_llm_model
2021
from rai.agents.conversational_agent import State, create_conversational_agent
2122
from rai.communication.ros2.connectors import ROS2ARIConnector
2223
from rai.tools.ros2 import ROS2ServicesToolkit, ROS2TopicsToolkit
2324
from rai.tools.time import WaitForSecondsTool
24-
from rai.utils.model_initialization import get_llm_model
2525
from rclpy.callback_groups import ReentrantCallbackGroup
2626
from rclpy.executors import MultiThreadedExecutor
2727
from rclpy.node import Node

examples/debugging_assistant.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright (C) 2024 Robotec.AI
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import streamlit as st
16+
from rai import get_llm_model
17+
from rai.agents import create_conversational_agent
18+
from rai.frontend import run_streamlit_app
19+
from rai.tools.ros2 import ROS2CLIToolkit
20+
21+
22+
@st.cache_resource
23+
def initialize_agent():
24+
llm = get_llm_model(model_type="complex_model", streaming=True)
25+
agent = create_conversational_agent(
26+
llm,
27+
ROS2CLIToolkit().get_tools(),
28+
system_prompt="""You are a ROS 2 expert helping a user with their ROS 2 questions. You have access to various tools that allow you to query the ROS 2 system.
29+
Be proactive and use the tools to answer questions. Retrieve as much information from the ROS 2 system as possible.
30+
""",
31+
)
32+
return agent
33+
34+
35+
st.set_page_config(
36+
page_title="ROS 2 Debugging Assistant",
37+
page_icon=":robot:",
38+
)
39+
40+
41+
def main():
42+
run_streamlit_app(
43+
initialize_agent(),
44+
page_title="ROS 2 Debugging Assistant",
45+
initial_message="Hi! I am a ROS 2 assistant. How can I help you?",
46+
)
47+
48+
49+
if __name__ == "__main__":
50+
main()

examples/manipulation-demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
import rclpy
1717
import rclpy.qos
1818
from langchain_core.messages import HumanMessage
19+
from rai import get_llm_model
1920
from rai.agents.conversational_agent import create_conversational_agent
2021
from rai.communication.ros2.connectors import ROS2ARIConnector
2122
from rai.tools.ros2 import GetROS2ImageTool, GetROS2TopicsNamesAndTypesTool
2223
from rai.tools.ros2.manipulation import GetObjectPositionsTool, MoveToPointTool
23-
from rai.utils.model_initialization import get_llm_model
2424
from rai_open_set_vision.tools import GetGrabbingPointTool
2525

2626

0 commit comments

Comments
 (0)