Capture Api Response Test Fixture

作者 vercel5028fa46b4b4無授權條款收錄於 2026年10月8日更新於 2026年10月8日

Capture API response test fixture.

AI 產生的概覽

將真實的供應商 API 回應擷取為測試 fixture,用於 AI SDK 儲存庫中的解析測試。

功能
引導代理撰寫小型範例指令碼,呼叫供應商模型並記錄或儲存原始回應。對於 generateText,會把原始回應主體輸出到主控台,以便複製成 fixture;對於 streamText,會啟用 includeRawChunks 並使用 saveRawChunks 輔助函式把結果寫入輸出資料夾。產生的檔案會放入 fixtures 子資料夾,並依現有命名慣例命名。
適用情境
適用於新增或更新需要真實錄製 API 回應作為 fixture 的供應商回應解析測試。也適合在該儲存庫中依既有做法,透過範例資料夾下的指令碼產生這些 fixture。
執行需求
需要 AI SDK 風格的儲存庫、pnpm 與 tsx、所呼叫供應商的套件與憑證、連線該供應商的網路,以及所引用的範例輔助函式(run、saveRawChunks)。此技能未附指令碼,僅為說明文件。

API Response Test Fixtures

For provider response parsing tests, we aim at storing test fixtures with the true responses from the providers (unless they are too large in which case some cutting that does not change semantics is advised).

The fixtures are stored in a __fixtures__ subfolder, e.g. packages/openai/src/responses/__fixtures__. See the file names in packages/openai/src/responses/__fixtures__ for naming conventions and packages/openai/src/responses/openai-responses-language-model.test.ts for how to set up test helpers.

You can use our examples under /examples/ai-functions to generate test fixtures.

generateText (doGenerate testing)

For generateText, put the script under src/generate-text/<provider>/, log the raw response output to the console, and copy it into a new test fixture.

ts
import { openai } from '@ai-sdk/openai';import { generateText } from 'ai';import { run } from '../../lib/run';
run(async () => {  const result = await generateText({    model: openai('gpt-5-nano'),    prompt: 'Invent a new holiday and describe its traditions.',  });
  console.log(JSON.stringify(result.response.body, null, 2));});
streamText (doStream testing)

For streamText, you need to set includeRawChunks to true and use the special saveRawChunks helper. Put the script under the provider directory and run it from the /examples/ai-functions folder via pnpm tsx src/stream-text/<provider>/<script-name>.ts. The result is then stored in the /examples/ai-functions/output folder. You can copy it to your fixtures folder and rename it.

ts
import { openai } from '@ai-sdk/openai';import { streamText } from 'ai';import { run } from '../../lib/run';import { saveRawChunks } from '../../lib/save-raw-chunks';
run(async () => {  const result = streamText({    model: openai('gpt-5-nano'),    prompt: 'Invent a new holiday and describe its traditions.',    includeRawChunks: true,  });
  await saveRawChunks({ result, filename: 'openai-gpt-5-nano' });});

來源與署名

來源:vercel/ai位於skills/capture-api-response-test-fixture提交5028fa4

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架