|  | 
|  | 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() | 
0 commit comments