Repository navigation
Expand file tree
/
Copy pathquickstart.cpp
More file actions
56 lines (49 loc) · 1.65 KB
/
Copy pathquickstart.cpp
File metadata and controls
56 lines (49 loc) · 1.65 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
46
47
48
49
50
51
52
53
54
55
56
#include <chrono>
#include <iostream>
#include <scry/scry.hpp>
#include <string>
#include <thread>
#include <utility>
// Each annotated member function becomes a tool that is bound to this object. The
// JSON schema and the argument decoder come from the signature, by reflection.
class HostTools {
public:
[[= scrydantic::tool{"Report the state of one subsystem"}]] std::string
subsystem_state(std::string name) const {
return name + " is running";
}
};
int fail(const scry::Error& error) {
std::cerr << error.message << '\n';
return 1;
}
int main() {
scry::ToolRegistry tools;
if (auto added = tools.add(HostTools{}); !added)
return fail(added.error());
// Assumes `ollama serve` is running and `ollama pull qwen3:8b` has completed.
auto harness =
scry::Harness::create({.base_url = "http://127.0.0.1:11434/v1",
.model = "qwen3:8b",
.dialect = scry::ProviderDialect::openai_compatible},
std::move(tools));
if (!harness)
return fail(harness.error());
auto conversation = scry::Conversation::create();
if (!conversation)
return fail(conversation.error());
const auto print = [](scry::Result<scry::Completion> done) {
if (done)
std::cout << done->text << '\n';
else
fail(done.error());
};
auto turn =
harness->send(*conversation, "Is the renderer running?", {.on_finished = print});
if (!turn)
return fail(turn.error());
while (!turn->finished()) {
harness->update(); // tool handlers and callbacks run here, on this thread
std::this_thread::sleep_for(std::chrono::milliseconds{1}); // your frame
}
}