completions.mjs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  2. import { APIResource } from "../../../resource.mjs";
  3. import { isRequestOptions } from "../../../core.mjs";
  4. import * as MessagesAPI from "./messages.mjs";
  5. import { Messages } from "./messages.mjs";
  6. import { CursorPage } from "../../../pagination.mjs";
  7. export class Completions extends APIResource {
  8. constructor() {
  9. super(...arguments);
  10. this.messages = new MessagesAPI.Messages(this._client);
  11. }
  12. create(body, options) {
  13. return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false });
  14. }
  15. /**
  16. * Get a stored chat completion. Only Chat Completions that have been created with
  17. * the `store` parameter set to `true` will be returned.
  18. *
  19. * @example
  20. * ```ts
  21. * const chatCompletion =
  22. * await client.chat.completions.retrieve('completion_id');
  23. * ```
  24. */
  25. retrieve(completionId, options) {
  26. return this._client.get(`/chat/completions/${completionId}`, options);
  27. }
  28. /**
  29. * Modify a stored chat completion. Only Chat Completions that have been created
  30. * with the `store` parameter set to `true` can be modified. Currently, the only
  31. * supported modification is to update the `metadata` field.
  32. *
  33. * @example
  34. * ```ts
  35. * const chatCompletion = await client.chat.completions.update(
  36. * 'completion_id',
  37. * { metadata: { foo: 'string' } },
  38. * );
  39. * ```
  40. */
  41. update(completionId, body, options) {
  42. return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
  43. }
  44. list(query = {}, options) {
  45. if (isRequestOptions(query)) {
  46. return this.list({}, query);
  47. }
  48. return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
  49. }
  50. /**
  51. * Delete a stored chat completion. Only Chat Completions that have been created
  52. * with the `store` parameter set to `true` can be deleted.
  53. *
  54. * @example
  55. * ```ts
  56. * const chatCompletionDeleted =
  57. * await client.chat.completions.del('completion_id');
  58. * ```
  59. */
  60. del(completionId, options) {
  61. return this._client.delete(`/chat/completions/${completionId}`, options);
  62. }
  63. }
  64. export class ChatCompletionsPage extends CursorPage {
  65. }
  66. export class ChatCompletionStoreMessagesPage extends CursorPage {
  67. }
  68. Completions.ChatCompletionsPage = ChatCompletionsPage;
  69. Completions.Messages = Messages;
  70. //# sourceMappingURL=completions.mjs.map