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

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

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 93 94 95 96 971x   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';
 
export const EmbeddingData = z.object({
  /**
   * The object type, which is always "embedding".
   */
  object: z.literal('embedding'),
 
  /**
   * The embedding vector, which is a list of floats. The length of vector depends on the model as listed in the embedding guide.
   * The embedding can be in string format when base64 encoding is requested.
   */
  embedding: z.union([z.array(z.number()), z.string()]),
 
  /**
   * The index of the embedding in the list of embeddings.
   */
  index: z.number(),
});
 
export type EmbeddingData = z.infer<typeof EmbeddingData>;
 
export const EmbeddingsUsage = z.object({
  /**
   * The number of tokens used by the prompt.
   */
  prompt_tokens: z.number(),
 
  /**
   * The total number of tokens used by the request.
   */
  total_tokens: z.number(),
});
 
export type EmbeddingsUsage = z.infer<typeof EmbeddingsUsage>;
 
export const CreateEmbeddingsResponseBody = z.object({
  /**
   * The object type, which is always "list".
   */
  object: z.literal('list'),
 
  /**
   * The list of embeddings generated by the model.
   */
  data: z.array(EmbeddingData),
 
  /**
   * The name of the model used to generate the embedding.
   */
  model: z.string(),
 
  /**
   * The usage information for the request.
   */
  usage: EmbeddingsUsage,
});
 
export type CreateEmbeddingsResponseBody = z.infer<
  typeof CreateEmbeddingsResponseBody
>;
 
export const CreateEmbeddingsError = z.object({
  /**
   * The error message.
   */
  message: z.string(),
 
  /**
   * The error type.
   */
  type: z.string(),
 
  /**
   * The error parameter that caused the issue.
   */
  param: z.string().optional(),
 
  /**
   * The error code.
   */
  code: z.string().optional(),
});
 
export type CreateEmbeddingsError = z.infer<typeof CreateEmbeddingsError>;
 
export const CreateEmbeddingsErrorResponseBody = z.object({
  /**
   * The error object.
   */
  error: CreateEmbeddingsError,
});
 
export type CreateEmbeddingsErrorResponseBody = z.infer<
  typeof CreateEmbeddingsErrorResponseBody
>;