-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_openrouter.cpp
More file actions
83 lines (72 loc) · 2.78 KB
/
Copy path08_openrouter.cpp
File metadata and controls
83 lines (72 loc) · 2.78 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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 08_openrouter.cpp
* @brief Running Jev evaluations through OpenRouter's System One endpoint.
*/
#include <typesafe/typesafe.h>
#include <cstdlib>
#include <iostream>
#include <string>
int main()
{
const char *key = std::getenv("OPENROUTER_API_KEY");
if (key == nullptr || std::string(key).empty())
{
std::cout << "Set OPENROUTER_API_KEY to run this example.\n"
<< "Example:\n"
<< " export OPENROUTER_API_KEY=\"sk-or-v1-...\"\n"
<< " ./build/examples/08_openrouter\n";
return (0);
}
try
{
auto client
= typesafe::TypeSafeClient::builder().openrouter(key).build();
typesafe::SystemOneRequest request;
request.state
= "My subscription was renewed automatically yesterday, but I "
"meant "
"to cancel last week. Can I please get a refund?";
request.add("team",
typesafe::Choice{
"Route ticket to the appropriate team",
{{"billing", "Payments, invoices, renewals, refunds"},
{"support", "Technical bugs and errors"},
{"sales", "Enterprise pricing and upgrades"}}});
request.add("urgency",
typesafe::Score{"Assess customer urgency",
{"low (can wait)", "normal (within 24h)",
"urgent (immediate)"}});
request.add("is_refund_request",
typesafe::Noul{"Is the customer asking for a refund?",
std::nullopt});
std::cout << "Sending request to OpenRouter (typesafe/jev-1.13)...\n";
const typesafe::SystemOneResponse answer = client.systemOne(request);
std::cout << "\n=== Response from OpenRouter ===\n";
std::cout << "Model: " << answer.model << "\n";
std::cout << "Team Choice: " << answer.choices.at("team").choice
<< " (confidence: " << answer.choices.at("team").confidence
<< ")\n";
std::cout << "Urgency Score: " << answer.scores.at("urgency").score
<< " (confidence: " << answer.scores.at("urgency").confidence
<< ")\n";
std::cout << "Refund Request:"
<< (answer.nouls.at("is_refund_request").noul >= 0.70 ? " YES"
: " NO")
<< " (probability: "
<< answer.nouls.at("is_refund_request").noul << ")\n";
std::cout << "Token Usage: " << answer.usage.input_tokens
<< " input tokens, " << answer.usage.output_tokens
<< " output tokens\n";
return (0);
}
catch (const typesafe::TypeSafeError &error)
{
std::cerr << "TypeSafe Error: " << error.what() << "\n";
return (1);
}
}