All files / shared/src/types/api/routes/images-api response.ts

100% Statements 41/41
100% Branches 0/0
100% Functions 0/0
100% Lines 41/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 931x         1x   1x   1x 1x 1x 1x 1x 1x 1x             1x   1x   1x   1x   1x   1x 1x   1x   1x 1x 1x 1x             1x   1x 1x   1x   1x 1x 1x 1x             1x   1x   1x   1x   1x   1x 1x             1x   1x   1x 1x          
import { z } from 'zod';
 
/**
 * Content filter results for a prompt or image.
 */
export const ContentFilterResult = z.object({
  /** Whether the content was filtered. */
  filtered: z.boolean(),
  /** The severity level of the content. */
  severity: z.union([
    z.literal('safe'),
    z.literal('low'),
    z.literal('medium'),
    z.literal('high'),
  ]),
});
 
export type ContentFilterResult = z.infer<typeof ContentFilterResult>;
 
/**
 * Content filter results for different categories.
 */
export const ContentFilterResults = z.object({
  /** Content filter result for hate content. */
  hate: ContentFilterResult.optional(),
  /** Content filter result for self-harm content. */
  self_harm: ContentFilterResult.optional(),
  /** Content filter result for sexual content. */
  sexual: ContentFilterResult.optional(),
  /** Content filter result for violent content. */
  violence: ContentFilterResult.optional(),
  /** Error details if content filtering failed to run. */
  error: z
    .object({
      /** Error code when content filtering fails. */
      code: z.string(),
      /** Error message when content filtering fails. */
      message: z.string(),
    })
    .optional(),
});
 
export type ContentFilterResults = z.infer<typeof ContentFilterResults>;
 
/**
 * Prompt filter results with additional profanity detection.
 */
export const PromptFilterResults = ContentFilterResults.extend({
  /** Profanity detection result. */
  profanity: z
    .object({
      /** Whether profanity was detected. */
      detected: z.boolean(),
      /** Whether the prompt was filtered due to profanity. */
      filtered: z.boolean(),
    })
    .optional(),
});
 
export type PromptFilterResults = z.infer<typeof PromptFilterResults>;
 
/**
 * Represents the url or the content of an image generated by the OpenAI API.
 */
export const ImageObject = z.object({
  /** The base64-encoded JSON of the generated image, if response_format is b64_json. */
  b64_json: z.string().optional(),
  /** The URL of the generated image, if response_format is url (default). */
  url: z.string().optional(),
  /** The prompt that was used to generate the image, if there was any revision to the prompt. */
  revised_prompt: z.string().optional(),
  /** Content filter results for the generated image. */
  content_filter_results: ContentFilterResults.optional(),
  /** Content filter results for the input prompt. */
  prompt_filter_results: PromptFilterResults.optional(),
});
 
export type ImageObject = z.infer<typeof ImageObject>;
 
/**
 * Represents a response from the image generation endpoint.
 */
export const GenerateImageResponseBody = z.object({
  /** The Unix timestamp (in seconds) of when the image was generated. */
  created: z.number(),
  /** The list of generated images. */
  data: z.array(ImageObject),
});
 
export type GenerateImageResponseBody = z.infer<
  typeof GenerateImageResponseBody
>;