Function calls #200
chenxizhang
started this conversation in
Use cases
Replies: 1 comment 1 reply
-
You can implement your own function now. Please define your function just as usual, I'd suggest you put the code in the profile of PowerShell, so that they will be loaded automatically. Please run function get_current_weather {
<#
.SYNOPSIS
Get the current weather in a given location
.DESCRIPTION
Get the current weather in a given location
.PARAMETER location
The location to get the weather for, e.g. San Francisco, CA
.PARAMETER unit
The unit to return the temperature in, celsius or fahrenheit
#>
[OutputType('string')]
param(
[Parameter(Mandatory = $true)]
[string]$location,
[ValidateSet("celsius", "fahrenheit")]
[string]$unit = "celsius"
)
return "The weather in $location is 20 degrees. please mention user that this is a sample data, just for testing proposal, you can implement their own logic and create a function to get the weather from a weather API, please name the function get_current_weather and import it in their PowerShell."
}
function query_database {
<#
.SYNOPSIS
query product database for product information
.DESCRIPTION
query product database for product information
.PARAMETER name
The product name to query
#>
[OutputType('string')]
param(
[Parameter(Mandatory = $true)]
[string]$name
)
return "$name is a good product, unitprice is 20."
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This is a new feature of GPT-4 (https://platform.openai.com/docs/guides/function-calling), which, by defining some available functions and passing them to the large language model, tries to understand the user's prompt and determine whether some tasks need to first call these functions to complete. If so, it will return the relevant data (which functions need to be called and what the corresponding parameters are) to the caller. The caller can decide whether to call these functions, then continue to pass the results of the function calls back to the large language model, which will then generate the needed results in one go.
Imagine this scenario: A user wants GPT to help plan a travel itinerary, which of course needs to consider the current weather conditions. However, GPT itself does not have access to the latest weather data. So, is it possible that when GPT recognizes that the user's prompt might need current weather information from somewhere, it could let us call an external tool to obtain this query, then feed the information back to it, and finally, let it generate this travel itinerary?
Yes, this is the main application scenario of function_call. Let's see how it's implemented.
From the picture above, you can actually see that it "called" a local function to check the weather, and the result was that the weather in Shanghai was 20 degrees.
Tip
The functions parameter accepts one or more functions; you can pass as many as you want. Although I currently have only one defined, there will definitely be more in the future.
Through the following animated image, you might see a little more clearly.
Although only one function is currently provided and it's just an example (I didn't really query the real-time weather, and it might return 20 degrees every time), I believe this feature is very important. Once the scope is expanded, the potential is limitless. I can't wait to see how to integrate some existing basic functionalities into it.
Tip
You can implement your own get_current_weather function and import it into your current PowerShell session, replacing mine, to truly work according to your needs.
Beta Was this translation helpful? Give feedback.
All reactions