diff --git a/CMakeLists.txt b/CMakeLists.txt index 0729d10..19cc70f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.8) -project(ros2_openai_server) +project(robosoft_openai) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() -set(THIS_PACKAGE_INCLUDE_DEPENDS ai_msgs cv_bridge rclcpp sensor_msgs) +set(THIS_PACKAGE_INCLUDE_DEPENDS cv_bridge rclcpp robosoft_ai_msgs sensor_msgs) find_package(ament_cmake REQUIRED) find_package(CURL REQUIRED) @@ -32,13 +32,13 @@ install( TARGETS example_client openai_server ARCHIVE DESTINATION lib LIBRARY DESTINATION lib - RUNTIME DESTINATION lib/ros2_openai_server) + RUNTIME DESTINATION lib/robosoft_openai) -install(DIRECTORY include DESTINATION include/ros2_openai_server) +install(DIRECTORY include DESTINATION include/robosoft_openai) install( DIRECTORY test_data DESTINATION DESTINATION - share/ros2_openai_server) + share/robosoft_openai) ament_export_dependencies(rosidl_default_runtime) ament_package() diff --git a/README.md b/README.md index 0abe3ab..7061f20 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ros2_openai_server +# robosoft_openai OpenAI server node for ROS2 Applications @@ -32,22 +32,22 @@ Set it as an environment variable: `export OPENAI_API_KEY="..."` Here's a quick example: -`ros2 run ros2_openai_server openai_server` +`ros2 run robosoft_openai openai_server` Send it a prompt. Here's an example that returns a bool from a yes/no question. Note that the `image` field of the service request may be left empty... -`ros2 service call /openai_server ai_msgs/srv/BoolResponse prompt:\ "Are you a pirate? Please respond with a one-word answer, yes or no"` +`ros2 service call /openai_server robosoft_ai_msgs/srv/StringImagePrompt prompt:\ "Are you a pirate? Please respond with a one-word answer, yes or no"` Here's an example that returns a full string... -`ros2 service call /openai_string_response ai_msgs/srv/StringResponse prompt:\ "Are you a pirate?"` +`ros2 service call /openai_server robosoft_ai_msgs/srv/StringImagePrompt prompt:\ "Are you a pirate?"` Here's an example client which sends an image of a wooden table and prompts whether it is indeed a wooden table: -`ros2 run ros2_openai_server example_client` +`ros2 run robosoft_openai example_client` ## Citation If you use this work, please cite it like so: - - Zelenak, A., Lock, J., & Aldrich, B. (2024) *An OpenAI Server for ROS2*. Github. **https://github.com/robosoft-ai/ros2_openai_server** + - Zelenak, A., Lock, J., & Aldrich, B. (2024) *An OpenAI Server for ROS2*. Github. **https://github.com/robosoft-ai/robosoft_openai** diff --git a/include/ros2_openai_server/convert_image_to_base_64.hpp b/include/robosoft_openai/convert_image_to_base_64.hpp similarity index 96% rename from include/ros2_openai_server/convert_image_to_base_64.hpp rename to include/robosoft_openai/convert_image_to_base_64.hpp index ba00ca6..09a55d0 100644 --- a/include/ros2_openai_server/convert_image_to_base_64.hpp +++ b/include/robosoft_openai/convert_image_to_base_64.hpp @@ -6,7 +6,7 @@ #include #include -namespace openai_server +namespace robosoft_openai { /** * @brief Convert jpeg to base64 encoding. There are 2 possible input types. @@ -59,4 +59,4 @@ std::string convert_image_to_base_64(const std::optional& ima return os.str(); } -} // namespace openai_server +} // namespace robosoft_openai diff --git a/package.xml b/package.xml index 1f811e1..752cec8 100644 --- a/package.xml +++ b/package.xml @@ -1,7 +1,7 @@ - ros2_openai_server + robosoft_openai 0.0.0 A server which sends prompts to OpenAI andy @@ -9,9 +9,9 @@ ament_cmake - ai_msgs cv_bridge rclcpp + robosoft_ai_msgs sensor_msgs ament_lint_auto diff --git a/src/example_client.cpp b/src/example_client.cpp index 1603d11..dff90d4 100644 --- a/src/example_client.cpp +++ b/src/example_client.cpp @@ -1,4 +1,4 @@ -#include "ai_msgs/srv/string_image_prompt.hpp" +#include "robosoft_ai_msgs/srv/string_image_prompt.hpp" #include "rclcpp/rclcpp.hpp" #include @@ -15,14 +15,14 @@ int main(int argc, char** argv) rclcpp::init(argc, argv); std::shared_ptr node = rclcpp::Node::make_shared("open_ai_client"); - rclcpp::Client::SharedPtr client = - node->create_client("openai_server"); + rclcpp::Client::SharedPtr client = + node->create_client("openai_server"); - auto request = std::make_shared(); + auto request = std::make_shared(); request->prompt = "Is this a wooden table? Please respond in one word, yes or no."; // Add an image of a wooden table to the OpenAI request - std::string pkg_share_directory = ament_index_cpp::get_package_share_directory("ros2_openai_server"); + std::string pkg_share_directory = ament_index_cpp::get_package_share_directory("robosoft_openai"); std::string image_path = pkg_share_directory + "/test_data/wood_table.jpg"; cv::Mat img = cv::imread(image_path, cv::IMREAD_COLOR); sensor_msgs::msg::Image::SharedPtr msg = cv_bridge::CvImage(std_msgs::msg::Header(), "bgr8", img).toImageMsg(); diff --git a/src/openai_server.cpp b/src/openai_server.cpp index cb2ee7b..fab5bc0 100644 --- a/src/openai_server.cpp +++ b/src/openai_server.cpp @@ -1,6 +1,6 @@ -#include "ros2_openai_server/convert_image_to_base_64.hpp" +#include "robosoft_openai/convert_image_to_base_64.hpp" -#include "ai_msgs/srv/string_image_prompt.hpp" +#include "robosoft_ai_msgs/srv/string_image_prompt.hpp" #include "rclcpp/rclcpp.hpp" #include "sensor_msgs/msg/image.hpp" @@ -10,14 +10,14 @@ #include #include -namespace openai_server +namespace robosoft_openai { class OpenAIServer : public rclcpp::Node { public: OpenAIServer() : Node("service_client") { - prompt_srv_ = create_service( + prompt_srv_ = create_service( "openai_server", std::bind(&OpenAIServer::promptCallback, this, std::placeholders::_1, std::placeholders::_2)); curl_ = curl_easy_init(); @@ -144,8 +144,8 @@ class OpenAIServer : public rclcpp::Node * @param request service request * @param response bool response, parsed from OpenAI's string response */ - void promptCallback(const std::shared_ptr request, - std::shared_ptr response) + void promptCallback(const std::shared_ptr request, + std::shared_ptr response) { RCLCPP_INFO_STREAM(this->get_logger(), "Incoming StringImagePrompt request: " << request->prompt); std::string string_response; @@ -160,18 +160,18 @@ class OpenAIServer : public rclcpp::Node response->string_response = std::move(string_response); } - rclcpp::Service::SharedPtr prompt_srv_; + rclcpp::Service::SharedPtr prompt_srv_; std::string openai_key_string_; CURL* curl_; }; -} // namespace openai_server +} // namespace robosoft_openai int main(int argc, char* argv[]) { rclcpp::init(argc, argv); - auto service_client = std::make_shared(); + auto service_client = std::make_shared(); while (rclcpp::ok()) { rclcpp::spin_some(service_client); diff --git a/upstream.repos b/upstream.repos index c7c2024..047dada 100644 --- a/upstream.repos +++ b/upstream.repos @@ -1,5 +1,5 @@ repositories: - ai_msgs: + robosoft_ai_msgs: type: git - url: https://github.com/robosoft-ai/ai_msgs.git + url: https://github.com/robosoft-ai/robosoft_ai_msgs.git version: main