Api.Gate.AiAssistantService 1.0.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package Api.Gate.AiAssistantService --version 1.0.8
                    
NuGet\Install-Package Api.Gate.AiAssistantService -Version 1.0.8
                    
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="Api.Gate.AiAssistantService" Version="1.0.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Api.Gate.AiAssistantService" Version="1.0.8" />
                    
Directory.Packages.props
<PackageReference Include="Api.Gate.AiAssistantService" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Api.Gate.AiAssistantService --version 1.0.8
                    
#r "nuget: Api.Gate.AiAssistantService, 1.0.8"
                    
#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.
#:package Api.Gate.AiAssistantService@1.0.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Api.Gate.AiAssistantService&version=1.0.8
                    
Install as a Cake Addin
#tool nuget:?package=Api.Gate.AiAssistantService&version=1.0.8
                    
Install as a Cake Tool

Api.Gate.AiAssistant

A simple C# .NET client library for AiAssistanService of company advancevauxhall.co.uk.This library facilitates seamless connection to corporate business chatbot via their RESTful API.

Description of the service The AiAssistantService allows users to engage in conversations based on pre-defined topics. During the conversation process, key data is collected. The outcome of the conversation depends on the targeted topic. In most cases, the result of the conversation involves issuing a service order.

For example: Example Image

Requirements

  • This library targets .NET 6.0 and above.
  • It should work across console apps, winforms, wpf, asp.net, etc.
  • It should also work across Windows, Linux, and Mac.

Getting started

Install from NuGet Install package Api.Gate.AiAssistantService from Nuget. Here's how via command line:

AI Conversation The general algorithm of working with the dialogs service is reduced to the following steps:

  1. Authentication API.
  2. Create a dialog object with a given topic.
  3. Add event handlers if it is necessary
  4. Pass the user's phrase to the dialog, get an answer from the AI. If necessary, use additional functions: Add a phrase to the dialog, Continue the dialog, Update the last phrase in the dialog, Get the dialog lines

Authentication API

   static IAiAssistantConversation _conversation;

   static async Task Main(string[] args)
   {
      var api = new ApiAiAssistantService(_base_url);
   }

_base_url = path to api of .../aiassistantgate/ url

Create a dialog object with a given topic.

    var api = new ApiAiAssistantService(_base_url);
    var bExists = await api.IsConversationExistsAsync(_conversationId);
       if (bExists)
       {
        _conversation = await api.GetConversationAsync(_conversationId);
       }
       else
       {      
           _conversation = await api.CreateConversationAsync(_conversationTopicCode, _conversationId);
       }

_conversationTopicCode - this code of topic from script editor _conversationId - unique id of conversation

Add event handlers. The conversation object supports events of two types: OnTopicChanged and OnConversationEnded. Both classes inherit from the EventDto class and have the following payload structure: Event OnTopicChanged has next structure:

     public class ConversationTopicChangedEventDto : BaseEventPayload
{
    public int PrevTopicId { get; set; }
    public int CurrentTopicId { get; set; }
    public Dictionary<string, string> Variables { get; set; } // A set of key information collected in the dialogue at the current point in time
}

Event OnConversationEnded has next structure:

   public class ConversationEndedEventDto : BaseEventPayload
{
    public int TopicId { get; set; }
    public DateTime FinishDate { get; set; }
    public Dictionary<string, string> Variables { get; set; } // A set of key information collected in the dialogue at the current point in time
}

Add event handlers.

     // add event handler OnTopicChanged
     _conversation.OnTopicChanged += (sender, e) =>
     {
        Console.WriteLine("Topic changed from " + e.EventDto.PrevTopicId + " to " + e.EventDto.CurrentTopicId);
     };
    // add event handler OnConversationEnded
    _conversation.OnConversationEnded += (sender, e) =>
    {
        Console.WriteLine("Conversation ended");
    };

Alternative work with events In addition to the method of working with events through the event model, can be used the method FetchEventAsync. In this case you should after got ai replica check event exists by method FetchEventAsync

     _conversation = await api.CreateConversationAsync(_conversationTopicCode, _conversationId,false);
       Console.Write("user:");
       string phrase = Console.ReadLine();
       phrase = phrase.Replace("user:", "");
       UserSayResponse response = await _conversation.UserSayAsync(phrase);
       Console.WriteLine("ai:" + response.AssistantPhrase);
               
       var aiEvent= await _conversation.FetchEventAsync();
           if(aiEvent!=null)
               {
                   Console.WriteLine("ai event:" + aiEvent.EventType.ToString());
               }

Pass the user's phrase to the dialog, get an answer from the AI.

    UserSayResponse response = await _conversation.UserSayAsync("HI there");

Add a phrase to the dialog.

    await _conversation.AddPhraseAsync(CONVERSATION_MEMBER_ROLE.AI, "new AI phrase");

Update last phrase of dialog.

    await _conversation.UpdateLastPhraseAsync(CONVERSATION_MEMBER_ROLE.AI, "update AI phrase");

Continue exists dialog This function uses when exist some dialog and client want to get new version of answer from AI to last replica of user.

     UserSayResponse p=await _conversation.CompleteConversationAsync(_conversationId);
     Console.WriteLine(p.AssistantPhrase);

CopyWriterService The copyright service is a separate function that allows you to generate advertising messages about the sale of cars from a database campaign advancevauxhall.co.uk The function can be accessed either directly or through the functionality of the package.

Generate advitersment by HTTP request You can generate an ad based on records from the database by executing a get request at: #path to api of advancevauxhall#/aiassistantgate/writeadvertisement/?topiccode=112&platenumber= ce67pmu

Generate advitersment by API

    var copyWriterService = new CopyWriterService(baseUrl); 
    string ad = await copyWriterService.MakeAdvertisment(topicCode, plateNumber);
    Console.WriteLine(ad);

topicCode - it is child codes from topic 'Advertising' of topic editor

General Remarks

The package includes custom 'Business Exception' types, which arise when there are flaws in the operational business logic. For instance, scenarios like 'Non-existent conversation topic' or 'Unavailable conversation ID' can trigger these exceptions.

    public async Task Run()
        {
            try
            {
                string plate = InputPalteNumber();
                var ad = await _api.MakeAdvertisment(_topicCode, plate);
                Console.WriteLine(ad);
                await Run();
            }
            catch (BusinessException e)
            {
                Console.WriteLine(e.Info);                
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());                
            }
        }
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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.2 194 9/20/2024
1.2.1 164 8/27/2024
1.2.0 166 7/2/2024
1.1.9 179 5/29/2024
1.1.8 148 5/23/2024
1.1.7 164 4/19/2024
1.1.6 162 2/19/2024
1.1.5 152 2/16/2024
1.1.2 328 10/26/2023
1.1.1 175 10/19/2023
1.0.9 219 10/6/2023
1.0.8 206 8/31/2023
1.0.7 191 8/31/2023
1.0.6 213 8/29/2023
1.0.5 217 8/11/2023
1.0.4 226 8/10/2023
1.0.3 262 7/17/2023
1.0.2 241 7/10/2023
1.0.1 257 7/9/2023
1.0.0 246 7/9/2023