From 125e0dffc6012c8eb53f4654f5e8a25423e647cb Mon Sep 17 00:00:00 2001 From: David Zhang Date: Tue, 5 Dec 2023 12:57:26 -0800 Subject: [PATCH] updated to latest version of llm-api that supports tool use --- package.json | 6 +++--- playground.ts | 4 ++-- src/completion.ts | 22 ++++++++++++++++------ src/types.ts | 4 ++++ yarn.lock | 12 ++++++------ 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index e81abcb..ed6b1b9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zod-gpt", "description": "Get structured, fully typed JSON outputs from OpenAI's new 0613 models via functions", - "version": "0.10.1", + "version": "0.11.0", "packageManager": "yarn@3.4.1", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", @@ -51,7 +51,7 @@ "zod-to-json-schema": "^3.21.4" }, "peerDependencies": { - "llm-api": "^1.0.1", + "llm-api": "^1.1.1", "zod": "^3.22.4" }, "devDependencies": { @@ -68,7 +68,7 @@ "husky": "^8.0.2", "jest": "^29.7.0", "lint-staged": "^13.2.0", - "llm-api": "^1.0.0", + "llm-api": "^1.1.1", "prettier": "^2.8.0", "ts-jest": "^29.1.1", "ts-node": "^10.9.1", diff --git a/playground.ts b/playground.ts index 67ad7f6..ae74a2b 100644 --- a/playground.ts +++ b/playground.ts @@ -19,7 +19,7 @@ import { completion } from './src'; { apiKey: process.env.OPENAI_KEY ?? 'YOUR_client_KEY', }, - { contextSize: 4096, model: 'gpt-3.5-turbo-0613' }, + { contextSize: 4096, model: 'gpt-4-1106-preview' }, ); } else if (process.env.ANTHROPIC_KEY) { client = new AnthropicChatApi( @@ -103,7 +103,7 @@ import { completion } from './src'; ); console.info('Response 4:', resBulletPoints.data); - const resBuletPoints2 = await resBulletPoints.respond('Generate 4 more'); + const resBuletPoints2 = await resBulletPoints.respond('Generate 10 more'); console.info('Response 4R:', resBuletPoints2.data); const resMessageHistory = await completion( diff --git a/src/completion.ts b/src/completion.ts index b08c933..f875e92 100644 --- a/src/completion.ts +++ b/src/completion.ts @@ -13,7 +13,7 @@ import { debug, parseUnsafeJson, zodToJsonSchema } from './utils'; const FunctionName = 'print'; const FunctionDescription = - 'ALWAYS respond by calling this function with the given parameters'; + 'Respond by calling this function with the correct parameters.'; const Defaults = { autoHeal: true, @@ -43,12 +43,14 @@ export async function chat( const opt = defaults( { // build function to call if schema is defined - callFunction: _opt?.schema ? FunctionName : undefined, + callFunction: _opt?.schema + ? _opt.functionName ?? FunctionName + : undefined, functions: _opt?.schema ? [ { - name: FunctionName, - description: FunctionDescription, + name: _opt.functionName ?? FunctionName, + description: _opt.functionDescription ?? FunctionDescription, parameters: jsonSchema, }, ] @@ -138,7 +140,11 @@ export async function chat( ...messages, response.message, typeof message === 'string' - ? { role: 'user', content: message } + ? { + role: 'tool', + toolCallId: response.toolCallId, + content: message, + } : message, ], opt ?? _opt, @@ -184,7 +190,11 @@ export async function chat( ...messages, response.message, typeof message === 'string' - ? { role: 'user', content: message } + ? { + role: 'tool', + toolCallId: response.toolCallId, + content: message, + } : message, ], opt ?? _opt, diff --git a/src/types.ts b/src/types.ts index cdf66b8..5276898 100644 --- a/src/types.ts +++ b/src/types.ts @@ -9,6 +9,10 @@ export type RequestOptions = Omit< // set a zod schema to enable JSON output schema?: T; + // override default function name and description used to print outputs + functionName?: string; + functionDescription?: string; + // set to enable automatically slicing the prompt on token overflow. prompt will be sliced starting from the last character // default: false autoSlice?: boolean; diff --git a/yarn.lock b/yarn.lock index 1bf111f..9afab4b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5542,9 +5542,9 @@ __metadata: languageName: node linkType: hard -"llm-api@npm:^1.0.0": - version: 1.0.0 - resolution: "llm-api@npm:1.0.0" +"llm-api@npm:^1.1.1": + version: 1.1.1 + resolution: "llm-api@npm:1.1.1" dependencies: "@anthropic-ai/sdk": ^0.8.1 "@aws-sdk/client-bedrock-runtime": ^3.427.0 @@ -5555,7 +5555,7 @@ __metadata: lodash: ^4.17.21 openai: ^4.20.0 type-fest: ^4.6.0 - checksum: ceb3c48956435d2de269fd5bc9db6beefd9c548724f2326b74163ca46b677fb44df8a4a4e3d68f6b5481e63ec2a81cc10af1578912e4a905a68ad2a412ef3d0a + checksum: 978d39b589ad5b397b84aed1f63d83c40845125b244eb126aa746ad6adf75767c4a8b950a9eab5a49d68a8265c521d34bc36b9f762be643f2fc7e29f649d353f languageName: node linkType: hard @@ -7640,7 +7640,7 @@ __metadata: jsonic: ^1.0.1 jsonrepair: ^3.4.0 lint-staged: ^13.2.0 - llm-api: ^1.0.0 + llm-api: ^1.1.1 lodash: ^4.17.21 prettier: ^2.8.0 ts-jest: ^29.1.1 @@ -7650,7 +7650,7 @@ __metadata: zod: ^3.22.4 zod-to-json-schema: ^3.21.4 peerDependencies: - llm-api: ^1.0.1 + llm-api: ^1.1.1 zod: ^3.22.4 languageName: unknown linkType: soft