diff --git a/examples/demo.ts b/examples/demo.ts index cc7b829..1a8da36 100755 --- a/examples/demo.ts +++ b/examples/demo.ts @@ -6,13 +6,11 @@ const client = new Edgen(); async function main() { // Non-streaming: - /* const completion = await client.chat.completions.create({ model: 'gpt-4', - messages: [{ role: 'user', content: 'Say this is a test' }], + messages: [{ role: 'user', content: 'What is the result of 1 + 2?' }], }); console.log(completion.choices[0]?.message?.content); - */ // Streaming: const stream = await client.chat.completions.create({ diff --git a/examples/models.ts b/examples/models.ts new file mode 100755 index 0000000..731b096 --- /dev/null +++ b/examples/models.ts @@ -0,0 +1,43 @@ +#!/usr/bin/env -S npm run tsn -T + +import Edgen from 'edgen'; + +const client = new Edgen(); + +async function main() { + const models = await client.models.list(); + + console.log("Models Listing"); + console.log("=============="); + for await (const model of models) { + console.log("id : %s", model.id); + console.log("type : %s", model.object); + console.log("created: %s", model.created); + console.log("owner : %s", model.owned_by); + }; + + console.log("One Model"); + console.log("========="); + try { + const model = await client.models.retrieve("TheFake%2fMy-fake-model-GGUF"); + console.log("id : %s", model.id); + console.log("type : %s", model.object); + console.log("created: %s", model.created); + console.log("owner : %s", model.owned_by); + } catch (e) { + console.log("ERROR: %s", e) + } + + console.log("Delete Model"); + console.log("============"); + try { + const model = await client.models.del("TheFake%2fMy-fake-model-GGUF"); + console.log("id : %s", model.id); + console.log("type : %s", model.object); + console.log("deleted: %s", model.deleted); + } catch (e) { + console.log("ERROR: %s", e) + } +} + +main(); diff --git a/src/index.ts b/src/index.ts index f562d54..e74a360 100644 --- a/src/index.ts +++ b/src/index.ts @@ -141,6 +141,7 @@ export class Edgen extends Core.APIClient { completions: API.Completions = new API.Completions(this); chat: API.Chat = new API.Chat(this); audio: API.Audio = new API.Audio(this); + models: API.Models = new API.Models(this); misc: API.Misc = new API.Misc(this); protected override defaultQuery(): Core.DefaultQuery | undefined { diff --git a/src/resources/index.ts b/src/resources/index.ts index 2b67f68..fab5fc0 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -14,3 +14,4 @@ export { CompletionCreateParamsStreaming, Completions, } from './completions'; +export { Model, ModelDeleted, ModelsPage, Models } from './models'; diff --git a/src/resources/models.ts b/src/resources/models.ts new file mode 100644 index 0000000..472ce8a --- /dev/null +++ b/src/resources/models.ts @@ -0,0 +1,76 @@ +// File generated from our OpenAPI spec by Stainless. + +import * as Core from 'edgen/core'; +import { APIResource } from 'edgen/resource'; +import * as ModelsAPI from 'edgen/resources/models'; +import { Page } from 'edgen/pagination'; + +export class Models extends APIResource { + /** + * Retrieves a model instance, providing basic information about the model such as + * the owner and permissioning. + */ + retrieve(model: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/models/${model}`, options); + } + + /** + * Lists the currently available models, and provides basic information about each + * one such as the owner and availability. + */ + list(options?: Core.RequestOptions): Core.PagePromise { + return this._client.getAPIList('/models', ModelsPage, options); + } + + /** + * Delete a fine-tuned model. You must have the Owner role in your organization to + * delete a model. + */ + del(model: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.delete(`/models/${model}`, options); + } +} + +/** + * Note: no pagination actually occurs yet, this is for forwards-compatibility. + */ +export class ModelsPage extends Page {} + +/** + * Describes an OpenAI model offering that can be used with the API. + */ +export interface Model { + /** + * The model identifier, which can be referenced in the API endpoints. + */ + id: string; + + /** + * The Unix timestamp (in seconds) when the model was created. + */ + created: number; + + /** + * The object type, which is always "model". + */ + object: 'model'; + + /** + * The organization that owns the model. + */ + owned_by: string; +} + +export interface ModelDeleted { + id: string; + + deleted: boolean; + + object: string; +} + +export namespace Models { + export import Model = ModelsAPI.Model; + export import ModelDeleted = ModelsAPI.ModelDeleted; + export import ModelsPage = ModelsAPI.ModelsPage; +}