46 lines
1.6 KiB
C++
46 lines
1.6 KiB
C++
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
#include <sstream>
|
|
|
|
namespace Tools {
|
|
|
|
// Super-lightweight JSON helpers (NOT robust; only for stub/testing).
|
|
inline std::string json_kv(const std::string& k, const std::string& v) {
|
|
std::ostringstream os; os << "\"" << k << "\"\: \"" << v << "\""; return os.str();
|
|
}
|
|
inline std::string json_kv_num(const std::string& k, double v) {
|
|
std::ostringstream os; os << "\"" << k << "\"\: " << v; return os.str();
|
|
}
|
|
inline std::string json_arr(const std::vector<std::string>& items) {
|
|
std::ostringstream os; os << "[";
|
|
for (size_t i=0;i<items.size();++i){ if(i) os<<","; os<<items[i]; }
|
|
os << "]"; return os.str();
|
|
}
|
|
|
|
// `echo` tool: echoes back the input
|
|
inline std::string echo_response(const std::string& input) {
|
|
return input;
|
|
}
|
|
|
|
// `ping` tool: echoes { ok: true, tools: [...] }
|
|
inline std::string ping_response(const std::vector<std::string>& toolNames) {
|
|
std::vector<std::string> quoted; quoted.reserve(toolNames.size());
|
|
for (auto &t: toolNames) { std::ostringstream q; q << "\"" << t << "\""; quoted.push_back(q.str()); }
|
|
std::ostringstream os;
|
|
os << "{" << json_kv("status", "ok") << ", "
|
|
<< "\"tools\": " << json_arr(quoted) << "}";
|
|
return os.str();
|
|
}
|
|
|
|
// `embed_text` stub: returns zero vectors of dimension 8 for each input text
|
|
inline std::string embed_text_stub(size_t n) {
|
|
std::ostringstream os;
|
|
os << "{\"model\":\"stub-embed-8d\",\"vectors\":[";
|
|
for (size_t i=0;i<n;++i){ if(i) os<<","; os<<"[0,0,0,0,0,0,0,0]"; }
|
|
os << "]}";
|
|
return os.str();
|
|
}
|
|
|
|
} // namespace Tools
|