UNPKG

ai-functions

Version:

A powerful TypeScript library for building AI-powered applications with template literals and structured outputs

55 lines 1.59 kB
import { Response } from 'undici'; export const createMockTextResponse = (text) => ({ text, usage: { promptTokens: 10, completionTokens: 20, totalTokens: 30 }, response: { id: '1', timestamp: new Date(), modelId: 'test-model', messages: [{ role: 'assistant', content: text }], }, finishReason: 'stop', warnings: [], request: {}, logprobs: undefined, toolCalls: [], toolResults: [], steps: [], experimental_output: null, experimental_providerMetadata: {}, }); export const createMockObjectResponse = (object) => ({ text: JSON.stringify(object), object, usage: { promptTokens: 10, completionTokens: 20, totalTokens: 30 }, response: { id: '1', timestamp: new Date(), modelId: 'test-model', messages: [{ role: 'assistant', content: JSON.stringify(object) }], }, finishReason: 'stop', warnings: [], request: {}, logprobs: undefined, toolCalls: [], toolResults: [], steps: [], experimental_output: object, experimental_providerMetadata: {}, toJsonResponse: () => new Response(JSON.stringify(object), { status: 200, headers: { 'Content-Type': 'application/json' }, }), }); export const createMockStreamResponse = (chunks) => ({ ...createMockTextResponse(chunks.join('')), experimental_stream: { [Symbol.asyncIterator]: async function* () { for (const chunk of chunks) { yield chunk; } }, }, }); //# sourceMappingURL=test-types.js.map