- 建置工具:mcpp — 工具鏈與相依
(如
tinyhttps)自動解析 - 也可以在 xmake 專案中使用,見使用 xmake 整合
mcpp new myagent --template llmapi
cd myagent
mcpp run列出函式庫提供的模板:
mcpp new --list-templates llmapimcpp add llmapi或在 mcpp.toml 中宣告:
[dependencies.mcpplibs]
llmapi = "0.2.8"git clone https://github.com/mcpplibs/llmapi.git
cd llmapi
mcpp buildimport mcpplibs.llmapi;
import std;
int main() {
using namespace mcpplibs::llmapi;
auto client = Client(Config{
.apiKey = std::getenv("OPENAI_API_KEY"),
.model = "gpt-4o-mini",
});
client.system("You are a helpful assistant.");
auto resp = client.chat("請用一句話介紹現代 C++。");
std::cout << resp.text() << '\n';
}OpenAI:
auto client = Client(Config{
.apiKey = std::getenv("OPENAI_API_KEY"),
.model = "gpt-4o-mini",
});Anthropic:
auto client = Client(AnthropicConfig{
.apiKey = std::getenv("ANTHROPIC_API_KEY"),
.model = "claude-sonnet-4-20250514",
});相容端點:
auto client = Client(Config{
.apiKey = std::getenv("DEEPSEEK_API_KEY"),
.baseUrl = std::string(URL::DeepSeek),
.model = "deepseek-chat",
});