embeddings.d.ts 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { APIResource } from "../resource.js";
  2. import * as Core from "../core.js";
  3. export declare class Embeddings extends APIResource {
  4. /**
  5. * Creates an embedding vector representing the input text.
  6. *
  7. * @example
  8. * ```ts
  9. * const createEmbeddingResponse =
  10. * await client.embeddings.create({
  11. * input: 'The quick brown fox jumped over the lazy dog',
  12. * model: 'text-embedding-3-small',
  13. * });
  14. * ```
  15. */
  16. create(body: EmbeddingCreateParams, options?: Core.RequestOptions<EmbeddingCreateParams>): Core.APIPromise<CreateEmbeddingResponse>;
  17. }
  18. export interface CreateEmbeddingResponse {
  19. /**
  20. * The list of embeddings generated by the model.
  21. */
  22. data: Array<Embedding>;
  23. /**
  24. * The name of the model used to generate the embedding.
  25. */
  26. model: string;
  27. /**
  28. * The object type, which is always "list".
  29. */
  30. object: 'list';
  31. /**
  32. * The usage information for the request.
  33. */
  34. usage: CreateEmbeddingResponse.Usage;
  35. }
  36. export declare namespace CreateEmbeddingResponse {
  37. /**
  38. * The usage information for the request.
  39. */
  40. interface Usage {
  41. /**
  42. * The number of tokens used by the prompt.
  43. */
  44. prompt_tokens: number;
  45. /**
  46. * The total number of tokens used by the request.
  47. */
  48. total_tokens: number;
  49. }
  50. }
  51. /**
  52. * Represents an embedding vector returned by embedding endpoint.
  53. */
  54. export interface Embedding {
  55. /**
  56. * The embedding vector, which is a list of floats. The length of vector depends on
  57. * the model as listed in the
  58. * [embedding guide](https://platform.openai.com/docs/guides/embeddings).
  59. */
  60. embedding: Array<number>;
  61. /**
  62. * The index of the embedding in the list of embeddings.
  63. */
  64. index: number;
  65. /**
  66. * The object type, which is always "embedding".
  67. */
  68. object: 'embedding';
  69. }
  70. export type EmbeddingModel = 'text-embedding-ada-002' | 'text-embedding-3-small' | 'text-embedding-3-large';
  71. export interface EmbeddingCreateParams {
  72. /**
  73. * Input text to embed, encoded as a string or array of tokens. To embed multiple
  74. * inputs in a single request, pass an array of strings or array of token arrays.
  75. * The input must not exceed the max input tokens for the model (8192 tokens for
  76. * all embedding models), cannot be an empty string, and any array must be 2048
  77. * dimensions or less.
  78. * [Example Python code](https://cookbook.openai.com/examples/how_to_count_tokens_with_tiktoken)
  79. * for counting tokens. In addition to the per-input token limit, all embedding
  80. * models enforce a maximum of 300,000 tokens summed across all inputs in a single
  81. * request.
  82. */
  83. input: string | Array<string> | Array<number> | Array<Array<number>>;
  84. /**
  85. * ID of the model to use. You can use the
  86. * [List models](https://platform.openai.com/docs/api-reference/models/list) API to
  87. * see all of your available models, or see our
  88. * [Model overview](https://platform.openai.com/docs/models) for descriptions of
  89. * them.
  90. */
  91. model: (string & {}) | EmbeddingModel;
  92. /**
  93. * The number of dimensions the resulting output embeddings should have. Only
  94. * supported in `text-embedding-3` and later models.
  95. */
  96. dimensions?: number;
  97. /**
  98. * The format to return the embeddings in. Can be either `float` or
  99. * [`base64`](https://pypi.org/project/pybase64/).
  100. */
  101. encoding_format?: 'float' | 'base64';
  102. /**
  103. * A unique identifier representing your end-user, which can help OpenAI to monitor
  104. * and detect abuse.
  105. * [Learn more](https://platform.openai.com/docs/guides/safety-best-practices#end-user-ids).
  106. */
  107. user?: string;
  108. }
  109. export declare namespace Embeddings {
  110. export { type CreateEmbeddingResponse as CreateEmbeddingResponse, type Embedding as Embedding, type EmbeddingModel as EmbeddingModel, type EmbeddingCreateParams as EmbeddingCreateParams, };
  111. }
  112. //# sourceMappingURL=embeddings.d.ts.map