GptInvoke 1.2.23041110
See the version list below for details.
dotnet add package GptInvoke --version 1.2.23041110
NuGet\Install-Package GptInvoke -Version 1.2.23041110
<PackageReference Include="GptInvoke" Version="1.2.23041110" />
paket add GptInvoke --version 1.2.23041110
#r "nuget: GptInvoke, 1.2.23041110"
// Install GptInvoke as a Cake Addin #addin nuget:?package=GptInvoke&version=1.2.23041110 // Install GptInvoke as a Cake Tool #tool nuget:?package=GptInvoke&version=1.2.23041110
Custom Service Invocation with ChatGPT
This package allows you to easily integrate ChatGPT with your custom service execution, such as invoking webhooks or performing actions within your application.
Table of Contents
Installation
To install the GptInvoke package, run the following command in the Package Manager Console:
Install-Package GptInvoke
or add the Package reference like this
<PackageReference Include="GptInvoke" Version="*" />
Service Registration
To register the necessary services, add the following code in your Program.cs
file:
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging => logging.ClearProviders())
.ConfigureServices(services => services.AddGptActionInvoker("YOUR-API-KEY"))
.Build();
You can also specify settings for the action, like this:
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureLogging(logging => logging.ClearProviders())
.ConfigureServices(services => services.AddGptActionInvoker(s =>
{
s.ApiKey = "API-KEY";
s.Model = Model.GPT4;
}))
.Build();
Service Implementation
To implement a custom service, create a new class that implements the IGptInvokableService
interface:
public interface IGptInvokableService
{
public string Name { get; }
public string Description { get; }
public GptInvokableServiceParameter[] Parameters { get; }
public Task<bool> ExecuteAsync(IDictionary<string, object> parameters);
}
Sample implementation:
public class MyClockService : IGptInvokableService
{
public string Name { get; set; } = "Alarm clock service";
public string Description { get; set; } = "I can set up an alarm clock";
public GptInvokableServiceParameter[] Parameters => new []
{
new GptInvokableServiceParameter("DateTime", "Target time to set alarm for", typeof(DateTime), true)
};
public Task<bool> ExecuteAsync(IDictionary<string, object> parameters)
{
var value = parameters.First().Value;
var dt = value is DateTime time ? time : DateTime.Parse(value.ToString());
var color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"HELLO from {GetType()} I created a new alarm at {dt}");
Console.ForegroundColor = color;
return Task.FromResult(true);
}
}
public class MyProductService : IGptInvokableService
{
public string Name { get; set; } = "Add Product service";
public string Description { get; set; } = "I can add products";
public GptInvokableServiceParameter[] Parameters => new[]
{
new GptInvokableServiceParameter("Name", "Name of the product to add", typeof(string), true),
new GptInvokableServiceParameter("Barcode", "Barcode of product", typeof(string), true)
};
public Task<bool> ExecuteAsync(IDictionary<string, object> parameters)
{
var name = parameters["Name"].ToString();
var barcode = parameters["Barcode"].ToString();
var color = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"HELLO from {GetType()} I created a new Product with the Name {name} and the Barcode {barcode}");
Console.ForegroundColor = color;
return Task.FromResult(true);
}
}
Services can then invoked like this
Invocation
To use the IGptActionInvoker
, add the following code to your application:
var commander = host.Services.GetRequiredService<IGptActionInvoker>();
Console.WriteLine("How can I assist you?");
while (true)
{
var userCommand = Console.ReadLine();
if (!string.IsNullOrEmpty(userCommand))
{
var res = await commander.PromptAsync(userCommand);
res.Switch(Console.WriteLine, _ => Console.WriteLine("####################################" + Environment.NewLine));
}
}
The PromptAsync
method returns a OneOf<string, GptServiceResult>
object. If the result is a GptServiceResult
, the service has been invoked and you will receive the following class:
public class GptServiceResult
{
public string Service { get; set; }
public string Type { get; set; }
public KeyValuePair<string, object>[] Parameters { get; set; }
public bool Successful { get; set; }
public IGptInvokableService UsedService { get; set; }
}
Now you have all the necessary information to start using GptInvoke in your projects. Simply follow the instructions for installation, service registration, service implementation, and invocation to integrate ChatGPT with your custom service execution.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- Nextended.Core (>= 7.0.21)
- OneOf (>= 3.0.243)
- OpenAI-DotNet (>= 6.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.24121212 | 122 | 12/12/2024 |
1.2.24121211 | 79 | 12/12/2024 |
1.2.23050509 | 230 | 5/5/2023 |
1.2.23050212 | 178 | 5/2/2023 |
1.2.23050211 | 180 | 5/2/2023 |
1.2.23043011 | 192 | 4/30/2023 |
1.2.23041212 | 196 | 4/12/2023 |
1.2.23041210 | 200 | 4/12/2023 |
1.2.23041110 | 205 | 4/11/2023 |
1.2.23040617 | 218 | 4/6/2023 |