openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

Automated Function Calls Readme.md example is missing required description property on function objects

Open Joshua-Shepherd opened this issue 1 year ago • 0 comments

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. SS-Cursor-11-30+0629PM

The description property is a string that describes what the function does, and are required under any RunnableFunction or ParsedFunction type: SS-Cursor-11-30+0638PM

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

SS-Cursor-11-30+0636PM

To Reproduce

  1. Go to https://github.com/openai/openai-node/blob/master/README.md#automated-function-calls
  2. Copy the provided example
  3. 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

Joshua-Shepherd avatar Dec 01 '23 00:12 Joshua-Shepherd