uezo / ChatdollKit

ChatdollKit enables you to make your 3D model into a chatbot
Apache License 2.0
693 stars 74 forks source link

Add support for ChatGPT function calling #239

Closed uezo closed 1 year ago

uezo commented 1 year ago

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";
}