Skip to content

Commit

Permalink
GPTDevice working and tested
Browse files Browse the repository at this point in the history
Added dependencies to CI. Upd readme
  • Loading branch information
fbrand-new committed Aug 29, 2023
1 parent f2f1729 commit f3452ad
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 21 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/conda-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,27 @@ jobs:
cmake --build . --config ${{ matrix.build_type }}
cmake --install . --config ${{ matrix.build_type }}
echo "YARP_DATA_DIRS=${CONDA_PREFIX}/share/yarp::${YARP_DATA_DIRS}" >> $GITHUB_ENV
# libaoi dependencies
cd ${GITHUB_WORKSPACE}
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg integrate install
./vcpkg install curl
./vcpkg install nlohmann-json
#liboai
cd ${GITHUB_WORKSPACE}
git clone https://github.com/D7EAD/liboai.git
cd liboai/liboai
mkdir build
cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_POSITION_INDEPENDENT_CODE=true ..
cmake --build . --config ${{ matrix.build_type }}
cmake --install . --config ${{ matrix.build_type }}
- name: Dependencies from source [Windows]
if: contains(matrix.os, 'windows')
Expand All @@ -117,6 +138,26 @@ jobs:
cmake --build . --config ${{ matrix.build_type }}
cmake --install . --config ${{ matrix.build_type }}
echo "YARP_DATA_DIRS=${CONDA_PREFIX}/Library/share/yarp;${YARP_DATA_DIRS}" >> $GITHUB_ENV
# libaoi dependencies
cd ${GITHUB_WORKSPACE}
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg integrate install
./vcpkg install curl
./vcpkg install nlohmann-json
#liboai
cd ${GITHUB_WORKSPACE}
git clone https://github.com/D7EAD/liboai.git
cd liboai/liboai
mkdir build
cd build
cmake -G"Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX}/Library \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .. \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_POSITION_INDEPENDENT_CODE=true ..
cmake --build . --config ${{ matrix.build_type }}
cmake --install . --config ${{ matrix.build_type }}
- name: Configure [Linux&macOS]
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu')
Expand All @@ -128,6 +169,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} .. \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DLIBOAI_INSTALL_PATH=${GITHUB_WORKSPACE}/liboai \
-DYARP_COMPILE_TESTS:BOOL=ON
- name: Configure [Windows]
Expand All @@ -139,6 +182,8 @@ jobs:
cmake -G"Visual Studio 16 2019" -DBUILD_TESTING:BOOL=ON ^
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} ^
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX}\Library .. ^
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake ^
-DLIBOAI_INSTALL_PATH=${GITHUB_WORKSPACE}/liboai ^
-DYARP_COMPILE_TESTS:BOOL=ON
- name: Build [Linux&macOS]
Expand Down Expand Up @@ -231,6 +276,22 @@ jobs:
cmake --build . --config ${{ matrix.build_type }}
cmake --install . --config ${{ matrix.build_type }}
echo "YARP_DATA_DIRS=${CONDA_PREFIX}/share/yarp::${YARP_DATA_DIRS}" >> $GITHUB_ENV
# libaoi dependencies
cd ${GITHUB_WORKSPACE}
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh -disableMetrics
./vcpkg integrate install
./vcpkg install curl
./vcpkg install nlohmann-json
#liboai
cd ${GITHUB_WORKSPACE}
git clone https://github.com/D7EAD/liboai.git
cd liboai/liboai
cmake --build . --config ${{ matrix.build_type }} \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/vcpkg/scripts/buildsystems/vcpkg.cmake \
-DCMAKE_POSITION_INDEPENDENT_CODE=true \
cmake --install . --config ${{ matrix.build_type }}
- name: Configure [Linux&macOS]
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu')
Expand All @@ -242,6 +303,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DYARP_VALGRIND_TESTS:BOOL=ON \
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} .. \
-DCMAKE_TOOLCHAIN_FILE=${GITHUB_WORKSPACE}/scripts/buildsystems/vcpkg.cmake \
-DLIBOAI_INSTALL_PATH=${GITHUB_WORKSPACE}/liboai \
-DYARP_COMPILE_TESTS:BOOL=ON
- name: Build [Linux&macOS]
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ set +a
CI Status
---------

