openai-chunks.ts 827 B

123456789101112131415161718192021222324252627
  1. /**
  2. * Shared chunk shapes for OpenAI Chat / OpenAI-compatible Chat fixture tests.
  3. * Multiple test files build the same `{ id, choices: [{ delta, finish_reason }], usage }`
  4. * envelope; consolidating here keeps tool-call event shapes consistent.
  5. */
  6. const FIXTURE_ID = "chatcmpl_fixture"
  7. export const deltaChunk = (delta: object, finishReason: string | null = null) => ({
  8. id: FIXTURE_ID,
  9. choices: [{ delta, finish_reason: finishReason }],
  10. usage: null,
  11. })
  12. export const usageChunk = (usage: object) => ({
  13. id: FIXTURE_ID,
  14. choices: [],
  15. usage,
  16. })
  17. export const finishChunk = (reason: string) => deltaChunk({}, reason)
  18. export const toolCallChunk = (id: string, name: string, args: string, index = 0) =>
  19. deltaChunk({
  20. role: "assistant",
  21. tool_calls: [{ index, id, function: { name, arguments: args } }],
  22. })