Skip to content

Commit 861c96b

Browse files
authored
Refresh README, examples, and project docs (#6)
* Refresh README, examples, and project docs * Add default OpenAI Client config shortcut
1 parent 4ffd87a commit 861c96b

File tree

16 files changed

+592
-838
lines changed

16 files changed

+592
-838
lines changed

README.md

Lines changed: 56 additions & 45 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+
> Modern C++23 LLM client built with modules
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.zh.md) - [繁體中文](README.zh.hant.md) |
1111
|:---:|
12-
| [Documentation](docs/) - [C++ API](docs/cpp-api.md) - [C API](docs/c-api.md) - [Examples](docs/examples.md) |
12+
| [Documentation](docs/) - [C++ API](docs/cpp-api.md) - [Examples](docs/examples.md) |
1313

14-
Clean, type-safe LLM API client using C++23 modules. Fluent interface with zero-cost abstractions. Works with OpenAI, Poe, DeepSeek and compatible endpoints.
14+
`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.
1515

16-
## Features
16+
## Features
1717

18-
- **C++23 Modules** - `import mcpplibs.llmapi`
19-
- **Auto-Save History** - Conversation history managed automatically
20-
- **Type-Safe Streaming** - Concept-constrained callbacks
21-
- **Fluent Interface** - Chainable methods
22-
- **Provider Agnostic** - OpenAI, Poe, and compatible endpoints
18+
- `import mcpplibs.llmapi` with C++23 modules
19+
- Strongly typed messages, tools, and response structs
20+
- Sync, async, and streaming chat APIs
21+
- Embeddings via the OpenAI provider
22+
- Conversation save/load helpers
23+
- OpenAI-compatible endpoint support through `openai::Config::baseUrl`
2324

2425
## Quick Start
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("Explain why C++23 modules are useful in two sentences.");
47+
48+
std::cout << resp.text() << '\n';
4349
return 0;
4450
}
4551
```
4652

47-
### Models / Providers
53+
## Providers
54+
55+
- `openai::OpenAI` for OpenAI chat, streaming, embeddings, and OpenAI-compatible endpoints
56+
- `anthropic::Anthropic` for Anthropic chat and streaming
57+
- `Config` as a convenient alias for `openai::Config`
58+
59+
Compatible endpoints can reuse the OpenAI provider:
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"); // Custom
62+
auto provider = openai::OpenAI({
63+
.apiKey = std::getenv("DEEPSEEK_API_KEY"),
64+
.baseUrl = std::string(URL::DeepSeek),
65+
.model = "deepseek-chat",
66+
});
5467
```
5568

56-
## Building
69+
## Build And Run
5770

5871
```bash
59-
xmake # Build
60-
xmake run basic # Run example(after cofig OPENAI_API_KEY)
72+
xmake
73+
xmake run hello_mcpp
74+
xmake run basic
75+
xmake run chat
6176
```
6277

63-
## Use in Build Tools
64-
65-
### xmake
78+
## Package Usage
6679

6780
```lua
68-
-- 0 - Add mcpplibs's index repos
69-
add_repositories("mcpplibs-index https://github.com/mcpplibs/llmapi.git")
70-
71-
-- 1 - Add the libraries and versions you need
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-
## 📄 License
92+
See [docs/getting-started.md](docs/getting-started.md) and [docs/providers.md](docs/providers.md) for more setup detail.
93+
94+
## License
8495

8596
Apache-2.0 - see [LICENSE](LICENSE)

docs/README.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
# llmapi Documentation
22

3-
Complete documentation for the llmapi library - a modern C++ LLM API client.
3+
Current documentation for the `llmapi` C++23 module library.
44

5-
## 📚 Contents
5+
## Contents
66

7-
- [Getting Started](getting-started.md) - Installation and first steps
8-
- [C++ API Guide](cpp-api.md) - Complete C++ API reference
9-
- [Examples](examples.md) - Code examples and use cases
10-
- [Providers](providers.md) - Supported LLM providers
11-
- [Advanced Usage](advanced.md) - Advanced features and patterns
7+
- [Getting Started](getting-started.md) - install, build, and first request
8+
- [C++ API Guide](cpp-api.md) - types, providers, and `Client<P>`
9+
- [Examples](examples.md) - chat, streaming, embeddings, and tool flows
10+
- [Providers](providers.md) - OpenAI, Anthropic, and compatible endpoints
11+
- [Advanced Usage](advanced.md) - persistence, async calls, and custom configuration
1212

13-
## Quick Links
13+
## What The Library Provides
1414

15-
**For C++ Developers:**
16-
- Start with [Getting Started](getting-started.md)
17-
- See [C++ API Guide](cpp-api.md) for full API reference
18-
- Check [Examples](examples.md) for common patterns
19-
20-
## Features Overview
21-
22-
- **C++23 Modules** - Modern module system
23-
- **Auto-Save History** - Automatic conversation management
24-
- **Type-Safe Streaming** - Concept-constrained callbacks
25-
- **Fluent Interface** - Chainable API design
26-
- **Provider Agnostic** - OpenAI, Poe, and custom endpoints
15+
- C++23 modules via `import mcpplibs.llmapi`
16+
- Typed chat messages and multimodal content structs
17+
- Provider concepts for sync, async, streaming, and embeddings
18+
- Built-in OpenAI and Anthropic providers
19+
- OpenAI-compatible endpoint support through configurable base URLs
20+
- Conversation save/load helpers for local session persistence
2721

2822
## License
2923

0 commit comments

Comments
 (0)