Skip to content

Commit

Permalink
updated to latest version of llm-api that supports tool use
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhng committed Dec 5, 2023
1 parent f820222 commit 125e0df
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
22 changes: 16 additions & 6 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -43,12 +43,14 @@ export async function chat<T extends z.ZodType = z.ZodString>(
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,
},
]
Expand Down Expand Up @@ -138,7 +140,11 @@ export async function chat<T extends z.ZodType = z.ZodString>(
...messages,
response.message,
typeof message === 'string'
? { role: 'user', content: message }
? {
role: 'tool',
toolCallId: response.toolCallId,
content: message,
}
: message,
],
opt ?? _opt,
Expand Down Expand Up @@ -184,7 +190,11 @@ export async function chat<T extends z.ZodType = z.ZodString>(
...messages,
response.message,
typeof message === 'string'
? { role: 'user', content: message }
? {
role: 'tool',
toolCallId: response.toolCallId,
content: message,
}
: message,
],
opt ?? _opt,
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export type RequestOptions<T extends z.ZodType> = 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;
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 125e0df

Please sign in to comment.