completions.mjs•2.58 kB
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from "../../../resource.mjs";
import { isRequestOptions } from "../../../core.mjs";
import * as MessagesAPI from "./messages.mjs";
import { Messages } from "./messages.mjs";
import { CursorPage } from "../../../pagination.mjs";
export class Completions extends APIResource {
constructor() {
super(...arguments);
this.messages = new MessagesAPI.Messages(this._client);
}
create(body, options) {
return this._client.post('/chat/completions', { body, ...options, stream: body.stream ?? false });
}
/**
* Get a stored chat completion. Only Chat Completions that have been created with
* the `store` parameter set to `true` will be returned.
*
* @example
* ```ts
* const chatCompletion =
* await client.chat.completions.retrieve('completion_id');
* ```
*/
retrieve(completionId, options) {
return this._client.get(`/chat/completions/${completionId}`, options);
}
/**
* Modify a stored chat completion. Only Chat Completions that have been created
* with the `store` parameter set to `true` can be modified. Currently, the only
* supported modification is to update the `metadata` field.
*
* @example
* ```ts
* const chatCompletion = await client.chat.completions.update(
* 'completion_id',
* { metadata: { foo: 'string' } },
* );
* ```
*/
update(completionId, body, options) {
return this._client.post(`/chat/completions/${completionId}`, { body, ...options });
}
list(query = {}, options) {
if (isRequestOptions(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/chat/completions', ChatCompletionsPage, { query, ...options });
}
/**
* Delete a stored chat completion. Only Chat Completions that have been created
* with the `store` parameter set to `true` can be deleted.
*
* @example
* ```ts
* const chatCompletionDeleted =
* await client.chat.completions.del('completion_id');
* ```
*/
del(completionId, options) {
return this._client.delete(`/chat/completions/${completionId}`, options);
}
}
export class ChatCompletionsPage extends CursorPage {
}
export class ChatCompletionStoreMessagesPage extends CursorPage {
}
Completions.ChatCompletionsPage = ChatCompletionsPage;
Completions.Messages = Messages;
//# sourceMappingURL=completions.mjs.map