threads.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
  3. Object.defineProperty(exports, "__esModule", { value: true });
  4. exports.Threads = void 0;
  5. const tslib_1 = require("../../../internal/tslib.js");
  6. const resource_1 = require("../../../core/resource.js");
  7. const MessagesAPI = tslib_1.__importStar(require("./messages.js"));
  8. const messages_1 = require("./messages.js");
  9. const RunsAPI = tslib_1.__importStar(require("./runs/runs.js"));
  10. const runs_1 = require("./runs/runs.js");
  11. const headers_1 = require("../../../internal/headers.js");
  12. const AssistantStream_1 = require("../../../lib/AssistantStream.js");
  13. const path_1 = require("../../../internal/utils/path.js");
  14. /**
  15. * @deprecated The Assistants API is deprecated in favor of the Responses API
  16. */
  17. class Threads extends resource_1.APIResource {
  18. constructor() {
  19. super(...arguments);
  20. this.runs = new RunsAPI.Runs(this._client);
  21. this.messages = new MessagesAPI.Messages(this._client);
  22. }
  23. /**
  24. * Create a thread.
  25. *
  26. * @deprecated The Assistants API is deprecated in favor of the Responses API
  27. */
  28. create(body = {}, options) {
  29. return this._client.post('/threads', {
  30. body,
  31. ...options,
  32. headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
  33. });
  34. }
  35. /**
  36. * Retrieves a thread.
  37. *
  38. * @deprecated The Assistants API is deprecated in favor of the Responses API
  39. */
  40. retrieve(threadID, options) {
  41. return this._client.get((0, path_1.path) `/threads/${threadID}`, {
  42. ...options,
  43. headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
  44. });
  45. }
  46. /**
  47. * Modifies a thread.
  48. *
  49. * @deprecated The Assistants API is deprecated in favor of the Responses API
  50. */
  51. update(threadID, body, options) {
  52. return this._client.post((0, path_1.path) `/threads/${threadID}`, {
  53. body,
  54. ...options,
  55. headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
  56. });
  57. }
  58. /**
  59. * Delete a thread.
  60. *
  61. * @deprecated The Assistants API is deprecated in favor of the Responses API
  62. */
  63. delete(threadID, options) {
  64. return this._client.delete((0, path_1.path) `/threads/${threadID}`, {
  65. ...options,
  66. headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
  67. });
  68. }
  69. createAndRun(body, options) {
  70. return this._client.post('/threads/runs', {
  71. body,
  72. ...options,
  73. headers: (0, headers_1.buildHeaders)([{ 'OpenAI-Beta': 'assistants=v2' }, options?.headers]),
  74. stream: body.stream ?? false,
  75. });
  76. }
  77. /**
  78. * A helper to create a thread, start a run and then poll for a terminal state.
  79. * More information on Run lifecycles can be found here:
  80. * https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
  81. */
  82. async createAndRunPoll(body, options) {
  83. const run = await this.createAndRun(body, options);
  84. return await this.runs.poll(run.id, { thread_id: run.thread_id }, options);
  85. }
  86. /**
  87. * Create a thread and stream the run back
  88. */
  89. createAndRunStream(body, options) {
  90. return AssistantStream_1.AssistantStream.createThreadAssistantStream(body, this._client.beta.threads, options);
  91. }
  92. }
  93. exports.Threads = Threads;
  94. Threads.Runs = runs_1.Runs;
  95. Threads.Messages = messages_1.Messages;
  96. //# sourceMappingURL=threads.js.map