YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ILLMTest.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef ILLMTEST_H
7#define ILLMTEST_H
8
9#include <yarp/dev/ILLM.h>
11
12#include <catch2/catch_amalgamated.hpp>
13
14using namespace yarp::dev;
15
16namespace yarp::dev::tests {
18{
19 REQUIRE(illm != nullptr);
20
21 bool b;
22 std::string input_prompt1 = "A prompt";
23 std::string input_prompt2 = "A new prompt";
24
25 //set a prompt
26 b = illm->setPrompt(input_prompt1);
27 CHECK(b);
28
29 std::string prompt;
30 b = illm->readPrompt(prompt);
31 CHECK(b);
32 CHECK(prompt == input_prompt1);
33
34 //a new prompt can be assigned only after deleting conversation
35 b = illm->setPrompt("A new prompt, this will fail, until a reset is done");
36 CHECK(!b);
37
38 b = illm->deleteConversation();
39 CHECK(b);
40
41 //set a new prompt
42 b = illm->setPrompt(input_prompt2);
43 CHECK(b);
44
45 b = illm->readPrompt(prompt);
46 CHECK(b);
47 CHECK(prompt == input_prompt2);
48
49 //check answers
51 b = illm->ask("A question", answer);
52 CHECK(b);
53 CHECK(answer.type == "assistant");
54 CHECK(answer.content != "");
55 CHECK(answer.parameters.empty()); // No parameters in a non-function call
56 CHECK(answer.arguments.empty()); // No arguments in a non-function call
57
58 // The fake device returns a function_call if the question is "function"
59 b = illm->ask("function", answer);
60 CHECK(b);
61 CHECK(answer.type == "function");
62 CHECK(answer.content != "");
63 CHECK(!answer.parameters.empty());
64 CHECK(!answer.arguments.empty());
65
66
67 std::vector<yarp::dev::LLM_Message> conversation;
68 b = illm->getConversation(conversation);
69 CHECK(b);
70
71 b = illm->refreshConversation();
72 CHECK(b);
73
74 b = illm->readPrompt(prompt);
75 CHECK(b);
76
77 b = illm->deleteConversation();
78 CHECK(b);
79}
80}
81
82#endif
ILLM interface.
Definition ILLM.h:26
virtual yarp::dev::ReturnValue deleteConversation()=0
Delete the conversation and clear the system context from any internally stored context.
virtual yarp::dev::ReturnValue setPrompt(const std::string &prompt)=0
Performs a question.
virtual yarp::dev::ReturnValue getConversation(std::vector< yarp::dev::LLM_Message > &conversation)=0
Retrieves the whole conversation.
virtual yarp::dev::ReturnValue refreshConversation()=0
Refresh the conversation.
virtual yarp::dev::ReturnValue readPrompt(std::string &oPrompt)=0
Retrieves the provided prompt.
virtual yarp::dev::ReturnValue ask(const std::string &question, yarp::dev::LLM_Message &answer)=0
Performs a question.
std::vector< std::string > parameters
possible parameters
std::string type
type of message (can be prompt, assistant, function, ...)
std::vector< std::string > arguments
possible arguments of the parameters
std::string content
content of the message
void exec_iLLM_test_1(yarp::dev::ILLM *illm)
Definition ILLMTest.h:17
For streams capable of holding different kinds of content, check what they actually have.