Skip to content

Commit

Permalink
Merge pull request #10 from Portkey-AI/noble-varghese/add-generations…
Browse files Browse the repository at this point in the history
…-api

feat: Add support for the saved prompt generations
  • Loading branch information
noble-varghese authored Oct 31, 2023
2 parents a1293fb + d89a792 commit 9b4d860
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
16 changes: 16 additions & 0 deletions examples/promptGeneration.ts
Original file line number Diff line number Diff line change
@@ -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();
28 changes: 27 additions & 1 deletion src/apis/generations.ts
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
export class Generations { }
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<Generation> {
const config = this.client.config || {
mode: this.client.mode,
options: this.client.llms
}
const body = { "variables": _body.variables }
return this.post<Generation>(`/v1/prompts/${_body.promptId}/generate`, { body, ...opts })
}
}

export interface GenerationsBody extends ModelParams {
promptId: string;
variables?: Record<string, any>
}

export interface Generation {
success: boolean,
data: Record<string, any>
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 9b4d860

Please sign in to comment.