108 lines
No EOL
4 KiB
JavaScript
108 lines
No EOL
4 KiB
JavaScript
"use strict";
|
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.Threads = void 0;
|
|
const resource_1 = require("../../../resource.js");
|
|
const core_1 = require("../../../core.js");
|
|
const AssistantStream_1 = require("../../../lib/AssistantStream.js");
|
|
const MessagesAPI = __importStar(require("./messages.js"));
|
|
const RunsAPI = __importStar(require("./runs/runs.js"));
|
|
class Threads extends resource_1.APIResource {
|
|
constructor() {
|
|
super(...arguments);
|
|
this.runs = new RunsAPI.Runs(this._client);
|
|
this.messages = new MessagesAPI.Messages(this._client);
|
|
}
|
|
create(body = {}, options) {
|
|
if ((0, core_1.isRequestOptions)(body)) {
|
|
return this.create({}, body);
|
|
}
|
|
return this._client.post('/threads', {
|
|
body,
|
|
...options,
|
|
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
});
|
|
}
|
|
/**
|
|
* Retrieves a thread.
|
|
*/
|
|
retrieve(threadId, options) {
|
|
return this._client.get(`/threads/${threadId}`, {
|
|
...options,
|
|
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
});
|
|
}
|
|
/**
|
|
* Modifies a thread.
|
|
*/
|
|
update(threadId, body, options) {
|
|
return this._client.post(`/threads/${threadId}`, {
|
|
body,
|
|
...options,
|
|
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
});
|
|
}
|
|
/**
|
|
* Delete a thread.
|
|
*/
|
|
del(threadId, options) {
|
|
return this._client.delete(`/threads/${threadId}`, {
|
|
...options,
|
|
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
});
|
|
}
|
|
createAndRun(body, options) {
|
|
return this._client.post('/threads/runs', {
|
|
body,
|
|
...options,
|
|
headers: { 'OpenAI-Beta': 'assistants=v2', ...options?.headers },
|
|
stream: body.stream ?? false,
|
|
});
|
|
}
|
|
/**
|
|
* A helper to create a thread, start a run and then poll for a terminal state.
|
|
* More information on Run lifecycles can be found here:
|
|
* https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
|
|
*/
|
|
async createAndRunPoll(body, options) {
|
|
const run = await this.createAndRun(body, options);
|
|
return await this.runs.poll(run.thread_id, run.id, options);
|
|
}
|
|
/**
|
|
* Create a thread and stream the run back
|
|
*/
|
|
createAndRunStream(body, options) {
|
|
return AssistantStream_1.AssistantStream.createThreadAssistantStream(body, this._client.beta.threads, options);
|
|
}
|
|
}
|
|
exports.Threads = Threads;
|
|
(function (Threads) {
|
|
Threads.Runs = RunsAPI.Runs;
|
|
Threads.RunsPage = RunsAPI.RunsPage;
|
|
Threads.Messages = MessagesAPI.Messages;
|
|
Threads.MessagesPage = MessagesAPI.MessagesPage;
|
|
})(Threads = exports.Threads || (exports.Threads = {}));
|
|
//# sourceMappingURL=threads.js.map
|