openai-node
openai-node copied to clipboard
Automated Function Calls Readme.md example is missing required description property on function objects
Confirm this is a Node library issue and not an underlying OpenAI API issue
- [X] This is an issue with the Node library
Describe the bug
The description
property is missing in the RunnableFunctionWithParse<any>
type on both getWeather
and getCurrentLocation
.
The description property is a string that describes what the function does, and are required under any RunnableFunction
or ParsedFunction
type:
To fix this, we just simply need to add a description
property to the getWeather
and getCurrentLocation
function objects in the Readme example.
https://github.com/openai/openai-node/blob/master/README.md#automated-function-calls
To Reproduce
- Go to https://github.com/openai/openai-node/blob/master/README.md#automated-function-calls
- Copy the provided example
- Insert in any Typescript("typescript": "^5.2.2") environment to immediately see the issue | Run example in Node.js
Code snippets
import OpenAI from 'openai';
const client = new OpenAI();
async function main() {
const runner = client.beta.chat.completions
.runFunctions({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'How is the weather this week?' }],
functions: [
{
function: getCurrentLocation,
description: 'This function gets the current location.', /*missing property*/
parameters: { type: 'object', properties: {} },
},
{
function: getWeather,
parse: JSON.parse, // or use a validation library like zod for typesafe parsing.
description: 'This function gets the weather for a given location.', /*missing property*/
parameters: {
type: 'object',
properties: {
location: { type: 'string' },
},
},
},
],
})
.on('message', (message) => console.log(message));
const finalContent = await runner.finalContent();
console.log();
console.log('Final content:', finalContent);
}
async function getCurrentLocation() {
return 'Boston'; // Simulate lookup
}
async function getWeather(args: { location: string }) {
const { location } = args;
// … do lookup …
return { temperature, precipitation };
}
main();
OS
macOS
Node version
Node v21.1.0
Library version
OpenAI 4.20.1