zhipu-api-templates.test.ts 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { readFile } from "node:fs/promises";
  2. import { describe, expect, it } from "vitest";
  3. import { parseZCodeBuiltinModelConfigRules } from "@zcode/provider";
  4. describe("Zhipu four manual API templates", () => {
  5. it.each(["zcode-builtin.json", "zcode-builtin.test.json"])(
  6. "%s 区分普通计费与套餐端点、签名准入、获取入口和媒体能力",
  7. async (filename) => {
  8. const release = JSON.parse(
  9. await readFile(new URL(`../../../config/provider/${filename}`, import.meta.url), "utf8"),
  10. );
  11. const templates = release.config.providerConfigRules.templateRules;
  12. for (const template of templates) {
  13. expect(
  14. new URL(template.config.access.apiKeyManagementUrl).protocol,
  15. template.templateId,
  16. ).toBe("https:");
  17. expect(template.config.access).not.toHaveProperty("teamApiKeyManagementUrl");
  18. }
  19. const rules = parseZCodeBuiltinModelConfigRules(release.config.modelConfigRules);
  20. for (const family of ["zai", "bigmodel"]) {
  21. for (const standard of [false, true]) {
  22. const templateId = `${family}-${standard ? "standard-" : ""}api`;
  23. const template = templates.find(
  24. (item: { templateId: string }) => item.templateId === templateId,
  25. );
  26. expect(template, templateId).toBeDefined();
  27. const label = `${family === "zai" ? "Z.ai" : "BigModel"} ${standard ? "API" : "Coding Plan"}`;
  28. expect(template.templateNameMap).toEqual({ "zh-CN": label, "en-US": label });
  29. const config = template.config;
  30. const host = family === "zai" ? "api.z.ai" : "open.bigmodel.cn";
  31. expect(config.api).toEqual({
  32. type: standard ? "openai-chat-completions" : "anthropic-messages",
  33. baseUrl: `https://${host}/api/${standard ? "paas/v4" : "anthropic"}`,
  34. });
  35. expect(config.access.type).toBe(standard ? "api-key" : "zhipu-coding-plan-api-key");
  36. expect(config.access.apiKeyManagementUrl).toBe(
  37. family === "zai"
  38. ? "https://z.ai/manage-apikey/apikey-list"
  39. : standard
  40. ? "https://bigmodel.cn/usercenter/proj-mgmt/apikeys"
  41. : "https://bigmodel.cn/coding-plan/personal/overview",
  42. );
  43. if (!standard) {
  44. expect(config.builtinModelIds).toEqual(["GLM-5.3", "GLM-5.3-Flash"]);
  45. }
  46. for (const modelId of ["GLM-5.3", "GLM-5.3-Flash"]) {
  47. const resolved = rules.resolve({
  48. templateId,
  49. providerId: "personal-fixture",
  50. modelId,
  51. apiType: config.api.type,
  52. baseUrl: config.api.baseUrl,
  53. });
  54. expect(config.builtinModelIds).toContain(modelId);
  55. expect(resolved.enabled).toBe(true);
  56. expect(resolved.properties?.inputFormat?.supportsImage).toBe(
  57. !standard || modelId.endsWith("Flash"),
  58. );
  59. expect(resolved.properties?.supportsNativeWebSearch).toBe(!standard);
  60. expect(resolved.properties?.supportsMidConversationSystem).toBe(!standard);
  61. }
  62. }
  63. }
  64. },
  65. );
  66. });