completions.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. "use strict";
  2. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  3. var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
  4. if (k2 === undefined) k2 = k;
  5. var desc = Object.getOwnPropertyDescriptor(m, k);
  6. if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
  7. desc = { enumerable: true, get: function() { return m[k]; } };
  8. }
  9. Object.defineProperty(o, k2, desc);
  10. }) : (function(o, m, k, k2) {
  11. if (k2 === undefined) k2 = k;
  12. o[k2] = m[k];
  13. }));
  14. var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
  15. Object.defineProperty(o, "default", { enumerable: true, value: v });
  16. }) : function(o, v) {
  17. o["default"] = v;
  18. });
  19. var __importStar = (this && this.__importStar) || function (mod) {
  20. if (mod && mod.__esModule) return mod;
  21. var result = {};
  22. if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
  23. __setModuleDefault(result, mod);
  24. return result;
  25. };
  26. Object.defineProperty(exports, "__esModule", { value: true });
  27. exports.ChatCompletionStoreMessagesPage = exports.ChatCompletionsPage = exports.Completions = void 0;
  28. const resource_1 = require("../../../resource.js");
  29. const core_1 = require("../../../core.js");
  30. const MessagesAPI = __importStar(require("./messages.js"));
  31. const messages_1 = require("./messages.js");
  32. const pagination_1 = require("../../../pagination.js");
  33. class Completions extends resource_1.APIResource {
  34. constructor() {
  35. super(...arguments);
  36. this.messages = new MessagesAPI.Messages(this._client);
  37. }
  38. create(body, options) {
  39. return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false });
  40. }
  41. /**
  42. * Get a stored chat completion. Only Chat Completions that have been created with
  43. * the `store` parameter set to `true` will be returned.
  44. *
  45. * @example
  46. * ```ts
  47. * const chatCompletion =
  48. * await client.chat.completions.retrieve('completion_id');
  49. * ```
  50. */
  51. retrieve(completionId, options) {
  52. return this._client.get(`/chat/completions/${completionId}`, options);
  53. }
  54. /**
  55. * Modify a stored chat completion. Only Chat Completions that have been created
  56. * with the `store` parameter set to `true` can be modified. Currently, the only
  57. * supported modification is to update the `metadata` field.
  58. *
  59. * @example
  60. * ```ts
  61. * const chatCompletion = await client.chat.completions.update(
  62. * 'completion_id',
  63. * { metadata: { foo: 'string' } },
  64. * );
  65. * ```
  66. */
  67. update(completionId, body, options) {
  68. return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
  69. }
  70. list(query = {}, options) {
  71. if ((0, core_1.isRequestOptions)(query)) {
  72. return this.list({}, query);
  73. }
  74. return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
  75. }
  76. /**
  77. * Delete a stored chat completion. Only Chat Completions that have been created
  78. * with the `store` parameter set to `true` can be deleted.
  79. *
  80. * @example
  81. * ```ts
  82. * const chatCompletionDeleted =
  83. * await client.chat.completions.del('completion_id');
  84. * ```
  85. */
  86. del(completionId, options) {
  87. return this._client.delete(`/chat/completions/${completionId}`, options);
  88. }
  89. }
  90. exports.Completions = Completions;
  91. class ChatCompletionsPage extends pagination_1.CursorPage {
  92. }
  93. exports.ChatCompletionsPage = ChatCompletionsPage;
  94. class ChatCompletionStoreMessagesPage extends pagination_1.CursorPage {
  95. }
  96. exports.ChatCompletionStoreMessagesPage = ChatCompletionStoreMessagesPage;
  97. Completions.ChatCompletionsPage = ChatCompletionsPage;
  98. Completions.Messages = messages_1.Messages;
  99. //# sourceMappingURL=completions.js.map