feat: add Z.AI env support and live test

This commit is contained in:
Peter Steinberger
2025-12-31 11:36:57 +01:00
parent 4bdc25d072
commit 21237dae98
6 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { completeSimple, getModel } from "@mariozechner/pi-ai";
import { describe, expect, it } from "vitest";
const ZAI_KEY = process.env.ZAI_API_KEY ?? process.env.Z_AI_API_KEY ?? "";
const LIVE = process.env.ZAI_LIVE_TEST === "1" || process.env.LIVE === "1";
const describeLive = LIVE && ZAI_KEY ? describe : describe.skip;
describeLive("zai live", () => {
it("returns assistant text", async () => {
const model = getModel("zai", "glm-4.7");
const res = await completeSimple(
model,
{
messages: [
{
role: "user",
content: "Reply with the word ok.",
timestamp: Date.now(),
},
],
},
{ apiKey: ZAI_KEY, maxTokens: 64 },
);
const text = res.content
.filter((block) => block.type === "text")
.map((block) => block.text.trim())
.join(" ");
expect(text.length).toBeGreaterThan(0);
});
});