glm-flash-pdf-turbo-defaults.test.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { fileURLToPath } from "node:url";
  2. import { describe, expect, it } from "vitest";
  3. import { ModelConfig, ModelConfigRules } from "@zcode/provider";
  4. import { NodeZCodeBuiltinProviderConfigSource } from "../src/index.js";
  5. describe("Todo126 发布配置的 Flash PDF 和模板 Turbo 默认", () => {
  6. it.each(["zai-standard-api", "bigmodel-standard-api"])(
  7. "普通 API %s 的两个 Turbo 默认关闭,个人可开启",
  8. async (templateId) => {
  9. const source = new NodeZCodeBuiltinProviderConfigSource({
  10. bundledFilePath: fileURLToPath(
  11. new URL("../../../config/provider/zcode-builtin.json", import.meta.url),
  12. ),
  13. watch: false,
  14. });
  15. try {
  16. const snapshot = await source.read();
  17. for (const modelId of ["GLM-5-Turbo", "GLM-5V-Turbo"]) {
  18. const input = {
  19. providerId: "personal",
  20. templateId,
  21. modelId,
  22. apiType: "openai-chat-completions",
  23. };
  24. expect(snapshot.models.resolve(input).enabled, modelId).toBe(false);
  25. const personal = new ModelConfigRules([
  26. {
  27. type: "provider-model",
  28. providerId: "personal",
  29. modelId,
  30. config: new ModelConfig({ enabled: true }),
  31. },
  32. ]);
  33. expect(
  34. ModelConfigRules.composeEffective(snapshot.models, personal).resolve(input).enabled,
  35. ).toBe(true);
  36. expect(snapshot.models.resolve({ ...input, templateId: undefined }).enabled).toBe(true);
  37. }
  38. for (const modelId of ["GLM-5.3", "GLM-5.3-Flash"]) {
  39. expect(
  40. snapshot.models.resolve({
  41. providerId: "personal",
  42. templateId,
  43. modelId,
  44. apiType: "openai-chat-completions",
  45. }).enabled,
  46. ).toBe(true);
  47. }
  48. } finally {
  49. source.dispose();
  50. }
  51. },
  52. );
  53. it("Flash 的全部格式/站点/别名支持 PDF,其他型号和个人覆盖不变", async () => {
  54. const source = new NodeZCodeBuiltinProviderConfigSource({
  55. bundledFilePath: fileURLToPath(
  56. new URL("../../../config/provider/zcode-builtin.json", import.meta.url),
  57. ),
  58. watch: false,
  59. });
  60. try {
  61. const snapshot = await source.read();
  62. for (const type of ["provider-model", "manual-provider-model"] as const) {
  63. const personal = new ModelConfigRules([
  64. {
  65. type,
  66. providerId: "personal",
  67. modelId: "GLM-5.3-Flash",
  68. config: new ModelConfig({ properties: { inputFormat: { supportsPdf: false } } }),
  69. },
  70. ]);
  71. const composed = ModelConfigRules.composeEffective(snapshot.models, personal);
  72. const effective = composed.resolve({
  73. providerId: "personal",
  74. modelId: "GLM-5.3-Flash",
  75. apiType: "openai-responses",
  76. });
  77. expect(effective.properties?.inputFormat?.supportsPdf).toBe(false);
  78. if (type === "manual-provider-model")
  79. expect(effective.properties?.inputFormat?.supportsImage).toBeUndefined();
  80. }
  81. for (const apiType of [
  82. "anthropic-messages",
  83. "openai-chat-completions",
  84. "openai-responses",
  85. ] as const) {
  86. for (const baseUrl of [
  87. "https://api.z.ai/api/anthropic",
  88. "https://open.bigmodel.cn/api/anthropic",
  89. "https://proxy.example/v1",
  90. ]) {
  91. for (const modelId of ["GLM-5.3-Flash", "glm-5.3-flash", "vendor/GLM-5.3-Flash:free"]) {
  92. const config = snapshot.models.resolve({
  93. providerId: "custom",
  94. modelId,
  95. apiType,
  96. baseUrl,
  97. });
  98. expect(
  99. config.properties?.inputFormat?.supportsPdf,
  100. `${apiType}/${baseUrl}/${modelId}`,
  101. ).toBe(true);
  102. expect(
  103. config.overlay(
  104. new ModelConfig({ properties: { inputFormat: { supportsPdf: false } } }),
  105. ).properties?.inputFormat?.supportsPdf,
  106. ).toBe(false);
  107. }
  108. for (const modelId of ["GLM-5.3", "GLM-4.7"]) {
  109. const config = snapshot.models.resolve({
  110. providerId: "custom",
  111. modelId,
  112. apiType,
  113. baseUrl,
  114. });
  115. expect(config.properties?.inputFormat?.supportsPdf).toBe(false);
  116. }
  117. }
  118. }
  119. } finally {
  120. source.dispose();
  121. }
  122. });
  123. it("仅两个套餐 Key 模板的 Turbo 默认关闭,个人仍可开启", async () => {
  124. const source = new NodeZCodeBuiltinProviderConfigSource({
  125. bundledFilePath: fileURLToPath(
  126. new URL("../../../config/provider/zcode-builtin.json", import.meta.url),
  127. ),
  128. watch: false,
  129. });
  130. try {
  131. const snapshot = await source.read();
  132. for (const templateId of [
  133. "zai-api",
  134. "bigmodel-api",
  135. "zai-standard-api",
  136. "bigmodel-standard-api",
  137. "custom",
  138. ]) {
  139. const config = snapshot.models.resolve({
  140. providerId: "personal",
  141. templateId,
  142. modelId: "GLM-5-Turbo",
  143. apiType: "anthropic-messages",
  144. baseUrl: "https://example.test",
  145. });
  146. // 普通 API 早已有 Turbo 默认关闭,保持;无模板的第三方仍沿用通用默认开启。
  147. expect(config.enabled, templateId).toBe(templateId === "custom");
  148. expect(config.overlay(new ModelConfig({ enabled: true })).enabled).toBe(true);
  149. expect(config.overlay(new ModelConfig({ enabled: false })).enabled).toBe(false);
  150. }
  151. } finally {
  152. source.dispose();
  153. }
  154. });
  155. });