embeddings.d.ts 4.0 KB

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