展示HN:一个现代的C++20 AI软件开发工具包(GPT-4o,Claude 3.5,工具调用)

1作者: cauchyk6 天前原帖
大家好, 我正在为 ClickHouse 原生客户端开发新功能,希望能够实现 JavaScript 和 Python 目前享有的“只需调用模型”的便捷体验。现代 C++ 中并没有这样的功能,所以我自己写了一个。 ai-sdk-cpp(Apache-2.0)为您提供: - 统一调用 OpenAI(GPT-4o)和 Anthropic(Claude 3.5)的单一 C++20 API。 - 支持流式传输、多轮对话、错误处理——全部使用 std::optional/std::variant,无需宏定义。 - 工具调用(函数调用),使模型能够访问真实的 API;支持同步或异步,能够并行运行。 其中的难点在于:C++ 仍然缺乏真正的反射功能,因此将普通函数映射到 JSON 模式并不像 TypeScript 装饰器那样自动化。我希望能得到大家的新鲜视角。请尝试这些示例,并告诉我哪些地方感觉不够顺畅。这一切的灵感来源于 Vercel 的 AI SDK 和 litellm。 代码库地址在这里:[https://github.com/ClickHouse/ai-sdk-cpp](https://github.com/ClickHouse/ai-sdk-cpp),欢迎反馈! [1] [https://github.com/vercel/ai](https://github.com/vercel/ai) [2] [https://github.com/BerriAI/litellm](https://github.com/BerriAI/litellm)
查看原文
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&#x2F;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&#x27;s AI SDK [1], and litellm [2].<p>Repo live here: <a href="https:&#x2F;&#x2F;github.com&#x2F;ClickHouse&#x2F;ai-sdk-cpp">https:&#x2F;&#x2F;github.com&#x2F;ClickHouse&#x2F;ai-sdk-cpp</a>, feedback welcome!<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;vercel&#x2F;ai">https:&#x2F;&#x2F;github.com&#x2F;vercel&#x2F;ai</a> [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;BerriAI&#x2F;litellm">https:&#x2F;&#x2F;github.com&#x2F;BerriAI&#x2F;litellm</a>