Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
Joshua-Shepherd opened this issue Dec 1, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@Joshua-Shepherd
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • 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 Joshua-Shepherd added the bug Something isn't working label Dec 1, 2023
SkyHustle added a commit to SkyHustle/openai-node that referenced this issue Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant