YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GPTDevice_test.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include <yarp/os/Network.h>
9#include <yarp/dev/ILLM.h>
10
11#include <catch2/catch_amalgamated.hpp>
12#include <harness.h>
13
14using namespace yarp::dev;
15using namespace yarp::os;
16
17TEST_CASE("dev::GPTDevice_test", "[yarp::dev]")
18{
19 YARP_REQUIRE_PLUGIN("GPTDevice", "device");
20
21 Network::setLocalMode(true);
22
23 SECTION("Checking the device")
24 {
25 PolyDriver dd;
26 ILLM* illm = nullptr;
27
28 //"Checking opening device"
29 {
31 pcfg.put("device", "GPTDevice");
32 REQUIRE(dd.open(pcfg));
33 }
34
35 // Do something
36 {
37 dd.view(illm);
38
39 std::string prompt = "This is a prompt";
40 std::string out_prompt;
41
42 bool ret = illm->readPrompt(out_prompt);
43 CHECK_FALSE(ret); //Prompt is not set yet
44
45 ret = illm->setPrompt(prompt);
46 CHECK(ret);
47
48 ret = illm->readPrompt(out_prompt);
49 CHECK(out_prompt == prompt);
50
51 //Since a prompt is already set you cannot set another one
52 //The user is expected to delete the conversation before starting a new one.
53 ret = illm->setPrompt(prompt);
54 CHECK(!ret);
55
57 ret = illm->ask("This is a question",answer);
58 CHECK(!ret); //If the device is offline ask will not work
59
60 std::vector<yarp::dev::LLM_Message> out_conversation;
61 ret = illm->getConversation(out_conversation);
62 CHECK(ret); //We have the system message
63 CHECK(out_conversation[0].type == "system");
64 CHECK(out_conversation[0].content == prompt);
65
66 ret = illm->deleteConversation();
67 CHECK(ret);
68
69 // Check that conversation is actually deleted
70 ret = illm->getConversation(out_conversation);
71 CHECK(!ret);
72 }
73
74 //"Close all polydrivers and check"
75 {
76 CHECK(dd.close());
77 }
78 }
79
80 SECTION("Check GTPDevice functions")
81 {
82 PolyDriver dd;
83 ILLM* illm = nullptr;
84
85 //"Checking opening device with functions"
86 {
88 pcfg.put("device", "GPTDevice");
89 pcfg.put("functions_file","functions_test.json");
90 REQUIRE(dd.open(pcfg));
91 }
92
93 {
94 dd.view(illm);
95
96 // Since we are in offline mode, we cannot test a proper function call
97 }
98
99 //"Close all polydrivers and check"
100 {
101 CHECK(dd.close());
102 }
103
104 }
105
106 Network::setLocalMode(false);
107}
TEST_CASE("dev::GPTDevice_test", "[yarp::dev]")
bool ret
bool view(T *&x)
Get an interface to the device driver.
ILLM interface.
Definition ILLM.h:26
A container for a device driver.
Definition PolyDriver.h:23
bool close() override
Close the DeviceDriver.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.