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

Add support for ChatGPT function calling #239

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

uezo
Copy link
Owner

@uezo uezo commented Jun 16, 2023

Add functions like below in Start().
In this example, GetWeatherAsync will be invoked when weather is detected as function by ChatGPT. See also ChatGPTStreamSkill.Start().

// Define function
var weatherFunction = new ChatGPTFunction("weather", "指定された地点の天気予報を調べます", functions.GetWeatherAsync);
// Add properties to function
weatherFunction.AddProperty("location", new Dictionary<string, object>()
{
    { "type", "string" }
});
// Register function
ChatGPTFunctions.Add(weatherFunction);

And, here is the example of implementation of function. See also ExampleFunctions.cs.

public async UniTask<string> DoSomethingAsync(string jsonString, CancellationToken token)
{
    // Parse arguments
    var funcArgs = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);

    // Do something

    // This message will be sent to ChatGPT again to convert human-friendly response
    return "Do something: success";
}

Add functions like below in `Start()`.
In this example, `GetWeatherAsync` will be invoked when `weather` is detected as function by ChatGPT.
See also `ChatGPTStreamSkill.Start()`.

```csharp
// Define function
var weatherFunction = new ChatGPTFunction("weather", "指定された地点の天気予報を調べます", functions.GetWeatherAsync);
// Add properties to function
weatherFunction.AddProperty("location", new Dictionary<string, object>()
{
    { "type", "string" }
});
// Register function
ChatGPTFunctions.Add(weatherFunction);
```

And, here is the example of implementation of function. See also ExampleFunctions.cs.

```csharp
public async UniTask<string> DoSomethingAsync(string jsonString, CancellationToken token)
{
    // Parse arguments
    var funcArgs = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);

    // Do something

    return "Notify user that I do something.";
}
```
@uezo uezo merged commit 944f9fa into master Jun 16, 2023
@uezo uezo deleted the feature-chatgpt-function-calling branch June 16, 2023 12:31
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.

None yet

1 participant