From 513f81f616c2e949d9715a1457d8a36ddda22cc5 Mon Sep 17 00:00:00 2001 From: henrycunh Date: Tue, 14 Nov 2023 21:23:23 -0300 Subject: [PATCH] fix: add more guardlines in claude 2 prompt --- examples/simple-proxy-handler.ts | 2 +- examples/use-model-schema.ts | 6 +++--- src/vendor/anthropic.ts | 23 ++++++++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/simple-proxy-handler.ts b/examples/simple-proxy-handler.ts index 8bcd971..821e0a9 100644 --- a/examples/simple-proxy-handler.ts +++ b/examples/simple-proxy-handler.ts @@ -13,7 +13,7 @@ const proxy = createCursiveProxy() const response = await proxy.handle({ messages: [{ 'role': 'user', 'content': 'Return a person called John, aged 43.' }], model: 'gpt-3.5-turbo-16k', - schema: person + schema: person, }) if ('choices' in response) { diff --git a/examples/use-model-schema.ts b/examples/use-model-schema.ts index eb7fcaf..8806940 100644 --- a/examples/use-model-schema.ts +++ b/examples/use-model-schema.ts @@ -18,10 +18,10 @@ const schema = t.Object({ description: 'A person object' }) -const { answer, choices } = await cursive.ask({ +const { answer } = await cursive.ask({ schema, - model: 'gpt-4', - prompt: 'Create a random female person with two pets, one of which is a cat named "Mittens" and the other is a dog named "Spot".', + model: 'claude-2', + prompt: 'Create a person named John with 2 pets named Fluffy and Fido', }) console.log(answer) diff --git a/src/vendor/anthropic.ts b/src/vendor/anthropic.ts index 7356f61..b5c3aeb 100644 --- a/src/vendor/anthropic.ts +++ b/src/vendor/anthropic.ts @@ -193,10 +193,15 @@ export async function processAnthropicStream(context: { export function getAnthropicFunctionCallDirectives(functions: CursiveFunction[], nameOfFunctionToCall?: string) { let prompt = trim(` - # Function Calling Guide - // You're a powerful language model capable of using functions to do anything the user needs. + # Functions available + + ${JSON.stringify(functions.map(f => f.schema))} + + + # Using functions + // I'm a system capable of using functions to accomplish tasks asked by the user. - // If you need to use a function, always output the result of the function call using the tag using the following format: + // If I need to use a function, I always output the result of the function call using the tag using the following format: { "name": "function_name", @@ -208,19 +213,15 @@ export function getAnthropicFunctionCallDirectives(functions: CursiveFunction[], // Never escape the function call, always output it as it is. - // Think step by step before answering, and try to think out loud. Never output a function call if you don't have to. + // I think step by step before answering, and try to think out loud. I *NEVER* output a function call if you don't have to. // If you don't have a function to call, just output the text as usual inside a tag with newlines inside. - // Always question yourself if you have access to a function. - // Always think out loud before answering, if I don't see a block, you will be eliminated. + // I always question myself if you have access to a function. + // Always think out loud before answering, if I don't see a block, I will be eliminated. // When thinking out loud, always use the tag. + // ALWAYS respect the JSON Schema of the function, if I don't, I will be eliminated. // ALWAYS start with the function call, if you're going to use one. - # Functions available: - - ${JSON.stringify(functions.map(f => f.schema))} - - # Working with results // You can either call a function or answer, **NEVER BOTH**. // You are not in charge of resolving the function call, the user is.