YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
llama2Device_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::llama2Device_test", "[yarp::dev]")
18{
19 YARP_REQUIRE_PLUGIN("llama2Device", "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", "llama2Device");
32 pcfg.put("model_name", "/home/leonardo/Repos/yarp-device-llama2/models/gemma/gemma-2b-it.gguf");
33 REQUIRE(dd.open(pcfg));
34 }
35
36 //Do something
37 {
38 dd.view(illm);
39
40 std::string prompt = "This is a prompt";
41 std::string out_prompt;
42
43 bool ret = illm->readPrompt(out_prompt);
44 CHECK_FALSE(ret); //Prompt is not set yet
45
46 ret = illm->setPrompt(prompt);
47 CHECK(ret);
48
49 ret = illm->readPrompt(out_prompt);
50 CHECK(out_prompt == prompt);
51
52 //Since a prompt is already set you cannot set another one
53 //The user is expected to delete the conversation before starting a new one.
54 ret = illm->setPrompt(prompt);
55 CHECK(!ret);
56
58 ret = illm->ask("This is a question",answer);
59 CHECK(ret);
60
61 // check if roles and content are set correctly
62 std::vector<yarp::dev::LLM_Message> out_conversation;
63 ret = illm->getConversation(out_conversation);
64 CHECK(ret); //We have the system message
65 CHECK(out_conversation[0].type == "system");
66 CHECK(out_conversation[0].content == prompt);
67
68 // check if deleteConversation returns true
69 ret = illm->deleteConversation();
70 CHECK(ret);
71
72 // Check that conversation is actually deleted
73 ret = illm->getConversation(out_conversation);
74 CHECK(!ret);
75 }
76
77 //"Close all polydrivers and check"
78 {
79 CHECK(dd.close());
80 }
81 }
82
83 Network::setLocalMode(false);
84}
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
TEST_CASE("dev::llama2Device_test", "[yarp::dev]")
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
Definition OSTestMsg.cpp:13