Skip to content

Commit 075e50d

Browse files
committed
Add Chinese README and docs
1 parent 94fad17 commit 075e50d

14 files changed

+784
-93
lines changed

README.zh.hant.md

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,96 @@
11
# llmapi
22

3-
> Modern C++ LLM API client with openai-compatible support
3+
> 使用 C++23 模組建構的現代 LLM 客戶端
44
55
[![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
66
[![Module](https://img.shields.io/badge/module-ok-green.svg)](https://en.cppreference.com/w/cpp/language/modules)
77
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
8-
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI_API-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)
8+
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)
99

1010
| [English](README.md) - [简体中文](README.zh.md) - 繁體中文 |
1111
|:---:|
12-
| [完整文件](docs/) - [C++ API](docs/cpp-api.md) - [C API](docs/c-api.md) - [範例](docs/examples.md) |
12+
| [中文文件](docs/README.zh.hant.md) - [C++ API](docs/cpp-api.zh.hant.md) - [範例](docs/examples.zh.hant.md) |
1313

14-
簡潔、型別安全的 LLM API 客戶端,使用 C++23 模組。流式介面設計,零成本抽象。支援 OpenAI、Poe、DeepSeek 及相容端點
14+
`llmapi` 提供型別化的 `Client<Provider>` API,涵蓋聊天、串流輸出、embeddings、工具呼叫與對話持久化。預設別名 `Config` 對應 OpenAI 風格設定,常見情況下不需要顯式寫出 `openai::OpenAI(...)`
1515

16-
## 特性
16+
## 特性
1717

18-
- **C++23 模組** - `import mcpplibs.llmapi`
19-
- **自動儲存歷史** - 對話歷史自動管理
20-
- **型別安全串流** - 概念約束的回呼函式
21-
- **流式介面** - 可鏈式呼叫的方法
22-
- **提供商無關** - OpenAI、Poe 及相容端點
18+
- C++23 模組:`import mcpplibs.llmapi`
19+
- 強型別訊息、工具與回應結構
20+
- 同步、非同步、串流聊天介面
21+
- OpenAI Provider 支援 embeddings
22+
- 支援儲存 / 載入對話歷史
23+
- 可透過 `baseUrl` 存取 OpenAI 相容端點
2324

2425
## 快速開始
2526

26-
2727
```cpp
28-
import std;
2928
import mcpplibs.llmapi;
29+
import std;
3030

3131
int main() {
32-
using namespace mcpplibs;
33-
34-
llmapi::Client client(std::getenv("OPENAI_API_KEY"), llmapi::URL::Poe);
35-
36-
client.model("gpt-5")
37-
.system("You are a helpful assistant.")
38-
.user("In one sentence, introduce modern C++. 並給出中文翻譯")
39-
.request([](std::string_view chunk) {
40-
std::print("{}", chunk);
41-
std::cout.flush();
42-
});
32+
using namespace mcpplibs::llmapi;
33+
34+
auto apiKey = std::getenv("OPENAI_API_KEY");
35+
if (!apiKey) {
36+
std::cerr << "OPENAI_API_KEY not set\n";
37+
return 1;
38+
}
4339

40+
auto client = Client(Config{
41+
.apiKey = apiKey,
42+
.model = "gpt-4o-mini",
43+
});
44+
45+
client.system("You are a concise assistant.");
46+
auto resp = client.chat("用兩句話解釋 C++23 模組的價值。");
47+
48+
std::cout << resp.text() << '\n';
4449
return 0;
4550
}
4651
```
4752

48-
### 模型 / 提供商
53+
## Provider
54+
55+
- `Config``openai::Config` 的匯出別名,預設走 OpenAI 風格
56+
- `openai::OpenAI`:OpenAI 聊天、串流、工具呼叫、embeddings
57+
- `AnthropicConfig` / `anthropic::Anthropic`:Anthropic 聊天與串流
58+
59+
相容端點範例:
4960

5061
```cpp
51-
llmapi::Client client(apiKey, llmapi::URL::OpenAI); // OpenAI
52-
llmapi::Client client(apiKey, llmapi::URL::Poe); // Poe
53-
llmapi::Client client(apiKey, llmapi::URL::DeepSeek); // Deepseek
54-
llmapi::Client client(apiKey, "https://custom.com"); // 自訂
62+
auto client = Client(Config{
63+
.apiKey = std::getenv("DEEPSEEK_API_KEY"),
64+
.baseUrl = std::string(URL::DeepSeek),
65+
.model = "deepseek-chat",
66+
});
5567
```
5668

57-
## 🛠️ 建置
69+
## 建置與執行
5870

5971
```bash
60-
xmake # 建置
61-
xmake run basic # 執行範例(需先設定 OPENAI_API_KEY)
72+
xmake
73+
xmake run hello_mcpp
74+
xmake run basic
75+
xmake run chat
6276
```
6377

64-
## 📦 在建置工具中使用
65-
66-
### xmake
78+
## 套件管理使用
6779

6880
```lua
69-
-- 0 - 新增 mcpplibs 索引倉庫
70-
add_repositories("mcpplibs-index https://github.com/mcpplibs/llmapi.git")
71-
72-
-- 1 - 新增需要的函式庫和版本
81+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
7382
add_requires("llmapi 0.0.2")
74-
```
75-
76-
> More: [mcpplibs-index](https://github.com/mcpplibs/mcpplibs-index)
7783

78-
### cmake
79-
80-
```
81-
todo...
84+
target("demo")
85+
set_kind("binary")
86+
set_languages("c++23")
87+
set_policy("build.c++.modules", true)
88+
add_files("src/*.cpp")
89+
add_packages("llmapi")
8290
```
8391

84-
## 📄 授權條款
92+
更多內容見 [docs/getting-started.zh.hant.md](docs/getting-started.zh.hant.md)[docs/providers.zh.hant.md](docs/providers.zh.hant.md)
93+
94+
## 授權
8595

86-
Apache-2.0 - 詳見 [LICENSE](LICENSE)
96+
Apache-2.0詳見 [LICENSE](LICENSE)

README.zh.md

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,96 @@
11
# llmapi
22

3-
> Modern C++ LLM API client with openai-compatible support
3+
> 使用 C++23 模块构建的现代 LLM 客户端
44
55
[![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
66
[![Module](https://img.shields.io/badge/module-ok-green.svg)](https://en.cppreference.com/w/cpp/language/modules)
77
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
8-
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI_API-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)
8+
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)
99

1010
| [English](README.md) - 简体中文 - [繁體中文](README.zh.hant.md) |
1111
|:---:|
12-
| [完整文档](docs/) - [C++ API](docs/cpp-api.md) - [C API](docs/c-api.md) - [示例](docs/examples.md) |
12+
| [中文文档](docs/README.zh.md) - [C++ API](docs/cpp-api.zh.md) - [示例](docs/examples.zh.md) |
1313

14-
简洁、类型安全的 LLM API 客户端,使用 C++23 模块。流式接口设计,零成本抽象。支持 OpenAI、Poe、DeepSeek 及兼容端点
14+
`llmapi` 提供类型化的 `Client<Provider>` API,覆盖聊天、流式输出、嵌入、工具调用与对话持久化。默认别名 `Config` 对应 OpenAI 风格配置,常见场景不需要显式写 `openai::OpenAI(...)`
1515

16-
## 特性
16+
## 特性
1717

18-
- **C++23 模块** - `import mcpplibs.llmapi`
19-
- **自动保存历史** - 对话历史自动管理
20-
- **类型安全流式** - 概念约束的回调函数
21-
- **流式接口** - 可链式调用的方法
22-
- **提供商无关** - OpenAI、Poe 及兼容端点
18+
- C++23 模块:`import mcpplibs.llmapi`
19+
- 强类型消息、工具与响应结构
20+
- 同步、异步、流式聊天接口
21+
- OpenAI Provider 支持 embeddings
22+
- 支持保存 / 加载对话历史
23+
- 可通过 `baseUrl` 访问 OpenAI 兼容端点
2324

2425
## 快速开始
2526

2627
```cpp
27-
import std;
2828
import mcpplibs.llmapi;
29+
import std;
2930

3031
int main() {
31-
using namespace mcpplibs;
32-
33-
llmapi::Client client(std::getenv("OPENAI_API_KEY"), llmapi::URL::Poe);
34-
35-
client.model("gpt-5")
36-
.system("You are a helpful assistant.")
37-
.user("In one sentence, introduce modern C++. 并给出中文翻译")
38-
.request([](std::string_view chunk) {
39-
std::print("{}", chunk);
40-
std::cout.flush();
41-
});
32+
using namespace mcpplibs::llmapi;
33+
34+
auto apiKey = std::getenv("OPENAI_API_KEY");
35+
if (!apiKey) {
36+
std::cerr << "OPENAI_API_KEY not set\n";
37+
return 1;
38+
}
39+
40+
auto client = Client(Config{
41+
.apiKey = apiKey,
42+
.model = "gpt-4o-mini",
43+
});
4244

45+
client.system("You are a concise assistant.");
46+
auto resp = client.chat("用两句话解释 C++23 模块的价值。");
47+
48+
std::cout << resp.text() << '\n';
4349
return 0;
4450
}
4551
```
4652

47-
### 模型 / 提供商
53+
## Provider
54+
55+
- `Config``openai::Config` 的导出别名,默认走 OpenAI 风格
56+
- `openai::OpenAI`:OpenAI 聊天、流式、工具调用、embeddings
57+
- `AnthropicConfig` / `anthropic::Anthropic`:Anthropic 聊天与流式
58+
59+
兼容端点示例:
4860

4961
```cpp
50-
llmapi::Client client(apiKey, llmapi::URL::OpenAI); // OpenAI
51-
llmapi::Client client(apiKey, llmapi::URL::Poe); // Poe
52-
llmapi::Client client(apiKey, llmapi::URL::DeepSeek); // Deepseek
53-
llmapi::Client client(apiKey, "https://custom.com"); // 自定义
62+
auto client = Client(Config{
63+
.apiKey = std::getenv("DEEPSEEK_API_KEY"),
64+
.baseUrl = std::string(URL::DeepSeek),
65+
.model = "deepseek-chat",
66+
});
5467
```
5568

56-
## 构建
69+
## 构建与运行
5770

5871
```bash
59-
xmake # 构建
60-
xmake run basic # 运行示例(需要先配置 OPENAI_API_KEY)
72+
xmake
73+
xmake run hello_mcpp
74+
xmake run basic
75+
xmake run chat
6176
```
6277

63-
## 在构建工具中使用
64-
65-
### xmake
78+
## 包管理使用
6679

6780
```lua
68-
-- 0 - 添加 mcpplibs 索引仓库
69-
add_repositories("mcpplibs-index https://github.com/mcpplibs/llmapi.git")
70-
71-
-- 1 - 添加需要的库和版本
81+
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
7282
add_requires("llmapi 0.0.2")
73-
```
74-
75-
> More: [mcpplibs-index](https://github.com/mcpplibs/mcpplibs-index)
7683

77-
### cmake
78-
79-
```
80-
todo...
84+
target("demo")
85+
set_kind("binary")
86+
set_languages("c++23")
87+
set_policy("build.c++.modules", true)
88+
add_files("src/*.cpp")
89+
add_packages("llmapi")
8190
```
8291

83-
## 📄 许可证
92+
更多内容见 [docs/getting-started.zh.md](docs/getting-started.zh.md)[docs/providers.zh.md](docs/providers.zh.md)
93+
94+
## 许可证
8495

85-
Apache-2.0 - 详见 [LICENSE](LICENSE)
96+
Apache-2.0详见 [LICENSE](LICENSE)

docs/README.zh.hant.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# llmapi 中文文件
2+
3+
`llmapi` 是一個基於 C++23 模組的 LLM 客戶端函式庫。
4+
5+
## 內容導覽
6+
7+
- [快速開始](getting-started.zh.hant.md)
8+
- [C++ API 參考](cpp-api.zh.hant.md)
9+
- [範例](examples.zh.hant.md)
10+
- [Provider 設定](providers.zh.hant.md)
11+
- [進階用法](advanced.zh.hant.md)
12+
13+
## 核心能力
14+
15+
- `import mcpplibs.llmapi`
16+
- 型別化訊息、工具與回應結構
17+
- Provider 概念約束
18+
- 內建 OpenAI / Anthropic 支援
19+
- OpenAI 相容端點支援
20+
- 對話儲存與還原

docs/README.zh.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# llmapi 中文文档
2+
3+
`llmapi` 是一个基于 C++23 模块的 LLM 客户端库。
4+
5+
## 内容导航
6+
7+
- [快速开始](getting-started.zh.md)
8+
- [C++ API 参考](cpp-api.zh.md)
9+
- [示例](examples.zh.md)
10+
- [Provider 配置](providers.zh.md)
11+
- [高级用法](advanced.zh.md)
12+
13+
## 核心能力
14+
15+
- `import mcpplibs.llmapi`
16+
- 类型化消息、工具和响应结构
17+
- Provider 概念约束
18+
- OpenAI / Anthropic 内置支持
19+
- OpenAI 兼容端点支持
20+
- 对话保存与恢复

docs/advanced.zh.hant.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# 進階用法
2+
3+
## 對話持久化
4+
5+
```cpp
6+
client.chat("記住我偏好簡潔回答。");
7+
client.save_conversation("session.json");
8+
```
9+
10+
## 手動注入訊息
11+
12+
```cpp
13+
client.add_message(Message::system("Translate English to Chinese."));
14+
client.add_message(Message::user("hello"));
15+
client.add_message(Message::assistant("你好"));
16+
```
17+
18+
## 非同步介面
19+
20+
```cpp
21+
auto task = client.chat_async("簡要解釋 coroutine。");
22+
auto resp = task.get();
23+
```
24+
25+
## 工具呼叫流程
26+
27+
```cpp
28+
auto first = client.chat("東京天氣如何?", params);
29+
for (const auto& call : first.tool_calls()) {
30+
client.add_message(Message{
31+
.role = Role::Tool,
32+
.content = std::vector<ContentPart>{
33+
ToolResultContent{
34+
.toolUseId = call.id,
35+
.content = R"({"temperature":"22C","condition":"sunny"})",
36+
},
37+
},
38+
});
39+
}
40+
```

0 commit comments

Comments
 (0)