forked from 0xeb/copilot-sdk-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreasoning_effort.cpp
More file actions
140 lines (118 loc) · 4.56 KB
/
Copy pathreasoning_effort.cpp
File metadata and controls
140 lines (118 loc) · 4.56 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Copyright (c) 2025 Elias Bachaalany
// SPDX-License-Identifier: MIT
/// @file reasoning_effort.cpp
/// @brief Example demonstrating reasoning effort configuration
///
/// This example shows how to:
/// 1. List available models and check which support reasoning effort
/// 2. Create a session with a specific reasoning effort level
/// 3. Compare responses at different reasoning effort levels
/// 4. Query model capabilities for supported reasoning efforts
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <copilot/copilot.hpp>
#include <iostream>
#include <mutex>
#include <string>
int main()
{
try
{
copilot::ClientOptions options;
copilot::Client client(options);
std::cout << "=== Reasoning Effort Example ===\n\n";
std::cout << "Reasoning effort controls how much 'thinking' a model does.\n";
std::cout << "Values: low, medium, high, xhigh\n\n";
client.start().get();
// List models and show which support reasoning effort
std::cout << "--- Available Models ---\n";
auto models = client.list_models().get();
for (const auto& model : models)
{
std::cout << " " << model.id;
if (model.capabilities.supports.reasoning_effort)
std::cout << " [reasoning effort: YES]";
if (model.supported_reasoning_efforts.has_value())
{
std::cout << " (levels: ";
for (size_t i = 0; i < model.supported_reasoning_efforts->size(); i++)
{
if (i > 0) std::cout << ", ";
std::cout << (*model.supported_reasoning_efforts)[i];
}
std::cout << ")";
}
if (model.default_reasoning_effort.has_value())
std::cout << " [default: " << *model.default_reasoning_effort << "]";
std::cout << "\n";
}
std::cout << "\n";
// Create session with reasoning effort
copilot::SessionConfig config;
config.reasoning_effort = copilot::ReasoningEffort::Medium;
// Permission handler
config.on_permission_request = [](const copilot::PermissionRequest&)
-> copilot::PermissionRequestResult
{
copilot::PermissionRequestResult r;
r.kind = "approved";
return r;
};
auto session = client.create_session(config).get();
std::cout << "Session created with reasoning_effort = 'medium'\n";
std::cout << "Session ID: " << session->session_id() << "\n\n";
std::mutex mtx;
std::condition_variable cv;
std::atomic<bool> idle{false};
auto sub = session->on(
[&](const copilot::SessionEvent& event)
{
if (auto* msg = event.try_as<copilot::AssistantMessageData>())
std::cout << "\nAssistant: " << msg->content << "\n";
else if (auto* usage = event.try_as<copilot::AssistantUsageData>())
{
std::cout << "[Usage:";
if (usage->input_tokens.has_value())
std::cout << " " << *usage->input_tokens << " in";
if (usage->output_tokens.has_value())
std::cout << " / " << *usage->output_tokens << " out";
if (usage->cost.has_value())
std::cout << " / cost=" << *usage->cost;
std::cout << "]\n";
}
else if (event.type == copilot::SessionEventType::SessionIdle)
{
std::lock_guard<std::mutex> lock(mtx);
idle = true;
cv.notify_one();
}
}
);
std::cout << "Chat with reasoning effort enabled. Type 'quit' to exit.\n\n> ";
std::string line;
while (std::getline(std::cin, line))
{
if (line == "quit" || line == "exit")
break;
if (line.empty()) { std::cout << "> "; continue; }
idle = false;
copilot::MessageOptions msg;
msg.prompt = line;
session->send(msg).get();
{
std::unique_lock<std::mutex> lock(mtx);
cv.wait(lock, [&idle]() { return idle.load(); });
}
std::cout << "\n> ";
}
session->destroy().get();
client.stop().get();
return 0;
}
catch (const std::exception& e)
{
std::cerr << "Error: " << e.what() << "\n";
return 1;
}
}