Skip to content

Commit 9af089d

Browse files
committed
add llmapi
1 parent 33c96a5 commit 9af089d

File tree

6 files changed

+104
-3
lines changed

6 files changed

+104
-3
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,26 @@ mcpplibs index
99
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
1010

1111
-- 1 - Add the libraries and versions you need
12-
add_requires("mcpplibs-index@templates 0.0.1")
12+
add_requires("templates 0.0.1")
13+
--add_requires("mcpplibs-index@templates 0.0.1")
1314

1415
target("templates_test")
1516
set_kind("binary")
1617
set_languages("c++23")
1718
add_files("main.cpp")
1819
-- 2 - Use it
19-
add_packages("mcpplibs-index@templates")
20+
add_packages("templates")
2021
set_policy("build.c++.modules", true)
21-
```
22+
```
23+
24+
## List
25+
26+
| name | introduce | demo | other |
27+
| --- | --- | --- | --- |
28+
| [templates](https://github.com/mcpplibs/templates) | A template of modern C++ `modules` libraries | [templates_test](tests/t/templates) | |
29+
| [llmapi](https://github.com/mcpplibs/llmapi) | Modern C++ LLM API client with openai-compatible support | [llmapi_test](tests/l/llmapi) | |
30+
31+
## Other
32+
33+
- [mcpplibs](https://github.com/mcpplibs)
34+
- [mcpp-community](https://github.com/mcpp-community)

packages/l/llmapi/xmake.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package("llmapi")
2+
3+
--set_kind("library", {headeronly = true})
4+
5+
set_homepage("https://github.com/mcpplibs/llmapi")
6+
set_description("Modern C++ LLM API client with openai-compatible support")
7+
set_license("Apache-2.0")
8+
9+
add_urls(
10+
-- https://github.com/mcpplibs/llmapi/archive/refs/tags/0.0.1.tar.gz
11+
"https://github.com/mcpplibs/llmapi/archive/refs/tags/$(version).tar.gz",
12+
"https://github.com/mcpplibs/llmapi.git"
13+
)
14+
15+
add_versions("0.0.1", "174f86d3afdf48a57ad1cc9688718d1f1100a78a7e56686c823c573c3ccf99f4")
16+
17+
add_configs("capi", {description = "Link with llmapi_c (C API) by default", default = false, type = "boolean"})
18+
19+
add_includedirs("include")
20+
add_deps("libcurl 8.11.0")
21+
22+
on_load(function (package)
23+
if package:config("capi") then
24+
package:add("links", "llmapi_c")
25+
end
26+
package:add("links", "llmapi")
27+
end)
28+
29+
on_install(function (package)
30+
import("package.tools.xmake").install(package)
31+
end)

tests/l/llmapi/capi/main.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
4+
#include "llmapi.h"
5+
6+
void stream_print(const char* s, size_t len, void* data) {
7+
printf("%.*s", (int)len, s);
8+
fflush(stdout);
9+
}
10+
11+
int main(void) {
12+
llmapi_client_t* c = llmapi_client_create(getenv("OPENAI_API_KEY"), LLMAPI_URL_POE);
13+
14+
c->set_model(c, "gpt-5");
15+
c->add_system_message(c, "You are a helpful assistant.");
16+
c->add_user_message(c, "In one sentence, introduce modern C++. 并给出中文翻译");
17+
c->request_stream(c, stream_print, NULL);
18+
19+
c->destroy(c);
20+
return 0;
21+
}

tests/l/llmapi/capi/xmake.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
2+
3+
add_requires("llmapi 0.0.1", {configs = { capi = true }})
4+
5+
target("llmapi_test_c")
6+
set_kind("binary")
7+
add_files("main.c")
8+
add_packages("llmapi")

tests/l/llmapi/main.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import std;
2+
import mcpplibs.llmapi;
3+
4+
int main() {
5+
using namespace mcpplibs;
6+
7+
llmapi::Client client(std::getenv("OPENAI_API_KEY"), llmapi::URL::Poe);
8+
9+
client.model("gpt-5")
10+
.system("You are a helpful assistant.")
11+
.user("In one sentence, introduce modern C++. 并给出中文翻译")
12+
.request([](std::string_view chunk) {
13+
std::print("{}", chunk);
14+
std::cout.flush();
15+
});
16+
17+
return 0;
18+
}

tests/l/llmapi/xmake.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
add_repositories("mcpplibs-index git@github.com:mcpplibs/mcpplibs-index.git")
2+
3+
add_requires("llmapi 0.0.1")
4+
5+
target("llmapi_test")
6+
set_kind("binary")
7+
add_languages("c++23")
8+
add_files("main.cpp")
9+
add_packages("llmapi")
10+
set_policy("build.c++.modules", true)

0 commit comments

Comments
 (0)