GptInvoke 1.2.23050509

dotnet add package GptInvoke --version 1.2.23050509                
NuGet\Install-Package GptInvoke -Version 1.2.23050509                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GptInvoke" Version="1.2.23050509" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GptInvoke --version 1.2.23050509                
#r "nuget: GptInvoke, 1.2.23050509"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GptInvoke as a Cake Addin
#addin nuget:?package=GptInvoke&version=1.2.23050509

// Install GptInvoke as a Cake Tool
#tool nuget:?package=GptInvoke&version=1.2.23050509                

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.

With this package you can achieve very easially something like this SAMPLE https://raw.githubusercontent.com/fgilde/GptInvoke/main/GptInvoke/screenshots/video.mkv

GitHub NuGet

If you like this package, please star it on GitHub and share it with your friends If not, you can give a star anyway and let me know what I can improve to make it better for you.

<hr/>

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 easially invoked. For example in a Console Prompt or whatever you want to build on top of of.

Screenshot

Screenshot

Screenshot

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.23050509 189 5/5/2023
1.2.23050212 149 5/2/2023
1.2.23050211 152 5/2/2023
1.2.23043011 161 4/30/2023
1.2.23041212 183 4/12/2023
1.2.23041210 171 4/12/2023
1.2.23041110 176 4/11/2023
1.2.23040617 190 4/6/2023