| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import { mkdtemp, writeFile } from "node:fs/promises";
- import { tmpdir } from "node:os";
- import { join } from "node:path";
- export const secret = "fixture-private-api-key";
- export const architectureAnswer = [
- "目标与边界",
- "组件与数据",
- "状态与时序",
- "故障推演",
- "方案取舍",
- "验证与运维",
- ]
- .map(
- (title, i) =>
- `## ${i + 1}. ${title}\n${"任务状态由数据库持有,投递允许重复,写入用版本校验,外部结果未知时进入对账流程。".repeat(6)}`,
- )
- .join("\n\n");
- export async function fixture(apiType = "openai-chat-completions") {
- const dir = await mkdtemp(join(tmpdir(), "provider-regression-"));
- const release = {
- schemaVersion: 1,
- revision: 1,
- config: {
- providerConfigRules: {
- templateRules: [
- {
- templateId: "example",
- templateNameMap: { "en-US": "Example" },
- config: {
- api: { type: apiType, baseUrl: "https://provider.example.com/v1" },
- access: { type: "api-key" },
- builtinModelIds: ["model-a"],
- },
- },
- ],
- providerRules: [],
- },
- modelConfigRules: {
- modelRules: [
- {
- modelMatch: ".*",
- config: {
- enabled: true,
- properties: {
- requiresMfjsToolSchema: false,
- contextWindow: 32000,
- inputFormat: {
- supportsText: true,
- supportsImage: false,
- supportsVideo: false,
- supportsAudio: false,
- supportsPdf: false,
- },
- outputFormat: { supportsText: true },
- supportsToolCall: true,
- supportsJsonSchemaOutput: false,
- supportsNativeWebSearch: false,
- supportsMidConversationSystem: true,
- },
- optionSpecs: {
- reasoningLevel: {
- values: ["low", "high"],
- map: '{"reasoning_effort": reasoningLevel}',
- },
- maxOutputTokens: { max: 8192, map: '{"max_tokens": maxOutputTokens}' },
- },
- },
- },
- ],
- modelApiRules: [],
- providerSiteRules: [],
- templateModelRules: [],
- builtinProviderModelRules: [],
- },
- },
- };
- await writeFile(join(dir, "builtin.json"), JSON.stringify(release));
- await writeFile(
- join(dir, "providers.json"),
- JSON.stringify({
- builtinFile: "builtin.json",
- providerRules: [
- {
- providerId: "test-a",
- templateId: "example",
- config: { group: "standard-personal", access: { type: "api-key", apiKey: secret } },
- },
- ],
- }),
- );
- const list = {
- targets: [{ providerId: "test-a", modelIds: ["*"] }],
- caseIds: ["REASON-001"],
- repetitions: 3,
- maxOutputTokens: 1024,
- timeoutMs: 2000,
- };
- await writeFile(join(dir, "list.json"), JSON.stringify(list));
- return {
- dir,
- list,
- options: {
- providersFile: join(dir, "providers.json"),
- listFile: join(dir, "list.json"),
- outputDir: join(dir, "report"),
- },
- };
- }
- export function chatResponse(reasoningTokens?: number, finish = "stop") {
- const payloads = [
- {
- choices: [
- {
- index: 0,
- delta: { role: "assistant", reasoning_content: "思考😀" },
- finish_reason: null,
- },
- ],
- },
- { choices: [{ index: 0, delta: { content: architectureAnswer }, finish_reason: null }] },
- {
- choices: [{ index: 0, delta: {}, finish_reason: finish }],
- usage: {
- prompt_tokens: 20,
- completion_tokens: 25,
- ...(reasoningTokens === undefined
- ? {}
- : { completion_tokens_details: { reasoning_tokens: reasoningTokens } }),
- },
- },
- ];
- return new Response(
- payloads
- .map(
- (p) =>
- `data: ${JSON.stringify({ id: "test", object: "chat.completion.chunk", created: 1, model: "model-a", ...p })}\n\n`,
- )
- .join("") + "data: [DONE]\n\n",
- { headers: { "content-type": "text/event-stream" } },
- );
- }
|