78 lines
2.7 KiB
JavaScript
78 lines
2.7 KiB
JavaScript
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
import { parseResponse, addOutputText, } from "../../lib/ResponsesParser.mjs";
|
|
import { ResponseStream } from "../../lib/responses/ResponseStream.mjs";
|
|
import { APIResource } from "../../core/resource.mjs";
|
|
import * as InputItemsAPI from "./input-items.mjs";
|
|
import { InputItems } from "./input-items.mjs";
|
|
import { buildHeaders } from "../../internal/headers.mjs";
|
|
import { path } from "../../internal/utils/path.mjs";
|
|
export class Responses extends APIResource {
|
|
constructor() {
|
|
super(...arguments);
|
|
this.inputItems = new InputItemsAPI.InputItems(this._client);
|
|
}
|
|
create(body, options) {
|
|
return this._client.post('/responses', { body, ...options, stream: body.stream ?? false })._thenUnwrap((rsp) => {
|
|
if ('object' in rsp && rsp.object === 'response') {
|
|
addOutputText(rsp);
|
|
}
|
|
return rsp;
|
|
});
|
|
}
|
|
retrieve(responseID, query = {}, options) {
|
|
return this._client.get(path `/responses/${responseID}`, {
|
|
query,
|
|
...options,
|
|
stream: query?.stream ?? false,
|
|
})._thenUnwrap((rsp) => {
|
|
if ('object' in rsp && rsp.object === 'response') {
|
|
addOutputText(rsp);
|
|
}
|
|
return rsp;
|
|
});
|
|
}
|
|
/**
|
|
* Deletes a model response with the given ID.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* await client.responses.delete(
|
|
* 'resp_677efb5139a88190b512bc3fef8e535d',
|
|
* );
|
|
* ```
|
|
*/
|
|
delete(responseID, options) {
|
|
return this._client.delete(path `/responses/${responseID}`, {
|
|
...options,
|
|
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
|
|
});
|
|
}
|
|
parse(body, options) {
|
|
return this._client.responses
|
|
.create(body, options)
|
|
._thenUnwrap((response) => parseResponse(response, body));
|
|
}
|
|
/**
|
|
* Creates a model response stream
|
|
*/
|
|
stream(body, options) {
|
|
return ResponseStream.createResponse(this._client, body, options);
|
|
}
|
|
/**
|
|
* Cancels a model response with the given ID. Only responses created with the
|
|
* `background` parameter set to `true` can be cancelled.
|
|
* [Learn more](https://platform.openai.com/docs/guides/background).
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* const response = await client.responses.cancel(
|
|
* 'resp_677efb5139a88190b512bc3fef8e535d',
|
|
* );
|
|
* ```
|
|
*/
|
|
cancel(responseID, options) {
|
|
return this._client.post(path `/responses/${responseID}/cancel`, options);
|
|
}
|
|
}
|
|
Responses.InputItems = InputItems;
|
|
//# sourceMappingURL=responses.mjs.map
|