Skip to content

Commit

Permalink
Merge pull request #2 from MrBearing/feat/ci_and_change_structure
Browse files Browse the repository at this point in the history
Change structure and add CI
  • Loading branch information
MrBearing authored Feb 3, 2024
2 parents 7822823 + 54db918 commit b93bdf5
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 54 deletions.
38 changes: 38 additions & 0 deletions .github/workflow/ci_humble.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ci_humble

on:
push:
branches:
- "humble"
pull_request:
types: [opened, synchronize, labeled]

jobs:
ci:
runs-on: ${{ matrix.os }}
if: |
((github.event.action == 'labeled') && (github.event.label.name == 'TESTING') && (github.base_ref == 'humble' )) ||
((github.event.action == 'synchronize') && (github.base_ref == 'humble') && contains(github.event.pull_request.labels.*.name, 'TESTING')) ||
(github.ref_name == 'humble')
container:
image: osrf/ros:${{ matrix.ros_distribution }}-desktop
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
ros_distribution: [humble]
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y wget python3-vcstool python3-colcon-coveragepy-result
- name: Build and Test
uses: ros-tooling/[email protected]
with:
target-ros2-distro: ${{ matrix.ros_distribution }}
import-token: ${{ secrets.GITHUB_TOKEN }}
package-name: |
chatgpt_ros_cpp
chatgpt_ros_cpp_node
chatgpt_ros_cpp_msgs
chatgpt_ros_cpp_bringup
21 changes: 21 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/opt/ros/humble/include/**",
"~/ws_humble/src/chatgpt_ros_cpp/chatgpt_ros_cpp/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14"
}
],
"version": 4
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"python.autoComplete.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"python.analysis.extraPaths": [
"/opt/ros/humble/lib/python3.10/site-packages",
"/opt/ros/humble/local/lib/python3.10/dist-packages"
],
"files.associations": {
"array": "cpp",
"*.tcc": "cpp",
"memory": "cpp",
"future": "cpp",
"istream": "cpp",
"functional": "cpp",
"tuple": "cpp",
"utility": "cpp",
"variant": "cpp"
}
}
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# chatgpt_ros_cpp
ROS for ChatGPT API in c++

ROS 2 service for ChatGPT API written in c++

## Usage

```
ros2 launch chatgpt_ros_cpp chat.launch.py api_key:="YOUR_OPEN_AI_API_KEY"
``` :bash
ros2 launch chatgpt_ros_cpp_bringup chat.launch.py api_key:="YOUR_OPEN_AI_API_KEY"
```
22 changes: 10 additions & 12 deletions chatgpt_ros_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
cmake_minimum_required(VERSION 3.8)
project(chatgpt_ros_cpp)

# Find dependencies
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

set(TARGET chatgpt_server)
set(MY_LIB_NAME ${PROJECT_NAME}_${TARGET})
ament_auto_add_library(${MY_LIB_NAME} SHARED src/${TARGET}.cpp)
rclcpp_components_register_node(
${MY_LIB_NAME}
PLUGIN "${PROJECT_NAME}::ChatGptServer"
EXECUTABLE ${TARGET}_exec)
target_link_libraries(${MY_LIB_NAME} cpprest)
find_package(ament_cmake REQUIRED)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_auto_package(INSTALL_TO_SHARE launch)
ament_package()
19 changes: 8 additions & 11 deletions chatgpt_ros_cpp/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>chatgpt_ros_cpp</name>
<version>0.0.0</version>
<description>ROS 2 package for ChatGPT API communication</description>
<maintainer email="[email protected]">Takumi Okamoto</maintainer>
<license>Apache License 2.0</license>
<version>0.1.0</version>
<description>meta package for chatgpt_ros_cpp</description>
<maintainer email="[email protected]">takumi</maintainer>
<license>Apache-2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>ament_cmake</buildtool_depend>

<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>std_msgs</depend>
<depend>cpprestsdk</depend>
<depend>nlohmann-json-dev</depend>
<depend>chatgpt_ros_interface</depend>
<depend>chatgpt_ros_cpp_bringup</depend>
<depend>chatgpt_ros_cpp_msgs</depend>
<depend>chatgpt_ros_cpp_node</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
10 changes: 4 additions & 6 deletions chatgpt_ros_cpp_bringup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(ament_cmake_auto REQUIRED)

# install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
Expand All @@ -23,4 +21,4 @@ if(BUILD_TESTING)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
ament_auto_package(INSTALL_TO_SHARE launch)
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ def generate_launch_description():
executable='component_container',
composable_node_descriptions=[
ComposableNode(
package='chatgpt_ros_cpp',
plugin='chatgpt_ros_cpp::ChatGptServer',
package='chatgpt_ros_cpp_node',
plugin='chatgpt_ros_cpp_node::ChatGptServer',
name='chatgpt_server',
namespace='',
parameters=[{
Expand Down
9 changes: 6 additions & 3 deletions chatgpt_ros_cpp_bringup/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
<name>chatgpt_ros_cpp_bringup</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<version>0.1.0</version>
<description>bringup package for chatgpt_ros_cpp</description>
<maintainer email="[email protected]">takumi</maintainer>
<license>A</license>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<exec_depend>chatgpt_ros_cpp_node</exec_depend>
<exec_depend>chatgpt_ros_cpp_msgs</exec_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(chatgpt_ros_interface)
project(chatgpt_ros_cpp_msgs)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?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>chatgpt_ros_interface</name>
<name>chatgpt_ros_cpp_msgs</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">takumi</maintainer>
<license>Apache License 2.0</license>
<license>Apache License 2.0Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>
<buildtool_depend>rosidl_default_generators</buildtool_depend>
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions chatgpt_ros_cpp_node/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.8)
project(chatgpt_ros_cpp_node)

# Find dependencies
find_package(ament_cmake_auto REQUIRED)
ament_auto_find_build_dependencies()

set(TARGET chatgpt_server)
set(MY_LIB_NAME ${PROJECT_NAME}_${TARGET})
ament_auto_add_library(${MY_LIB_NAME} SHARED src/${TARGET}.cpp)
rclcpp_components_register_node(
${MY_LIB_NAME}
PLUGIN "${PROJECT_NAME}::ChatGptServer"
EXECUTABLE ${TARGET}_exec)
target_link_libraries(${MY_LIB_NAME} cpprest)

if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_auto_package()
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
#include <cpprest/json.h>
#include <rclcpp/rclcpp.hpp>
#include <nlohmann/json.hpp>
#include <chatgpt_ros_interface/srv/chatgpt_service.hpp>
#include <chatgpt_ros_cpp_msgs/srv/chatgpt_service.hpp>

namespace chatgpt_ros_cpp {
namespace chatgpt_ros_cpp_node {

using ChatgptService = chatgpt_ros_interface::srv::ChatgptService;
using ChatgptService = chatgpt_ros_cpp_msgs::srv::ChatgptService;

class ChatGptServer : public rclcpp::Node{
public:
Expand All @@ -46,7 +46,7 @@ class ChatGptServer : public rclcpp::Node{
const std::shared_ptr<ChatgptService::Response> response);
};

} // namespace chatgpt_ros_cpp
} // namespace chatgpt_ros_cpp_node

#include "rclcpp_components/register_node_macro.hpp"
RCLCPP_COMPONENTS_REGISTER_NODE(chatgpt_ros_cpp::ChatGptServer)
RCLCPP_COMPONENTS_REGISTER_NODE(chatgpt_ros_cpp_node::ChatGptServer)
34 changes: 34 additions & 0 deletions chatgpt_ros_cpp_node/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>chatgpt_ros_cpp_node</name>
<version>0.0.0</version>
<description>ROS 2 package for ChatGPT API communication</description>
<maintainer email="[email protected]">Takumi Okamoto</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake_auto</buildtool_depend>

<build_depend>rclcpp</build_depend>
<build_depend>rclcpp_components</build_depend>
<build_depend>std_msgs</build_depend>
<!-- <build_depend>cpprestsdk</build_depend> -->
<build_depend>libcpprest-dev</build_depend>
<build_depend>nlohmann-json-dev</build_depend>
<build_depend>chatgpt_ros_cpp_msgs</build_depend>

<exec_depend>rclcpp</exec_depend>
<exec_depend>rclcpp_components</exec_depend>
<exec_depend>std_msgs</exec_depend>
<!-- <exec_depend>cpprestsdk</exec_depend> -->
<exec_depend>libcpprest-dev</exec_depend>
<exec_depend>nlohmann-json-dev</exec_depend>
<exec_depend>chatgpt_ros_cpp_msgs</exec_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "chatgpt_ros_cpp/chatgpt_server.hpp"
#include "chatgpt_ros_cpp_node/chatgpt_server.hpp"

namespace chatgpt_ros_cpp {
namespace chatgpt_ros_cpp_node {

ChatGptServer::ChatGptServer(const rclcpp::NodeOptions& options)
: Node("chat_gpt_server", options) {
Expand All @@ -35,11 +35,6 @@ ChatGptServer::ChatGptServer(const rclcpp::NodeOptions& options)
RCLCPP_INFO(this->get_logger(), "ChatGPTServer is ready.");
}

// ChatGptServer::~ChatGptServer() {
// // http_client_->reset();
// // server_->reset();
// }

void ChatGptServer::request_chat(
const std::shared_ptr<rmw_request_id_t> request_header,
const std::shared_ptr<ChatgptService::Request> request,
Expand All @@ -52,7 +47,7 @@ void ChatGptServer::request_chat(
nlohmann::json request_json;
request_json["model"] = "gpt-3.5-turbo";
request_json["messages"][0]["role"]= "user";
request_json["messages"][0]["content"]= query;
request_json["messages"][0]["content"] = query;
request_json["temperature"]= 0.7;

RCLCPP_INFO(this->get_logger(), "send request object");
Expand All @@ -78,6 +73,7 @@ void ChatGptServer::request_chat(

web::json::value json_result;
try {
RCLCPP_INFO("",)
json_result = res.extract_json().get()["choices"][0]["message"]["content"];
}catch (const std::exception & exp){
RCLCPP_ERROR(this->get_logger(), "Parser Error: %s ",
Expand Down Expand Up @@ -116,4 +112,4 @@ std::string ChatGptServer::getApiKey() {
}


} // namespace chatgpt_ros_cpp
} // namespace chatgpt_ros_cpp_node
Loading

0 comments on commit b93bdf5

Please sign in to comment.