From 122f01f6f40371129180863290377b1e0fd0630d Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Fri, 26 May 2023 17:03:25 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- legacy/examples/scratch.ts | 2 +- legacy/src/agentic.ts | 30 ++++++++++++++++++++++++++++++ legacy/src/llm.ts | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/legacy/examples/scratch.ts b/legacy/examples/scratch.ts index 05233df0..803661a7 100644 --- a/legacy/examples/scratch.ts +++ b/legacy/examples/scratch.ts @@ -16,7 +16,7 @@ async function main() { // .call() // console.log(ex0) - const ex1 = await $.gpt4(`give me fake data`) + const ex1 = await $.gpt4(`generate fake data`) .output(z.object({ foo: z.string(), bar: z.number() })) // .output(z.string()) // .retry({ attempts: 3 }) diff --git a/legacy/src/agentic.ts b/legacy/src/agentic.ts index cd837779..07da0bf4 100644 --- a/legacy/src/agentic.ts +++ b/legacy/src/agentic.ts @@ -34,6 +34,36 @@ export class Agentic { } } + llm( + promptOrChatCompletionParams: + | string + | Partial // TODO: make more strict + ) { + let options: Partial + + if (typeof promptOrChatCompletionParams === 'string') { + options = { + messages: [ + { + role: 'user', + content: promptOrChatCompletionParams + } + ] + } + } else { + options = promptOrChatCompletionParams + + if (!options.messages) { + throw new Error('messages must be provided') + } + } + + return new OpenAIChatModelBuilder(this._client, { + ...(this._defaults as any), // TODO + ...options + }) + } + gpt4( promptOrChatCompletionParams: | string diff --git a/legacy/src/llm.ts b/legacy/src/llm.ts index c30722bb..25837b68 100644 --- a/legacy/src/llm.ts +++ b/legacy/src/llm.ts @@ -147,7 +147,7 @@ export abstract class BaseChatModelBuilder< messages.push({ role: 'system', - content: dedent`Output JSON only in the following TypeScript format: + content: dedent`Do not output code. Output JSON only in the following TypeScript format: \`\`\`ts ${tsTypeString} \`\`\``