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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jobs:

- name: Build with mcpp
run: mcpp build

- name: Template smoke (compile each template against this checkout)
run: bash tools/template_smoke.sh
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mcpp add llmapi

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

```cpp
Expand Down
2 changes: 1 addition & 1 deletion README.zh.hant.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mcpp add llmapi

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

```cpp
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mcpp add llmapi

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

```cpp
Expand Down
2 changes: 1 addition & 1 deletion docs/en/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Or declare it in `mcpp.toml`:

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

### Building from Source
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-hant/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mcpp add llmapi

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

## 從原始碼建置
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mcpp add llmapi

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

## 从源码构建
Expand Down
2 changes: 1 addition & 1 deletion mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "llmapi"
version = "0.2.7"
version = "0.2.8"
description = "Modern C++ LLM API client with openai-compatible support"
license = "Apache-2.0"
repo = "https://github.com/mcpplibs/llmapi"
Expand Down
2 changes: 1 addition & 1 deletion templates/anthropic/src/main.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {

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

Expand Down
14 changes: 8 additions & 6 deletions templates/chat/src/main.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {

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

Expand All @@ -21,21 +21,23 @@ int main() {
std::println("{{project.name}} — chat CLI (type 'quit' to exit)");

while (true) {
std::print("\nYou: ");
std::print(std::cout, "\nYou: ");
std::cout.flush();
std::string input;
if (!std::getline(std::cin, input)) break;
if (input == "quit" || input == "q") break;
if (input.empty()) continue;

try {
std::print("AI: ");
std::print(std::cout, "AI: ");
std::cout.flush();
client.chat_stream(input, [](std::string_view chunk) {
std::print("{}", chunk);
std::fflush(stdout);
std::print(std::cout, "{}", chunk);
std::cout.flush();
});
std::println("");
} catch (const std::exception& e) {
std::println(stderr, "\nError: {}", e.what());
std::println(std::cerr, "\nError: {}", e.what());
}
}

Expand Down
2 changes: 1 addition & 1 deletion templates/deepseek/src/main.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ int main() {

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

Expand Down
2 changes: 1 addition & 1 deletion templates/openai/src/main.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int main() {

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

Expand Down
67 changes: 67 additions & 0 deletions tools/template_smoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash
# Compile-check every template in templates/ against the in-repo library.
#
# Renders each template the way `mcpp new` does ({{project.name}} /
# {{self.name}} / {{self.version}}), then swaps the generated version
# dependency for a path dependency on this checkout so templates are
# verified BEFORE a release exists in the index.
#
# Usage: bash tools/template_smoke.sh (requires mcpp on PATH, or $MCPP)
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MCPP_BIN="${MCPP:-$(command -v mcpp || true)}"
if [[ -z "$MCPP_BIN" || ! -x "$MCPP_BIN" ]]; then
echo "FATAL: set MCPP=/path/to/mcpp or put mcpp on PATH" >&2
exit 1
fi

SELF_NAME="llmapi"
SELF_VERSION="$(sed -n 's/^version *= *"\([^"]*\)".*/\1/p' "$ROOT/mcpp.toml" | head -1)"

# Stay inside the repo so the workspace mcpp pin (.xlings.json) still
# resolves the `mcpp` shim; target/ is gitignored.
TMP="$ROOT/target/template-smoke"
rm -rf "$TMP"
mkdir -p "$TMP"
trap 'rm -rf "$TMP"' EXIT

fail=0
for tdir in "$ROOT"/templates/*/; do
tname="$(basename "$tdir")"
proj="$TMP/smoke_$tname"
mkdir -p "$proj"

# render: strip .in, expand the placeholder vocabulary
while IFS= read -r -d '' f; do
rel="${f#"$tdir"}"
case "$rel" in template.toml) continue ;; esac
dest="$proj/${rel%.in}"
mkdir -p "$(dirname "$dest")"
if [[ "$f" == *.in ]]; then
sed -e "s/{{project\.name}}/smoke_$tname/g" \
-e "s/{{self\.name}}/$SELF_NAME/g" \
-e "s/{{self\.version}}/$SELF_VERSION/g" "$f" > "$dest"
else
cp "$f" "$dest"
fi
done < <(find "$tdir" -type f -print0)

# build against this checkout, not the (possibly unreleased) index version
python3 - "$proj/mcpp.toml" "$ROOT" <<'EOF'
import sys, re, pathlib
p, root = pathlib.Path(sys.argv[1]), sys.argv[2]
t = p.read_text()
t = re.sub(r'llmapi *= *"[^"]*"', f'llmapi = {{ path = "{root}" }}', t)
p.write_text(t)
EOF

echo "=== template: $tname ==="
if ! (cd "$proj" && "$MCPP_BIN" build); then
echo "FAIL: template '$tname' does not compile" >&2
fail=1
fi
done

[[ $fail -eq 0 ]] && echo "All templates compile."
exit $fail
Loading