1. What you program:
system: “You are a chat bot. Your pretrained knowledge cuts off at September 2021. You’re gonna need to use the internet to find newer information.”
function_list=[
{
"name": "google_for_answers",
"description": "Search Google for more information, receiving back top result summaries.",
"parameters": {
"type": "object",
"properties": {
"query": {
"type": "string",
}
}
}
}
]
2. What the user inputs:
What movie won the 2022 Oscar for best picture?
3. What the AI outputs, a “function_call”
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "google_for_answers",
"arguments": "{\n \"query\": \"2022 Oscar winner for best picture\"\n}"
}
},
"finish_reason": "function_call"
}
4. Do what the AI wants. Return the results in a new role:
Long code including the text from the Google API you used
function_return=“”"
Oscars 2022 Winners: See the Full List Here (Updated)
Vanity Fair
https://www.vanityfair.com › Hollywood › awards
Mar 28, 2022 — CODA wins best picture, Jessica Chastain takes best actress, and Will Smith nabs best actor at a thoroughly unpredictable Oscars.
94th Academy Awards
Wikipedia
https://en.wikipedia.org › wiki
CODA won three awards, including Best Picture. Other winners included Dune … In July 2022, the broadcast was nominated for three awards at the 74th …
Winners and nominees · Awards · Ceremony information · Critical reviews
Oscars 2022: the full list of winners
The Guardian
https://www.theguardian.com › film › 2022 › mar
Mar 29, 2022 — Best actress. Jessica Chastain (The Eyes of Tammy Faye) – WINNER! Olivia Colman (The Lost Daughter) Penélope Cruz (Parallel Mothers)
2022 Oscars winners full list, CODA wins best picture
Los Angeles Times
https://www.latimes.com › awards › story › 2022-03-27
Mar 27, 2022 — The complete list of 2022 Oscar winners … Will Smith holds his Oscar for best actor for “King Richard” during the show at the 94th Academy …
Oscars 2022: ‘CODA’ wins best picture, but Will Smith slap …
ABC7 Los Angeles
https://abc7.com › oscars-2022-oscar-winners-will-smith-…
Mar 28, 2022 — “CODA” was named best picture after one of the most shocking moments in Oscars history: Will Smith slapped Chris Rock onstage.
“”".strip()
response = openai.ChatCompletion.create(
messages=[{“role”: “system”, “content”: ("You are a chat bot. "
"Your pretrained knowledge cuts off at September 2021. "
“You’re gonna need to use the internet to find newer information.”)},
{“role”: “user”, “content”: “What movie won the 2022 Oscar for best picture?”},
{“role”: “function”, “name”: “google_for_answers”,
“content”: function_return}],
model=“gpt-3.5-turbo”, max_tokens=200, temperature=0.2, functions=function_list)
5. The AI now decides to answer instead of calling more functions:
{
"index": 0,
"message": {
"role": "assistant",
"content": "The movie \"CODA\" won the 2022 Oscar for Best Picture."
},
"finish_reason": "stop"
}
(actual execution of function I just ran manually)
So you are correct, there is no code provided by OpenAI to make the function magic happen. You program and provide the operational function that can “do_actual_math” or “drop_sql_tables”.