-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_parallel_classification.cpp
More file actions
64 lines (53 loc) · 1.65 KB
/
Copy path04_parallel_classification.cpp
File metadata and controls
64 lines (53 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
57
58
59
60
61
62
63
64
// Copyright 2026 Bontal LLC
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.
/**
* @file 04_parallel_classification.cpp
* @brief Concurrent classification across multiple messages using
* systemOneAsync.
*/
#include <typesafe/typesafe.h>
#include <future>
#include <iostream>
#include <string>
#include <vector>
#include "openrouter_helper.h"
int main()
{
try
{
auto client = typesafe::examples::createClient();
const std::vector<std::string> messages = {
"You won a free cruise! Click here to claim.",
"Hey, are we still on for lunch tomorrow?",
"Your invoice for August is attached. Thank you!",
"URGENT: your account will be suspended in 24 hours",
};
std::vector<std::future<typesafe::SystemOneResponse>> futures;
futures.reserve(messages.size());
for (const std::string &message : messages)
{
typesafe::SystemOneRequest request;
request.state = message;
request.add("spam", typesafe::Noul{
"Is this message unsolicited advertising?",
std::nullopt});
futures.push_back(client.systemOneAsync(request));
}
for (std::size_t index = 0; index < messages.size(); ++index)
{
const typesafe::SystemOneResponse answer = futures[index].get();
std::cout << (answer.nouls.at("spam").noul > 0.5 ? "SPAM "
: "clean")
<< " " << messages[index] << "\n";
}
return (0);
}
catch (const typesafe::TypeSafeError &error)
{
std::cerr << "TypeSafe: " << error.what() << "\n";
return (1);
}
}