:construction: This repository is currently work in progress. :construction:

[![Build Status](https://github.com/robotology/yarp-device-template/workflows/CI%20Workflow/badge.svg)](https://github.com/robotology/yarp-device-template/actions?query=workflow%3A%22CI+Workflow%22)
[![Build Status](https://github.com/robotology/yarp-devices-llm/workflows/CI%20Workflow/badge.svg)](https://github.com/robotology/yarp-devices-llm/actions?query=workflow%3A%22CI+Workflow%22)

License
---------

:construction: This repository is currently work in progress. :construction:


Maintainers
--------------
Expand Down
31 changes: 19 additions & 12 deletions src/devices/GPTDevice/GPTDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ bool GPTDevice::open(yarp::os::Searchable &config)
azure_deployment_id = std::getenv("DEPLOYMENT_ID");
azure_resource = std::getenv("AZURE_RESOURCE");

// if(!azure_resource)
// {
// yError() << "Could not read env variable AZURE_RESOURCE, please provide it";
// return false;
// }

// if(!oai.auth.SetAzureKeyEnv("AZURE_API_KEY"))
// {
// yError() << "Invalid azure key provided";
// return false;
// }
if (!azure_resource)
{
yWarning() << "Could not read env variable AZURE_RESOURCE. Device set in offline mode";
m_offline = true;
return true;
}

if (!oai.auth.SetAzureKeyEnv("AZURE_API_KEY"))
{
yWarning() << "Invalid or no azure key provided. Device set in offline mode.";
m_offline = true;
}

return true;
}
Expand All @@ -33,6 +34,12 @@ bool GPTDevice::ask(const std::string &question, std::string &oAnswer)
// Adding prompt to conversation
m_convo->AddUserData(question);

if (m_offline)
{
yWarning() << "Device in offline mode";
return false;
}

// Asking gpt for an answer
try
{
Expand Down Expand Up @@ -118,4 +125,4 @@ bool GPTDevice::deleteConversation() noexcept
bool GPTDevice::close()
{
return true;
}
}
11 changes: 7 additions & 4 deletions src/devices/GPTDevice/GPTDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class GPTDevice : public yarp::dev::ILLM,
public yarp::dev::DeviceDriver
{
public:
GPTDevice() : ILLM(), m_convo{std::make_unique<liboai::Conversation>()}
GPTDevice() : ILLM(), m_convo{std::make_unique<liboai::Conversation>()}, m_offline{false}
{
}

Expand Down Expand Up @@ -46,13 +46,16 @@ class GPTDevice : public yarp::dev::ILLM,
std::unique_ptr<liboai::Conversation> m_convo;

// configuration
char* azure_resource;
char* azure_deployment_id;
char *azure_resource;
char *azure_deployment_id;
std::string azure_api_version;
liboai::OpenAI oai;

// offline mode for testing purpouses
bool m_offline;

// model
std::string m_model;
};

#endif // YARP_GPTDevice_H
#endif // YARP_GPTDevice_H
4 changes: 3 additions & 1 deletion src/devices/GPTDevice/tests/GPTDevice_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ TEST_CASE("dev::GPTDevice_test", "[yarp::dev]")
ret = illm->readPrompt(out_prompt);
CHECK(out_prompt == prompt);

//TODO: add illm->ask test without accessing internet
std::string answer;
ret = illm->ask("This is a question",answer);
CHECK(!ret); //If the device is offline ask will not work

std::vector<std::pair<Author,Content>> out_conversation;
ret = illm->getConversation(out_conversation);
Expand Down

0 comments on commit f3452ad

Please sign in to comment.