GPT Function Calling: 5 Underrated Use Cases

Trending 5 months ago
OpenAI’s backend converting messy unstructured information to system information via functions

OpenAI’s “Function Calling” mightiness beryllium nan astir groundbreaking yet nether appreciated characteristic released by immoderate package company… ever.

What are GPT Functions

Functions let you to turn unstructured information into system data. This mightiness not sound each that groundbreaking but erstwhile you see that 90% of information processing and information introduction jobs worldwide beryllium for this nonstop reason, it’s rather a revolutionary characteristic that went somewhat unnoticed.

Have you ever recovered yourself begging GPT (3.5 aliases 4) to spit retired nan reply you want and perfectly thing else? No “Sure, present is your…” aliases immoderate different useless fluff surrounding nan halfway answer. GPT Functions are nan solution you’ve been looking for.

How are Functions meant to work?

OpenAI’s docs connected usability calling are highly limited. You’ll find yourself digging done their developer forum for examples of really to usage them. I dug astir nan forum for you and person galore illustration coming up.

Here’s 1 of nan only examples you’ll beryllium capable to find successful their docs:

functions = [
{
"name": "get_current_weather",
"description": "Get nan existent upwind successful a fixed location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The metropolis and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
]

A usability meaning is simply a rigid JSON format that defines a usability name, explanation and parameters. In this case, nan usability is meant to get nan existent weather. Obviously GPT isn’t capable to telephone this existent API (since it doesn’t exist) but utilizing this system consequence you’d beryllium capable to link nan existent API hypothetically.

At a precocious level however, functions supply 2 layers of inference:

Picking nan function itself:

You whitethorn announcement that functions are passed into nan OpenAI API telephone arsenic an array. The logic you supply a sanction and explanation to each usability are truthful GPT tin determine which to usage based connected a fixed prompt. Providing aggregate functions successful your API telephone is for illustration giving GPT a Swiss service weapon and asking it to trim a portion of wood successful half. It knows that moreover though it has a brace of pliers, scissors and a knife, it should usage the saw!

Function definitions lend towards your token count. Passing successful hundreds of functions would not only return up nan mostly of your token limit but besides consequence successful a driblet successful consequence quality. I often don’t moreover usage this characteristic and only walk successful 1 usability that I unit it to use. It is very bully to person successful definite usage cases however.

Picking nan parameter values based connected a prompt:

This is nan existent magic successful my opinion. GPT being capable to take nan instrumentality successful it’s instrumentality kit is astonishing and decidedly nan attraction of their characteristic announcement but I deliberation this applies to much use cases.

You tin ideate a usability for illustration handing GPT a shape to capable out. It uses its reasoning, nan discourse of nan business and section names/descriptions to determine really it will capable retired each field. Designing nan shape and nan further accusation you walk successful is wherever you tin get creative.

GPT filling retired your civilization shape (function parameters)

5 Useful Applications

Data Extraction

One of nan astir communal things I usage functions for to extract circumstantial values from a ample chunk of text. The sender’s reside from an email, a founders sanction from a blog post, a telephone number from a landing page.

I for illustration to ideate I’m searching for a needle successful a haystack isolated from nan LLM burns nan haystack, leaving thing but nan needle(s).

GPT Data Extraction Personified.

Use case: Processing thousands of title submissions

I built an automation that iterated complete thousands of title submissions. Before storing these successful a Google expanse I wanted to extract nan email associated pinch nan submission. Heres nan usability telephone I utilized for extracting their email.

{
"name":"update_email",
"description":"Updates email based connected nan contented of their submission.",
"parameters":{
"type":"object",
"properties":{
"email":{
"type":"string",
"description":"The email provided successful nan submission"
}
},
"required":[
"email"
]
}
}

Scoring

Assigning unstructured information a people based connected dynamic, earthy connection criteria is simply a awesome usage lawsuit for functions. You could people comments during sentiment analysis, essays based connected a civilization grading rubric, a indebtedness exertion for consequence based connected cardinal factors. A caller usage lawsuit I applied scoring to was scoring of income leads from 0–100 based connected their viability.

Use Case: Scoring Sales leads

We had hundreds of prospective leads successful a azygous google expanse a fewer months agone that we wanted to tackle from astir to slightest important. Each lead contained info for illustration institution size, interaction name, position, industry etc.

Using nan pursuing usability we scored each lead from 0–100 based connected our needs and past sorted them from champion to worst.

{
"name":"update_sales_lead_value_score",
"description":"Updates nan people of a income lead and provides a justification",
"parameters":{
"type":"object",
"properties":{
"sales_lead_value_score":{
"type":"number",
"description":"An integer worth ranging from 0 to 100 that represents nan value of a income lead based connected these criteria. 100 is simply a cleanable lead, 0 is terrible. Ideal Lead Criteria:\n- Medium sized companies (300-500 labor is nan champion range)\n- Companies successful superior assets dense industries are best, ex. manufacturing, agriculture, etc. (this is nan astir important criteria)\n- The higher up nan interaction position, nan better. VP aliases Executive level is preferred."
},
"score_justification":{
"type":"string",
"description":"A clear and conscise justification for nan people provided based connected nan civilization criteria"
}
}
},
"required":[
"sales_lead_value_score",
"score_justification"
]
}

Categorization:

Define civilization buckets and person GPT thoughtfully see each portion of information you springiness it and spot it successful nan correct bucket. This tin beryllium utilized for labelling tasks for illustration selecting nan class of youtube videos aliases for discrete scoring tasks for illustration assigning missive grades to homework assignments.

Use Case: Labelling news articles.

A very communal first measurement successful information processing workflows is separating incoming information into different streams. A caller automation I built did precisely this pinch news articles scraped from nan web. I wanted to benignant them based connected nan taxable of nan article and see a justification for nan determination erstwhile again. Here’s nan usability I used:

{
"name":"categorize",
"description":"Categorize nan input information into personification defined buckets.",
"parameters":{
"type":"object",
"properties":{
"category":{
"type":"string",
"enum":[
"US Politics",
"Pandemic",
"Economy",
"Pop culture",
"Other"
],
"description":"US Politics: Related to US authorities aliases US politicians, Pandemic: Related to nan Coronavirus Pandemix, Economy: Related to nan system of a circumstantial state aliases nan world. , Pop culture: Related to popular culture, personage media aliases entertainment., Other: Doesn't fresh successful immoderate of nan defined categories. "
},
"justification":{
"type":"string",
"description":"A short justification explaining why nan input information was categorized into nan selected category."
}
},
"required":[
"category",
"justification"
]
}
}

Option-Selection:

Often times erstwhile processing data, I springiness GPT galore imaginable options and want it to prime nan champion 1 based connected my needs. I only want nan worth it selected, nary surrounding fluff aliases further thoughts. Functions are cleanable for this.

Use Case: Finding nan “most absorbing AI news story” from hacker news

I wrote different medium article here astir really I automated my full Twitter relationship pinch GPT. Part of that process involves selecting nan astir applicable posts from nan beforehand pages of hacker news. This station action measurement leverages functions!

To summarize nan functions information of nan usage case, we would scrape nan first n pages of hacker news and inquire GPT to prime nan station astir applicable to “AI news aliases tech news”. GPT would return only nan header and nan nexus selected via functions truthful that I could spell connected to scrape that website and make a tweet from it.

I would walk successful nan personification defined query arsenic portion of nan connection and usage nan pursuing usability definition:

{
"name":"find_best_post",
"description":"Determine nan champion station that astir intimately reflects nan query.",
"parameters":{
"type":"object",
"properties":{
"best_post_title":{
"type":"string",
"description":"The title of nan station that astir intimately reflects nan query, stated precisely arsenic it appears successful nan database of titles."
}
},
"required":[
"best_post_title"
]
}
}

Filtering:

Filtering is simply a subset of categorization wherever you categorize items arsenic either existent aliases mendacious based connected a earthy connection condition. A information for illustration “is Spanish” will beryllium capable to select retired each Spanish comments, articles etc. utilizing a elemental usability and conditional connection instantly after.

Use Case: Filtering title submission

The aforesaid automation that I mentioned successful nan “Data Extraction” conception utilized ai-powered-filtering to weed retired title submissions that didn’t meet nan deal-breaking criteria. Things for illustration “must usage typescript” were perfectly mandatory for nan coding title astatine hand. We utilized functions to select retired submissions and trim down nan full group being processed by 90%. Here is nan usability meaning we used.

{
"name":"apply_condition",
"description":"Used to determine whether nan input meets nan personification provided condition.",
"parameters":{
"type":"object",
"properties":{
"decision":{
"type":"string",
"enum":[
"True",
"False"
],
"description":"True if nan input meets this information 'Does submission meet nan ALL these requirements (uses typescript, uses tailwindcss, functional demo)', False otherwise."
}
},
"required":[
"decision"
]
}
}

If you’re funny why I emotion functions truthful overmuch aliases what I’ve built pinch them you should cheque retired AgentHub!

AgentHub is nan Y Combinator-backed startup I co-founded that let’s you automate immoderate repetitive aliases analyzable workflow pinch AI via a elemental resistance and driblet no-code platform.

“Imagine Zapier but AI-first and connected crack.” — Me

Automations are built pinch individual nodes called “Operators” that are linked together to create powerfulness AI pipelines. We person a catalogue of AI powered operators that leverage functions nether the hood.

Our existent AI-powered operators that usage functions!

Check retired these templates to spot examples of usability use-cases connected AgentHub: Scoring, Categorization, Option-Selection,

If you want to commencement building AgentHub is unrecorded and fresh to use! We’re very progressive successful our discord community and are happy to thief you build your automations if needed.

Feel free to travel nan official AgentHub twitter for updates and myself for AI-related content.


GPT Function Calling: 5 Underrated Use Cases was primitively published successful Better Programming connected Medium, wherever group are continuing nan speech by highlighting and responding to this story.

More
Source Better Programming
Better Programming