Skip to content

Commit d81d7d3

Browse files
committed
refactor: move debugging assistant to examples
1 parent fe3ffe1 commit d81d7d3

File tree

5 files changed

+80
-87
lines changed

5 files changed

+80
-87
lines changed

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

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.conversational_agent import create_conversational_agent
18+
from rai.frontend.streamlit 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()

src/rai_core/rai/tools/debugging_assistant.py

Lines changed: 0 additions & 85 deletions
This file was deleted.

src/rai_core/rai/tools/ros2/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
from .cli import (
16+
ROS2CLIToolkit,
17+
ros2_action,
18+
ros2_interface,
19+
ros2_node,
20+
ros2_param,
21+
ros2_service,
22+
ros2_topic,
23+
)
1524
from .generic import (
1625
CallROS2ServiceTool,
1726
CancelROS2ActionTool,
@@ -67,9 +76,16 @@
6776
"NavigateToPoseTool",
6877
"PublishROS2MessageTool",
6978
"ROS2ActionToolkit",
79+
"ROS2CLIToolkit",
7080
"ROS2ServicesToolkit",
7181
"ROS2Toolkit",
7282
"ROS2TopicsToolkit",
7383
"ReceiveROS2MessageTool",
7484
"StartROS2ActionTool",
85+
"ros2_action",
86+
"ros2_interface",
87+
"ros2_node",
88+
"ros2_param",
89+
"ros2_service",
90+
"ros2_topic",
7591
]

src/rai_core/rai/tools/ros2/cli.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from threading import Timer
1717
from typing import List, Literal, Optional
1818

19-
from langchain_core.tools import tool
19+
from langchain_core.tools import BaseTool, BaseToolkit, tool
2020

2121
FORBIDDEN_CHARACTERS = ["&", ";", "|", "&&", "||", "(", ")", "<", ">", ">>", "<<"]
2222

@@ -52,6 +52,18 @@ def run_command(cmd: List[str], timeout: int = 5):
5252
return str(output)
5353

5454

55+
class ROS2CLIToolkit(BaseToolkit):
56+
def get_tools(self) -> List[BaseTool]:
57+
return [
58+
ros2_action,
59+
ros2_service,
60+
ros2_node,
61+
ros2_param,
62+
ros2_interface,
63+
ros2_topic,
64+
]
65+
66+
5567
@tool
5668
def ros2_action(
5769
command: Literal["info", "list", "type", "send_goal"],

0 commit comments

Comments
 (0)