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

feat: add an OpenAI function-calling experiment #2

Merged
merged 4 commits into from
Apr 15, 2024

Conversation

anandaroop
Copy link
Member

@anandaroop anandaroop commented Apr 13, 2024

This adds a first experiment, using the OpenAI Function Calling capability:

  • interpret some natural language questions about artists
  • turn them into calls to Metaphysics
  • format the results

Example:

yarn tsx src/01-function-calling/index.ts "who is trending on artsy right now?"

# or pretty print with
yarn -s tsx src/01-function-calling/index.ts "who is trending on artsy right now?" | jq

Screenshot 2024-04-15 at 10 44 40 AM

@anandaroop anandaroop self-assigned this Apr 13, 2024
@anandaroop anandaroop marked this pull request as draft April 13, 2024 01:25
@anandaroop anandaroop force-pushed the anandaroop/function-calling branch from ed0697c to 907fad6 Compare April 13, 2024 03:21
@anandaroop anandaroop force-pushed the anandaroop/function-calling branch from 907fad6 to ab91642 Compare April 15, 2024 14:37
Comment on lines +59 to +60
name: "get_artists",
description: `Get a list of artists on Artsy. Artists may be sorted chronologically by creation date, alphabetically by name, or in descending order of a popularity/trending score.`,
Copy link
Member Author

@anandaroop anandaroop Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen below this function (which is defined locally) results in a request to the MP root field artists(size: $size, sort: $sort)

Having concise but informative descriptions seems to be a factor in nudging it towards the appropriate function calls.

Comment on lines +90 to +91
name: "get_curated_artists",
description: `Get a list of curated artists on Artsy. These are artists whose works have been highlighted by Artsy curators, and may change from week to week.`,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly this result in a call to the MP root field curatedTrendingArtists(first: $size)

Comment on lines +114 to +115
model: "gpt-3.5-turbo",
temperature: 0,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model — I should try GPT-4 now that we have access.

temperature — Function calling is a case where we want determinism rather than "creativity", so a low temperature is specified here.


Context
'''
${JSON.stringify(artists, null, 2)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the null, 2 to pretty print the supplied JSON context over multiple lines — rather than compacting it into one line — after seeing the LLM misinterpret the compact version of the JSON.

A simple reliability hack noticed by others as well.

@anandaroop anandaroop marked this pull request as ready for review April 15, 2024 14:39
@anandaroop anandaroop requested review from sweir27 and mc-jones April 15, 2024 14:39
@anandaroop anandaroop assigned mc-jones and unassigned anandaroop Apr 15, 2024
description: "The number of artists to return",
default: 5,
minimum: 1,
maximum: 20,
Copy link
Contributor

@mc-jones mc-jones Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the model enforce these constraints, or could I override them via a user prompt? Something like "give me 100 curated artists".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good thought, I hadn't tried to break out of the limits here, but I just tried it now with "give me 23 trending artists"

And… it quite obediently gave me 23 results 🤦🏽‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Speaks to the importance of validating the function call signature before actually doing anything with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@mc-jones mc-jones merged commit 45e038e into main Apr 15, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants