Show HN: 现代 C++20 AI SDK (GPT‑4o, Claude 3.5, 工具调用)
1 分•作者: cauchyk•6 个月前
大家好,
我正在为 ClickHouse 原生客户端开发新功能,希望实现与 JavaScript 和 Python 类似的“只需调用模型”的便捷性。现代 C++ 还没有这样的功能,所以我写了一个。
ai-sdk-cpp (Apache-2.0) 为您提供:
- 通过单一 C++20 API 统一调用 OpenAI (GPT-4o) 和 Anthropic (Claude 3.5)。
- 流式传输、多轮对话、错误处理——全部使用 std::optional/std::variant,没有宏。
- 工具调用(函数调用),让模型能够调用真实的 API;同步或异步,并行运行。
难点在于:C++ 仍然缺乏真正的反射机制,因此将普通函数映射到 JSON 模式不像 TypeScript 装饰器那样自动化。我希望大家能关注这部分。请尝试这些示例,告诉我哪里感觉不顺畅。这个项目受到了 Vercel 的 AI SDK [1] 和 litellm [2] 的启发。
代码库在这里:<a href="https://github.com/ClickHouse/ai-sdk-cpp">https://github.com/ClickHouse/ai-sdk-cpp</a>,欢迎反馈!
[1] <a href="https://github.com/vercel/ai">https://github.com/vercel/ai</a>
[2] <a href="https://github.com/BerriAI/litellm">https://github.com/BerriAI/litellm</a>
查看原文
Hi all,<p>I’m hacking on new features for the ClickHouse native client and wanted the same “just call the model” ergonomics JavaScript and Python now enjoy. It didn’t exist for modern C++, so I wrote one.<p>ai‑sdk‑cpp (Apache‑2.0) gives you:<p>- Unified calls to OpenAI (GPT‑4o) and Anthropic (Claude 3.5) with a single C++20 API.
- Streaming, multi‑turn chat, error handling—all std::optional/std::variant, no macros.
- Tool calling (function‑calling) so the model can hit real APIs; sync or async, runs in parallel.<p>The tricky bit: C++ still lacks real reflection, so mapping plain functions → JSON schemas isn’t as automatic as, say, TypeScript decorators. I’d love fresh eyes on that part. Try the examples and tell me where it feels clunky. This is inspired by Vercel's AI SDK [1], and litellm [2].<p>Repo live here: <a href="https://github.com/ClickHouse/ai-sdk-cpp">https://github.com/ClickHouse/ai-sdk-cpp</a>, feedback welcome!<p>[1] <a href="https://github.com/vercel/ai">https://github.com/vercel/ai</a>
[2] <a href="https://github.com/BerriAI/litellm">https://github.com/BerriAI/litellm</a>