Skip to content

Commit

Permalink
Package renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyZe committed Jul 11, 2024
1 parent def464c commit 7f8ed60
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ros2_openai_server
# robosoft_openai

OpenAI server node for ROS2 Applications

Expand Down Expand Up @@ -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**
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <opencv2/opencv.hpp>
#include <optional>

namespace openai_server
namespace robosoft_openai
{
/**
* @brief Convert jpeg to base64 encoding. There are 2 possible input types.
Expand Down Expand Up @@ -59,4 +59,4 @@ std::string convert_image_to_base_64(const std::optional<const std::string>& ima

return os.str();
}
} // namespace openai_server
} // namespace robosoft_openai
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>ros2_openai_server</name>
<name>robosoft_openai</name>
<version>0.0.0</version>
<description>A server which sends prompts to OpenAI</description>
<maintainer email="[email protected]">andy</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>ai_msgs</depend>
<depend>cv_bridge</depend>
<depend>rclcpp</depend>
<depend>robosoft_ai_msgs</depend>
<depend>sensor_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
10 changes: 5 additions & 5 deletions src/example_client.cpp
Original file line number Diff line number Diff line change
@@ -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 <ament_index_cpp/get_package_share_directory.hpp>
Expand All @@ -15,14 +15,14 @@ int main(int argc, char** argv)
rclcpp::init(argc, argv);

std::shared_ptr<rclcpp::Node> node = rclcpp::Node::make_shared("open_ai_client");
rclcpp::Client<ai_msgs::srv::StringImagePrompt>::SharedPtr client =
node->create_client<ai_msgs::srv::StringImagePrompt>("openai_server");
rclcpp::Client<robosoft_ai_msgs::srv::StringImagePrompt>::SharedPtr client =
node->create_client<robosoft_ai_msgs::srv::StringImagePrompt>("openai_server");

auto request = std::make_shared<ai_msgs::srv::StringImagePrompt::Request>();
auto request = std::make_shared<robosoft_ai_msgs::srv::StringImagePrompt::Request>();
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();
Expand Down
18 changes: 9 additions & 9 deletions src/openai_server.cpp
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -10,14 +10,14 @@
#include <sensor_msgs/image_encodings.hpp>
#include <stdlib.h>

namespace openai_server
namespace robosoft_openai
{
class OpenAIServer : public rclcpp::Node
{
public:
OpenAIServer() : Node("service_client")
{
prompt_srv_ = create_service<ai_msgs::srv::StringImagePrompt>(
prompt_srv_ = create_service<robosoft_ai_msgs::srv::StringImagePrompt>(
"openai_server", std::bind(&OpenAIServer::promptCallback, this, std::placeholders::_1, std::placeholders::_2));

curl_ = curl_easy_init();
Expand Down Expand Up @@ -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<ai_msgs::srv::StringImagePrompt::Request> request,
std::shared_ptr<ai_msgs::srv::StringImagePrompt::Response> response)
void promptCallback(const std::shared_ptr<robosoft_ai_msgs::srv::StringImagePrompt::Request> request,
std::shared_ptr<robosoft_ai_msgs::srv::StringImagePrompt::Response> response)
{
RCLCPP_INFO_STREAM(this->get_logger(), "Incoming StringImagePrompt request: " << request->prompt);
std::string string_response;
Expand All @@ -160,18 +160,18 @@ class OpenAIServer : public rclcpp::Node
response->string_response = std::move(string_response);
}

rclcpp::Service<ai_msgs::srv::StringImagePrompt>::SharedPtr prompt_srv_;
rclcpp::Service<robosoft_ai_msgs::srv::StringImagePrompt>::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<openai_server::OpenAIServer>();
auto service_client = std::make_shared<robosoft_openai::OpenAIServer>();
while (rclcpp::ok())
{
rclcpp::spin_some(service_client);
Expand Down
4 changes: 2 additions & 2 deletions upstream.repos
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7f8ed60

Please sign in to comment.