From d89a792485532accce1fd82afd92fe9f2d378f13 Mon Sep 17 00:00:00 2001 From: noble-varghese Date: Tue, 31 Oct 2023 16:51:18 +0530 Subject: [PATCH] feat: Add support for the saved prompt generations --- examples/promptGeneration.ts | 16 ++++++++++++++++ src/apis/generations.ts | 28 +++++++++++++++++++++++++++- src/index.ts | 2 +- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 examples/promptGeneration.ts diff --git a/examples/promptGeneration.ts b/examples/promptGeneration.ts new file mode 100644 index 0000000..644f089 --- /dev/null +++ b/examples/promptGeneration.ts @@ -0,0 +1,16 @@ +import { Portkey } from "../src"; + +const portkey = new Portkey({ + mode: "fallback" +}); + +async function main() { + const chatCompletion = await portkey.generations.create({ + promptId: "your-prompt-id", + // variables: {hello: "world"} # Add variables if required + }); + + console.log(chatCompletion.data); +}; + +main(); \ No newline at end of file diff --git a/src/apis/generations.ts b/src/apis/generations.ts index 3ec7f96..3da3021 100644 --- a/src/apis/generations.ts +++ b/src/apis/generations.ts @@ -1 +1,27 @@ -export class Generations { } \ No newline at end of file +import { ModelParams } from "../_types/portkeyConstructs"; +import { ApiResource } from "../apiResource"; +import { APIPromise, RequestOptions } from "../baseClient"; + +export class Generations extends ApiResource { + create( + _body: GenerationsBody, + opts?: RequestOptions + ): APIPromise { + const config = this.client.config || { + mode: this.client.mode, + options: this.client.llms + } + const body = { "variables": _body.variables } + return this.post(`/v1/prompts/${_body.promptId}/generate`, { body, ...opts }) + } +} + +export interface GenerationsBody extends ModelParams { + promptId: string; + variables?: Record +} + +export interface Generation { + success: boolean, + data: Record +} diff --git a/src/index.ts b/src/index.ts index 40c2003..65408b7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,7 @@ export class Portkey extends ApiClient { completions: API.Completions = new API.Completions(this); chatCompletions = new API.ChatCompletions(this); - // generations = new API.Generations(); + generations = new API.Generations(this); } export import LLMOptions = Types.LLMOptions; \ No newline at end of file