Skip to content

Commit

Permalink
Message renaming (#6) (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyZe authored Jul 11, 2024
1 parent 6baae7b commit 6e338c6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(THIS_PACKAGE_INCLUDE_DEPENDS ament_index_cpp cv_bridge rclcpp robosoft_ai_msgs
sensor_msgs)
set(THIS_PACKAGE_INCLUDE_DEPENDS ament_index_cpp cv_bridge openai_msgs rclcpp sensor_msgs)

find_package(ament_cmake REQUIRED)
find_package(CURL REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ Here's a quick example:

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 robosoft_ai_msgs/srv/StringImagePrompt prompt:\ "Are you a pirate? Please respond with a one-word answer, yes or no"`
`ros2 service call /openai_server openai_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_server robosoft_ai_msgs/srv/StringImagePrompt prompt:\ "Are you a pirate?"`
`ros2 service call /openai_server openai_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:

Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<depend>ament_index_cpp</depend>
<depend>cv_bridge</depend>
<depend>openai_msgs</depend>
<depend>rclcpp</depend>
<depend>robosoft_ai_msgs</depend>
<depend>sensor_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
Expand Down
8 changes: 4 additions & 4 deletions src/example_client.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "robosoft_ai_msgs/srv/string_image_prompt.hpp"
#include "openai_msgs/srv/string_image_prompt.hpp"
#include "rclcpp/rclcpp.hpp"

#include <ament_index_cpp/get_package_share_directory.hpp>
Expand All @@ -15,10 +15,10 @@ 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<robosoft_ai_msgs::srv::StringImagePrompt>::SharedPtr client =
node->create_client<robosoft_ai_msgs::srv::StringImagePrompt>("openai_server");
rclcpp::Client<openai_msgs::srv::StringImagePrompt>::SharedPtr client =
node->create_client<openai_msgs::srv::StringImagePrompt>("openai_server");

auto request = std::make_shared<robosoft_ai_msgs::srv::StringImagePrompt::Request>();
auto request = std::make_shared<openai_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
Expand Down
10 changes: 5 additions & 5 deletions src/openai_server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "robosoft_openai/convert_image_to_base_64.hpp"

#include "robosoft_ai_msgs/srv/string_image_prompt.hpp"
#include "openai_msgs/srv/string_image_prompt.hpp"
#include "rclcpp/rclcpp.hpp"
#include "sensor_msgs/msg/image.hpp"

Expand All @@ -17,7 +17,7 @@ class OpenAIServer : public rclcpp::Node
public:
OpenAIServer() : Node("service_client")
{
prompt_srv_ = create_service<robosoft_ai_msgs::srv::StringImagePrompt>(
prompt_srv_ = create_service<openai_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<robosoft_ai_msgs::srv::StringImagePrompt::Request> request,
std::shared_ptr<robosoft_ai_msgs::srv::StringImagePrompt::Response> response)
void promptCallback(const std::shared_ptr<openai_msgs::srv::StringImagePrompt::Request> request,
std::shared_ptr<openai_msgs::srv::StringImagePrompt::Response> response)
{
RCLCPP_INFO_STREAM(this->get_logger(), "Incoming StringImagePrompt request: " << request->prompt);
std::string string_response;
Expand All @@ -160,7 +160,7 @@ class OpenAIServer : public rclcpp::Node
response->string_response = std::move(string_response);
}

rclcpp::Service<robosoft_ai_msgs::srv::StringImagePrompt>::SharedPtr prompt_srv_;
rclcpp::Service<openai_msgs::srv::StringImagePrompt>::SharedPtr prompt_srv_;

std::string openai_key_string_;
CURL* curl_;
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:
robosoft_ai_msgs:
openai_msgs:
type: git
url: https://github.com/robosoft-ai/robosoft_ai_msgs.git
url: https://github.com/robosoft-ai/openai_msgs.git
version: main

0 comments on commit 6e338c6

Please sign in to comment.