Skip to content

Commit e8dd857

Browse files
committed
Rename handler -> client to reflect MCP terminology
1 parent 9db9686 commit e8dd857

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

examples/main/main.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <vector>
1818

1919
#ifdef LLAMA_USE_TOOLCALL
20-
# include "toolcall-handler.h"
20+
# include "toolcall-client.h"
2121
#endif
2222

2323
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__))
@@ -100,9 +100,9 @@ class chat_formatter {
100100
std::vector<common_chat_msg> & chat_msgs,
101101
struct common_chat_templates * chat_templates,
102102
const llama_vocab * vocab,
103-
toolcall::handler::ptr tc_handler)
103+
toolcall::client::ptr tc_client)
104104

105-
: params_(params), chat_msgs_(chat_msgs), chat_templates_(chat_templates), vocab_(vocab), tc_handler_(tc_handler) {}
105+
: params_(params), chat_msgs_(chat_msgs), chat_templates_(chat_templates), vocab_(vocab), tc_client_(tc_client) {}
106106
#endif
107107

108108
std::string operator () (const std::string & role, const std::string & content, [[maybe_unused]] bool use_toolcalls = false) {
@@ -114,9 +114,9 @@ class chat_formatter {
114114
common_chat_params cparams;
115115
common_chat_templates_inputs cinputs;
116116
#ifdef LLAMA_USE_TOOLCALL
117-
if (tc_handler_ != nullptr && use_toolcalls) {
118-
cinputs.tool_choice = common_chat_tool_choice_parse_oaicompat(tc_handler_->tool_choice());
119-
cinputs.tools = common_chat_tools_parse_oaicompat(tc_handler_->tool_list());
117+
if (tc_client_ != nullptr && use_toolcalls) {
118+
cinputs.tool_choice = common_chat_tool_choice_parse_oaicompat(tc_client_->tool_choice());
119+
cinputs.tools = common_chat_tools_parse_oaicompat(tc_client_->tool_list());
120120
}
121121
#endif
122122
bool add_ass = role == "user";
@@ -140,7 +140,7 @@ class chat_formatter {
140140

141141
#ifdef LLAMA_USE_TOOLCALL
142142
const llama_vocab * vocab_;
143-
toolcall::handler::ptr tc_handler_;
143+
toolcall::client::ptr tc_client_;
144144
#endif
145145
};
146146

@@ -328,11 +328,11 @@ int main(int argc, char ** argv) {
328328
std::vector<llama_token> embd_inp;
329329

330330
#ifdef LLAMA_USE_TOOLCALL
331-
auto tc_handler = toolcall::create_handler(tc_params);
332-
if (tc_handler) {
333-
tc_handler->initialize();
331+
auto tc_client = toolcall::create_client(tc_params);
332+
if (tc_client) {
333+
tc_client->initialize();
334334
}
335-
chat_formatter chat_add_and_format(params, chat_msgs, chat_templates.get(), vocab, tc_handler);
335+
chat_formatter chat_add_and_format(params, chat_msgs, chat_templates.get(), vocab, tc_client);
336336
#else
337337
chat_formatter chat_add_and_format(params, chat_msgs, chat_templates.get());
338338
#endif
@@ -851,8 +851,8 @@ int main(int argc, char ** argv) {
851851
if (params.enable_chat_template) {
852852
chat_add_and_format("assistant", assistant_ss.str(), true);
853853
#ifdef LLAMA_USE_TOOLCALL
854-
auto should_use_toolcall = [&params, tc_handler] (const std::string & asst_msg) {
855-
if (! params.use_jinja || tc_handler == nullptr) {
854+
auto should_use_toolcall = [&params, tc_client] (const std::string & asst_msg) {
855+
if (! params.use_jinja || tc_client == nullptr) {
856856
return false;
857857
}
858858
try {
@@ -865,7 +865,7 @@ int main(int argc, char ** argv) {
865865
};
866866

867867
if (should_use_toolcall(assistant_ss.str())) {
868-
toolcall::result_set res = tc_handler->call(assistant_ss.str());
868+
toolcall::result_set res = tc_client->call(assistant_ss.str());
869869
if (! res.empty()) {
870870
std::string toolcall_result_str;
871871
for (const auto & r : res) {

toolcall/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
set(TARGET toolcall)
33

44
set(SOURCES
5-
handler.cpp
5+
client.cpp
66
mcp_messages.cpp
77
mcp_stdio_transport.cpp
88
params.cpp
99
)
1010

1111
set(HEADERS
1212
toolcall-params.h
13-
toolcall-handler.h
13+
toolcall-client.h
1414
mcp_transport.h
1515
mcp_messages.h
1616
mcp_stdio_transport.h

toolcall/handler.cpp renamed to toolcall/client.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#include <json.hpp>
3-
#include "toolcall-handler.h"
3+
#include "toolcall-client.h"
44
#include <chrono>
55
#include <stdexcept>
66

@@ -12,48 +12,48 @@
1212

1313
using json = nlohmann::json;
1414

15-
std::shared_ptr<toolcall::handler> toolcall::create_handler(const toolcall::params & params) {
16-
std::shared_ptr<toolcall::handler> handler;
15+
std::shared_ptr<toolcall::client> toolcall::create_client(const toolcall::params & params) {
16+
std::shared_ptr<toolcall::client> client;
1717

1818
auto tools = params.tools();
1919
auto choice = params.choice();
2020
if (params) {
2121
if (params.has_uri()) {
2222
#ifdef LLAMA_USE_CURL
23-
handler.reset(new toolcall::handler(
23+
client.reset(new toolcall::client(
2424
std::make_unique<toolcall::mcp_impl>(tools, choice)));
2525
#endif
2626
} else {
27-
handler.reset(new toolcall::handler(
27+
client.reset(new toolcall::client(
2828
std::make_unique<toolcall::loopback_impl>(tools, choice)));
2929
}
3030
}
31-
return handler;
31+
return client;
3232
}
3333

34-
std::string toolcall::handler::tool_list() {
34+
std::string toolcall::client::tool_list() {
3535
return impl_->tool_list();
3636
}
3737

38-
bool toolcall::handler::tool_list_dirty() const {
38+
bool toolcall::client::tool_list_dirty() const {
3939
return impl_->tool_list_dirty();
4040
}
4141

42-
toolcall::result_set toolcall::handler::call(const std::string & request) {
42+
toolcall::result_set toolcall::client::call(const std::string & request) {
4343
return impl_->call(request);
4444
}
4545

46-
const std::string & toolcall::handler::tool_choice() const {
46+
const std::string & toolcall::client::tool_choice() const {
4747
return impl_->tool_choice();
4848
}
4949

50-
void toolcall::handler::initialize() {
50+
void toolcall::client::initialize() {
5151
impl_->initialize();
5252
}
5353

5454
#ifdef LLAMA_USE_CURL
5555
toolcall::mcp_impl::mcp_impl(std::string server_uri, std::string tool_choice)
56-
: handler_impl(tool_choice),
56+
: client_impl(tool_choice),
5757
transport_(new mcp_sse_transport(server_uri)),
5858
tools_("[]"),
5959
tools_mutex_(),
@@ -63,7 +63,7 @@ toolcall::mcp_impl::mcp_impl(std::string server_uri, std::string tool_choice)
6363
}
6464
#else
6565
toolcall::mcp_impl::mcp_impl(std::string /*server_uri*/, std::string tool_choice)
66-
: handler_impl(tool_choice),
66+
: client_impl(tool_choice),
6767
transport_(nullptr),
6868
tools_("[]"),
6969
tools_mutex_(),
@@ -74,7 +74,7 @@ toolcall::mcp_impl::mcp_impl(std::string /*server_uri*/, std::string tool_choice
7474
#endif
7575

7676
toolcall::mcp_impl::mcp_impl(std::vector<std::string> argv, std::string tool_choice)
77-
: handler_impl(tool_choice),
77+
: client_impl(tool_choice),
7878
transport_(new mcp_stdio_transport(argv))
7979
{
8080
}

toolcall/toolcall-handler.h renamed to toolcall/toolcall-client.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ namespace toolcall
2020

2121
using result_set = std::vector<result>;
2222

23-
class handler_impl;
24-
class handler {
23+
class client_impl;
24+
class client {
2525
public:
26-
using ptr = std::shared_ptr<handler>;
26+
using ptr = std::shared_ptr<client>;
2727

28-
handler(std::unique_ptr<handler_impl> impl) : impl_(std::move(impl)) {}
28+
client(std::unique_ptr<client_impl> impl) : impl_(std::move(impl)) {}
2929

3030
result_set call(const std::string & request);
3131

@@ -37,17 +37,17 @@ namespace toolcall
3737
void initialize();
3838

3939
private:
40-
std::unique_ptr<handler_impl> impl_;
40+
std::unique_ptr<client_impl> impl_;
4141
};
4242

43-
std::shared_ptr<toolcall::handler> create_handler(const toolcall::params & params);
43+
std::shared_ptr<toolcall::client> create_client(const toolcall::params & params);
4444

45-
class handler_impl {
45+
class client_impl {
4646
public:
47-
handler_impl(std::string tool_choice)
47+
client_impl(std::string tool_choice)
4848
: tool_choice_(std::move(tool_choice)), tool_list_dirty_(true) {}
4949

50-
virtual ~handler_impl() = default;
50+
virtual ~client_impl() = default;
5151

5252
virtual std::string tool_list() = 0;
5353

@@ -66,10 +66,10 @@ namespace toolcall
6666
bool tool_list_dirty_;
6767
};
6868

69-
class loopback_impl : public handler_impl {
69+
class loopback_impl : public client_impl {
7070
public:
7171
loopback_impl(std::string tools, std::string tool_choice)
72-
: handler_impl(tool_choice), tools_(std::move(tools)) {}
72+
: client_impl(tool_choice), tools_(std::move(tools)) {}
7373

7474
virtual std::string tool_list() override {
7575
tool_list_dirty_ = false;
@@ -87,7 +87,7 @@ namespace toolcall
8787
};
8888

8989
class mcp_transport;
90-
class mcp_impl : public handler_impl {
90+
class mcp_impl : public client_impl {
9191
public:
9292
mcp_impl(std::string server_uri, std::string tool_choice);
9393
mcp_impl(std::vector<std::string> argv, std::string tool_choice);

0 commit comments

Comments
 (0)