-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage_runtime_test.cpp
More file actions
45 lines (35 loc) · 1.42 KB
/
Copy pathlanguage_runtime_test.cpp
File metadata and controls
45 lines (35 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "ai/language_runtime.hpp"
#include <cassert>
int main()
{
using namespace droidcli::ai;
using droidcli::core::String;
LanguageRuntime runtime;
runtime.set_system_prompt("You are a concise assistant.");
assert(runtime.submit_user_message("What is 2+2?"));
assert(runtime.snapshot().awaiting_response);
const OpenAICompatOutboundRequest request = runtime.build_pending_chat_request();
assert(request.valid);
assert(request.body.find("What is 2+2?") != String::npos);
OpenAICompatChatResponse response;
response.transport_ok = true;
response.http_success = true;
response.status_code = 200;
response.done = true;
response.assistant_message = "4";
assert(runtime.apply_chat_response(response));
assert(!runtime.snapshot().awaiting_response);
assert(runtime.representation_text() == "4");
assert(runtime.format_transcript().find("assistant: 4") != String::npos);
assert(runtime.transcript().size() == 3);
LanguageTransportCallbacks transport;
transport.post_json = [](const String&, const String&, const droidcli::core::Array<String>&, int32_t& status_code_out, String& response_body_out) {
status_code_out = 200;
response_body_out = R"({"choices":[{"index":0,"message":{"role":"assistant","content":"Done."},"finish_reason":"stop"}]})";
return true;
};
assert(runtime.submit_user_message("Next question"));
assert(runtime.complete_turn(transport));
assert(runtime.representation_text() == "Done.");
return 0;
}