Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ jobs:
- name: Refresh package index
run: xlings update

- name: Install workspace tools (.xlings.json → mcpp 0.0.13)
- name: Install workspace tools (.xlings.json → mcpp 0.0.53)
run: xlings install -y

- name: Cache mcpp sandbox
uses: actions/cache@v4
with:
path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.13/registry
key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.13
path: ~/.xlings/data/xpkgs/xim-x-mcpp/0.0.53/registry
key: mcpp-sandbox-${{ runner.os }}-mcpp0.0.53

- name: Build with mcpp
run: mcpp build
2 changes: 1 addition & 1 deletion .xlings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"workspace": {
"mcpp": { "linux": "0.0.13" }
"mcpp": { "linux": "0.0.53" }
}
}
117 changes: 58 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
# llmapi

> Modern C++23 LLM client built with modules
> Modern C++23 LLM client built with modules — `import` and chat, OpenAI-compatible, template-ready

[![Release](https://img.shields.io/github/v/release/mcpplibs/llmapi)](https://github.com/mcpplibs/llmapi/releases)
[![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
[![Module](https://img.shields.io/badge/module-ok-green.svg)](https://en.cppreference.com/w/cpp/language/modules)
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)

| English - [简体中文](README.zh.md) - [繁體中文](README.zh.hant.md) |
|:---:|
| [Documentation](docs/README.md) - [English Docs](docs/en/README.md) - [中文文档](docs/zh/README.md) - [繁體中文文件](docs/zh-hant/README.md) |
| [mcpp build tool](https://github.com/mcpp-community/mcpp) · [package index](https://github.com/mcpp-community/mcpp-index) · [Documentation](docs/README.md) · [Issues](https://github.com/mcpplibs/llmapi/issues) |

`llmapi` provides a typed `Client<Provider>` API for chat, streaming, embeddings, tool calls, and conversation persistence. The default config alias `Config` maps to OpenAI-style providers, so the common case does not need an explicit `openai::OpenAI` wrapper.

## Features
## Quick Start (mcpp)

- `import mcpplibs.llmapi` with C++23 modules
- Strongly typed messages, tools, and response structs
- Sync, async, and streaming chat APIs
- Embeddings via the OpenAI provider
- Conversation save/load helpers
- OpenAI-compatible endpoint support through `openai::Config::baseUrl`
```bash
mcpp new myagent --template llmapi && cd myagent
export OPENAI_API_KEY="sk-..."
mcpp run
```

Templates ship with the library and version-track it automatically:

```bash
mcpp new --list-templates llmapi # list available templates
mcpp new mybot --template llmapi:chat # interactive streaming chat CLI
mcpp new mybot --template llmapi:anthropic # Anthropic provider
mcpp new mybot --template llmapi:deepseek # OpenAI-compatible endpoint (DeepSeek)
```

## Quick Start
Or add it to an existing mcpp project:

```bash
mcpp add llmapi
```

```toml
[dependencies.mcpplibs]
llmapi = "0.2.7"
```

```cpp
import mcpplibs.llmapi;
Expand All @@ -33,7 +51,7 @@ int main() {

auto apiKey = std::getenv("OPENAI_API_KEY");
if (!apiKey) {
std::cerr << "OPENAI_API_KEY not set\n";
std::println(stderr, "OPENAI_API_KEY not set");
return 1;
}

Expand All @@ -45,11 +63,30 @@ int main() {
client.system("You are a concise assistant.");
auto resp = client.chat("Explain why C++23 modules are useful in two sentences.");

std::cout << resp.text() << '\n';
std::println("{}", resp.text());
return 0;
}
```

## Features

- `import mcpplibs.llmapi` with C++23 modules
- Strongly typed messages, tools, and response structs
- Sync, async, and streaming chat APIs
- Embeddings via the OpenAI provider
- Conversation save/load helpers
- OpenAI-compatible endpoint support through `openai::Config::baseUrl`
- Project templates: `mcpp new <name> --template llmapi[:<template>]`

## Templates

| Template | Description |
|---|---|
| `openai` (default) | Minimal OpenAI chat — one request, one answer |
| `chat` | Interactive streaming chat CLI (OpenAI) |
| `anthropic` | Anthropic (Claude) chat |
| `deepseek` | OpenAI-compatible endpoint via `baseUrl` (DeepSeek) |

## Providers

- `openai::OpenAI` for OpenAI chat, streaming, embeddings, and OpenAI-compatible endpoints
Expand All @@ -59,65 +96,27 @@ int main() {
Compatible endpoints can reuse the OpenAI provider:

```cpp
auto provider = openai::OpenAI({
auto client = Client(Config{
.apiKey = std::getenv("DEEPSEEK_API_KEY"),
.baseUrl = std::string(URL::DeepSeek),
.model = "deepseek-chat",
});
```

## Build And Run

```bash
xmake
xmake run hello_mcpp
xmake run basic
xmake run chat
```

## Package Usage

```lua
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
add_requires("llmapi 0.1.0")

target("demo")
set_kind("binary")
set_languages("c++23")
set_policy("build.c++.modules", true)
add_files("src/*.cpp")
add_packages("llmapi")
```

See [docs/en/getting-started.md](docs/en/getting-started.md), [docs/en/providers.md](docs/en/providers.md), and [docs/en/README.md](docs/en/README.md) for more setup and readiness detail.

## 使用 mcpp 构建

### 添加依赖

```bash
mcpp add llmapi@0.2.5
```

或在 `mcpp.toml` 中手动添加:

```toml
[dependencies]
llmapi = "0.2.5"
```

### 构建
## Build From Source

```bash
git clone https://github.com/mcpplibs/llmapi.git && cd llmapi
mcpp build
```

### 代码示例
## Documentation

```cpp
import mcpplibs.llmapi;
// ... usage example
```
- [Getting Started](docs/en/getting-started.md)
- [Providers](docs/en/providers.md)
- [C++ API Guide](docs/en/cpp-api.md)
- [Using llmapi with xmake](docs/en/xmake.md)
- [Docs index](docs/README.md)

## License

Expand Down
89 changes: 58 additions & 31 deletions README.zh.hant.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
# llmapi

> 使用 C++23 模組建構的現代 LLM 客戶端
> 使用 C++23 模組建構的現代 LLM 客戶端 — `import` 即聊天 · OpenAI 相容 · 模板開箱即用

[![Release](https://img.shields.io/github/v/release/mcpplibs/llmapi)](https://github.com/mcpplibs/llmapi/releases)
[![C++23](https://img.shields.io/badge/C%2B%2B-23-blue.svg)](https://en.cppreference.com/w/cpp/23)
[![Module](https://img.shields.io/badge/module-ok-green.svg)](https://en.cppreference.com/w/cpp/language/modules)
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](LICENSE)
[![OpenAI Compatible](https://img.shields.io/badge/OpenAI-Compatible-green.svg)](https://platform.openai.com/docs/api-reference)

| [English](README.md) - [简体中文](README.zh.md) - 繁體中文 |
|:---:|
| [文件導覽](docs/README.md) - [繁體中文文件](docs/zh-hant/README.md) - [English Docs](docs/en/README.md) - [简体中文文档](docs/zh/README.md) |
| [mcpp 建置工具](https://github.com/mcpp-community/mcpp) · [套件索引 mcpp-index](https://github.com/mcpp-community/mcpp-index) · [文件導覽](docs/README.md) · [Issues](https://github.com/mcpplibs/llmapi/issues) |

`llmapi` 提供型別化的 `Client<Provider>` API,涵蓋聊天、串流輸出、embeddings、工具呼叫與對話持久化。預設別名 `Config` 對應 OpenAI 風格設定,常見情況下不需要顯式寫出 `openai::OpenAI(...)`。

## 特性
## 快速開始(mcpp)

- C++23 模組:`import mcpplibs.llmapi`
- 強型別訊息、工具與回應結構
- 同步、非同步、串流聊天介面
- OpenAI Provider 支援 embeddings
- 支援儲存 / 載入對話歷史
- 可透過 `baseUrl` 存取 OpenAI 相容端點
```bash
mcpp new myagent --template llmapi && cd myagent
export OPENAI_API_KEY="sk-..."
mcpp run
```

模板隨函式庫發佈、版本自動對齊:

```bash
mcpp new --list-templates llmapi # 列出函式庫提供的模板
mcpp new mybot --template llmapi:chat # 互動式串流聊天 CLI
mcpp new mybot --template llmapi:anthropic # Anthropic Provider
mcpp new mybot --template llmapi:deepseek # OpenAI 相容端點(DeepSeek)
```

或在既有 mcpp 專案中接入:

```bash
mcpp add llmapi
```

## 快速開始
```toml
[dependencies.mcpplibs]
llmapi = "0.2.7"
```

```cpp
import mcpplibs.llmapi;
Expand All @@ -33,7 +51,7 @@ int main() {

auto apiKey = std::getenv("OPENAI_API_KEY");
if (!apiKey) {
std::cerr << "OPENAI_API_KEY not set\n";
std::println(stderr, "OPENAI_API_KEY not set");
return 1;
}

Expand All @@ -45,11 +63,30 @@ int main() {
client.system("You are a concise assistant.");
auto resp = client.chat("用兩句話解釋 C++23 模組的價值。");

std::cout << resp.text() << '\n';
std::println("{}", resp.text());
return 0;
}
```

## 特性

- C++23 模組:`import mcpplibs.llmapi`
- 強型別訊息、工具與回應結構
- 同步、非同步、串流聊天介面
- OpenAI Provider 支援 embeddings
- 支援儲存 / 載入對話歷史
- 可透過 `baseUrl` 存取 OpenAI 相容端點
- 專案模板:`mcpp new <name> --template llmapi[:<template>]`

## 模板

| 模板 | 說明 |
|---|---|
| `openai`(預設) | 最小 OpenAI 聊天 — 一問一答 |
| `chat` | 互動式串流聊天 CLI(OpenAI) |
| `anthropic` | Anthropic(Claude)聊天 |
| `deepseek` | 透過 `baseUrl` 走 OpenAI 相容端點(DeepSeek) |

## Provider

- `Config`:`openai::Config` 的匯出別名,預設走 OpenAI 風格
Expand All @@ -66,30 +103,20 @@ auto client = Client(Config{
});
```

## 建置與執行
## 原始碼建置

```bash
xmake
xmake run hello_mcpp
xmake run basic
xmake run chat
git clone https://github.com/mcpplibs/llmapi.git && cd llmapi
mcpp build
```

## 套件管理使用

```lua
add_repositories("mcpplibs-index https://github.com/mcpplibs/mcpplibs-index.git")
add_requires("llmapi 0.1.0")

target("demo")
set_kind("binary")
set_languages("c++23")
set_policy("build.c++.modules", true)
add_files("src/*.cpp")
add_packages("llmapi")
```
## 文件

更多內容見 [docs/zh-hant/getting-started.md](docs/zh-hant/getting-started.md)、[docs/zh-hant/providers.md](docs/zh-hant/providers.md) 與 [docs/zh-hant/README.md](docs/zh-hant/README.md)。
- [快速上手](docs/zh-hant/getting-started.md)
- [Provider 設定](docs/zh-hant/providers.md)
- [C++ API 指南](docs/zh-hant/cpp-api.md)
- [使用 xmake 整合 llmapi](docs/zh-hant/xmake.md)
- [文件導覽](docs/README.md)

## 授權

Expand Down
Loading
Loading