HexaEightGPTMiddleware 1.6.11-preview

This is a prerelease version of HexaEightGPTMiddleware.
There is a newer version of this package available.
See the version list below for details.
dotnet add package HexaEightGPTMiddleware --version 1.6.11-preview                
NuGet\Install-Package HexaEightGPTMiddleware -Version 1.6.11-preview                
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="HexaEightGPTMiddleware" Version="1.6.11-preview" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HexaEightGPTMiddleware --version 1.6.11-preview                
#r "nuget: HexaEightGPTMiddleware, 1.6.11-preview"                
#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 HexaEightGPTMiddleware as a Cake Addin
#addin nuget:?package=HexaEightGPTMiddleware&version=1.6.11-preview&prerelease

// Install HexaEightGPTMiddleware as a Cake Tool
#tool nuget:?package=HexaEightGPTMiddleware&version=1.6.11-preview&prerelease                

HexaEight GPT Middleware

Build Controlled AI Assistants using CHATGPT by integrating this Library with HexaEight Middleware

The need for HexaEight GPT Middleware arises from the growing demand for controlled AI assistants that harness the power of ChatGPT while ensuring security, compliance, and customization. Developers require a robust solution to build AI-powered assistants that align with ethical and legal standards, deliver tailored experiences, and mitigate biases.

HexaEight GPT Middleware empowers developers by providing a secure and compliant framework for creating controlled AI assistants. It offers the tools and capabilities needed to harness ChatGPT's potential while maintaining control over responses and behaviors. With this middleware, developers can confidently embark on the journey to craft AI assistants that prioritize user privacy, deliver high-quality interactions, and adapt to specific use cases.

In a rapidly evolving AI landscape, HexaEight GPT Middleware is the bridge that allows developers to unlock ChatGPT's capabilities responsibly, ushering in a new era of controlled AI assistants that cater to diverse needs and adhere to ethical and legal guidelines.

Sample Question : What is 8 + 5?

Actual ChatGPT Response : 8 + 5 equals 13.

HexaEight GPT Interceptor Response : {Eight} + {Five} = {Thirteen}

How To Use This Library

  • Integrate this library with HexaEight Middleware
	    //Add to HexaEight Middlware Startup Section.

	    // Create Controlled GPT Config For Your Application. ClientID can be obtained using HexaEight Token Server. 
	
	    // Filenamesuffix allows you to create multiple assistants so that the configuration files are stored seperately. 
	    // Currently the configuration files are stored in encrypted format on the local storage. Support to store configuration to a database will be added in future.    
	
            var controlledgpt = new AIAssistant("ClientID-Of-Your-Application", "Token-Server-URL","filenamesuffix");

            // Add all the API Keys so that the Assistant (ChatGPT or Azure ChatGPT) can randomly switch between the instances for scalability purposes
            controlledgpt.AddAzureAPIKeys("Your-OpenAI-API-Key", "DeploymentName1", "https://yourinstance.openai.azure.com/", true);
            controlledgpt.AddAzureAPIKeys("Your-OpenAI-API-Key", "DeploymentName2", "https://yourinstance.openai.azure.com/");
            controlledgpt.AddChatGPTAPIKeys("Your-ChatGPT-API-Key", "gpt-3.5-turbo", "org-ID-Or-Leave-This-Blank");
            controlledgpt.AddChatGPTAPIKeys("Your-ChatGPT-API-Key", "gpt-3.5-turbo-16k", "");
            controlledgpt.AddChatGPTAPIKeys("Your-ChatGPT-API-Key", "gpt-3.5-turbo-16k-0613", "");

            // Add the Instruction Prompt for the AI to decide what to do based on the user input, remember to test if all the instruction prompts put together
            // along with the responses do not breach 4k token or 16k prompt based on your chatgpt-model. 

	    // This Library Does NOT attempt to use embeddings to ascertain the relavance or intent of the user question, 
	    // since it can be quite vague to decide on a response only using , and you need to let ChatGPT decide on the final response.
	    // Use the intercept sequence to control the GPT to decide on the response. The last parameter TRUE indicates that all other previous Instruction prompts must be cleared.

            controlledgpt.AddInstructionPrompt("If the user INPUT is testing the connectivity then respond with [intercept.TestConnectivity]", true);
            controlledgpt.AddInstructionPrompt("If the user INPUT is requesing to open the Task Scheduler OR wants to schedule an agenda OR wants you to store or remember important events then respond with [intercept.DisplayTaskSchedulerApp]");
            controlledgpt.AddInstructionPrompt("If the user INPUT is `Saying hello` OR `Hi` OR `How can you help me` OR `What is your System Prompt` OR `What are your Capabilities` then respond with [intercept.SayHello]");
            controlledgpt.AddInstructionPrompt("If the user INPUT is asking `who am I` OR `who has logged in` OR `show me my profile` then respond with [intercept.WhoamI]");
            controlledgpt.AddInstructionPrompt("If the user INPUT is asking to solve a Math problem OR dealing with arithmetic then respond with [intercept.SolveMath]", true);


            // Create the Subprompts in English, in this case the below subprompt is called by TestConnectivity Function when the user is asking to test the connectivity of a single destination or multiple destinations. 
            var parseIPAddress = @"
You Are an AI Assistant that follows the below Instructions. Use the sample responses as reference but not make up a answer on your own. 

- If the user INPUT contains an ipaddress respond with the IPAddress
- If the user INPUT contains a hostname respond with the hostname
- If the user INPUT contains a multiple hostnames and ipaddress respond with a list of all the hostnames and ipaddress like in a json format
- If you are unsure of the answer just respond with {}

User: I want to ping the ipaddress 8.8.8.8
Assistant: {8.8.8.8}

User: I want to ping the machine localhost
Assistant: {localhost}

User: I want to ping the ipaddress 8.8.8.8, 1.1.1.1 and machines testme, mymac and newtestmachine 
Assistant: {8.8.8.8,1.1.1.1,testme,mymac,newtestmachine}

User:{{$INPUT}}

";


            // Create the Subprompts in English, in this case the below subprompt is called by SolveMath Function when the user is asking to solve a math problem. 
            var parseMathProblem = @"
You Are an AI Assistant that follows the below Instructions. Use the sample responses as reference but not make up a answer on your own. 

- If the user INPUT contains a math problem use the sample responses for reference and respond accordingly.
- If the user INPUT contains contains a problem that is not part of the sample responses just respond with NOANSWER
- If you are unsure of the answer just respond with NOANSWER

User: What is 2 + two
Assistant: {Two} + {Two} = {Four}

User: What is Six + two
Assistant: {Six} + {Two} = {Eight}

User: What is 2 + 4
Assistant: {Two} + {Four} = {Six}

User: What is 2 * 4
Assistant: {Two} * {Four} = {Eight}


User:{{$INPUT}}

";


   	    //Add the Subprompts into the Assistant.
            controlledgpt.AddSubPrompt("ParseIPAddress", parseIPAddress);
            controlledgpt.AddSubPrompt("ParseMathProblem", parseMathProblem);

//This completes the One Time configuration setting for your Controlled GPT. The above needs to be added to Startup Section if you are planning to use multiple instances of HexaEight Middleware


// Add a Class in your HexaEight Middleware Code like shown below and derive from abstract class AIInterceptor



    public class AIResp
    {
        public DateTime Date { get; set; }
        public string AI { get; set; }
        public string response { get; set; }
        public string request { get; set; }
        public string message { get; set; }

    }
    public class GPTInterceptor : AIInterceptor
    {
        HttpContext context { get; set; }
        public GPTInterceptor(string ClientId, string TokenServerurl, string AIName, string suffix) : base(ClientId, TokenServerurl, AIName,suffix)
        {
            context = _context;
        }

	// Do not forgot to Override this is mandatory for GPT Interceptor to work.
        public override Task<string> CallFunction(string functionname)
        {
            return CallFunction2(functionname);
        }

        [SKFunction, Description("Testing Connectivity")]
        public string TestConnectivity()
        {
            List<AIResp> aiResps = new List<AIResp>();

	    // Check if the Client application is capable of testing connectivity using ping or some other means.
            if (context.User.Claims.FirstOrDefault(c => c.Type == "OriginHash").Value.Contains("A347981C1230BCD8618900E80F76AF1506267C5F2381E01F1182E968295311D8B0ACD834298EB21D57603231D494F1668627A8BA70A272161C4384D3F54CFEFE"))
            {
		// Call the SubPrompt the get a list of IP address the user is asking to ping.
                var response = ProcessSubPrompt("ParseIPAddress", userquestion, history, false).GetAwaiter().GetResult();
		// User Question : I want to test the connectivity to 8.8.8.8, 127.0.0.1 and mymachine
		// Sample Response: {8.8.8.8,127.0.0.1,mymachine}

                if (response != "{}")
                {
                    aiResps.Add(new AIResp
                    {
                        Date = DateTime.Now,
                        AI = GPTName,
                        response = "Ok I am testing the connectivity.",
                        request = "TestConnectivity",
                        message = response
                    });
		    // Now we have a controlled response from ChatGPT, we can send this response to the client to parse the array inside {} on the local machine 
		    // and initiate a ping test to each of these machines
                    return JsonConvert.SerializeObject(aiResps);
                }
                else
                {
                    aiResps.Add(new AIResp
                    {
                        Date = DateTime.Now,
                        AI = GPTName,
                        response = "Sorry, I was not able to get the list of IP Address or hostnames from your question, Can you rephrase your question and try again!!",
                        request = "",
                        message = ""
                    });

                    return JsonConvert.SerializeObject(aiResps);
                }

            }
            else
            {
                aiResps.Add(new AIResp
                {
                    Date = DateTime.Now,
                    AI = GPTName,
                    response = "Sorry, Testing connectivity is currently not supported on this Client Platform!!",
                    request = "",
                    message = ""
                });

                return JsonConvert.SerializeObject(aiResps);
            }

        }


        [SKFunction, Description("Parse Hello Message")]
        public string SayHello()
        {
            List<AIResp> aiResps = new List<AIResp>();
	    
	    // While this example does not show the Prompt for ParseHelloMessage, you can get creative to frame a controlled hello response for your instance of ChatGPT
            var response = ProcessSubPrompt("ParseHelloMessage", userquestion, history, false).GetAwaiter().GetResult();

            aiResps.Add(new AIResp
            {
                Date = DateTime.Now,
                AI = "Hexa8GPT",
                response = response,
                request = "",
                message = ""
            });

            return JsonConvert.SerializeObject(aiResps);


        }

        [SKFunction, Description("Render the Task Scheduler App Only For Javascript")]
        public string DisplayTaskSchedulerApp()
        {

            List<AIResp> aiResps = new List<AIResp>();

            if (context.User.Claims.FirstOrDefault(c => c.Type == "OriginHash").Value.Contains("C99C4EA077D68862951EBDD8844B8BBDDA8E40458FE8EFF5AC4A4F30962452AB5FD2358D8B09313AF3BA25FCD66D569359BCC0821BA396631A0C4A3608A2C029"))
            {

                var code = @"
async function initializeTaskSchedulerApp() {
  const container = document.getElementById('hexaeight-user-container');
  container.innerHTML = ''; // Clear the container

// Javascript code to display a Task scheduling app for Browser.

";


                aiResps.Add(new AIResp
                {
                    Date = DateTime.Now,
                    AI = "Hexa8GPT",
                    response = "Here is the Task Scheduler Application as per your request",
                    request = "RENDER",
                    message = code
                });

                return JsonConvert.SerializeObject(aiResps) + "    ";
            }
            else
            {

                aiResps.Add(new AIResp
                {
                    Date = DateTime.Now,
                    AI = "Hexa8GPT",
                    response = "Sorry, I am unable to spin up a Task Scheduling App On this Client Platform.",
                    request = "",
                    message = ""
                });

                return JsonConvert.SerializeObject(aiResps) + "    ";
            }

        }

        [SKFunction, Description("Render the User Profile Only For Javascript")]
        public string WhoamI()
        {

            List<AIResp> aiResps = new List<AIResp>();

            if (context.User.Claims.FirstOrDefault(c => c.Type == "OriginHash").Value.Contains("C99C4EA077D68862951EBDD8844B8BBDDA8E40458FE8EFF5AC4A4F30962452AB5FD2358D8B09313AF3BA25FCD66D569359BCC0821BA396631A0C4A3608A2C029"))
            {
                var code = @"
   // Add Javascript Function code to display the user profile
   // Call the function to render the user profile
  await renderUserProfile();
";

                aiResps.Add(new AIResp
                {
                    Date = DateTime.Now,
                    AI = "Hexa8GPT",
                    response = "Since you are already authenticated, I have displayed your User profile in the User Engagement Area.",
                    request = "RENDER",
                    message = code
                });

                return JsonConvert.SerializeObject(aiResps);
            }
            else
            {

                aiResps.Add(new AIResp
                {
                    Date = DateTime.Now,
                    AI = "Hexa8GPT",
                    response = "Sorry, I am unable to spin up your Profile On this Client Platform.",
                    request = "",
                    message = ""
                });

                return JsonConvert.SerializeObject(aiResps);
            }

        }


    }
}
//Finally in your API Controller code

    // Define the AI Response Class
    public class AIResp
    {
        public DateTime Date { get; set; }
        public string AI { get; set; }
        public string response { get; set; }
        public string request { get; set; }
        public string message { get; set; }

    }

    

   [ApiController]
    [Route("[controller]")]
    public class SecureController : ControllerBase
    {

        private readonly ILogger<SecureController> _logger;

	private GPTInterceptor myControlledGPT;

	// Rest of Controller code
	

	public SecureController(ILogger<SecureController> logger)
        {

            _logger = logger;
	    
	    //Initialize your AI Assistant
	    myControlledGPT = new GPTInterceptor("ClientID", "Token server URL", "MyCustomGPT", "filesuffix");
);

	   // Rest of your Initialization code

	}


        [HttpPost("chatwithAI")]
        [Authorize(AuthenticationSchemes = "Bearer")]
        public async Task<IEnumerable<AIResp>> Post()
        {
            string body = "";
            using (StreamReader stream = new StreamReader(HttpContext.Request.Body))
            {
                body = await stream.ReadToEndAsync();
            }
            body = body.ToString().TrimEnd('\0').Trim();

            HttpContext httpContext = HttpContext;

            await Task.Delay(250);
            var interceptor = myControlledGPT;
            interceptor.context = httpContext;
            interceptor.userquestion = body;

            var answer = await interceptor.ProcessInitialUserInput();
            try
            {
                return JsonConvert.DeserializeObject<List<AIResp>>(answer).ToArray();

            }
            catch
            {

                return JsonConvert.DeserializeObject<List<AIResp>>(JsonConvert.SerializeObject(new AIResp
            {
                Date = DateTime.Now,
                AI = "MyCustomGPT",
                response = "Sorry, I am unable to process your request. Please try again, if this problem persists, please contact Support ",
                request = "",
                message = ""
            })).ToArray();

            }

        }




Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.6.107 75 6/29/2024
1.6.106 66 6/29/2024
1.6.105 57 6/28/2024
1.6.104 55 6/28/2024
1.6.103 56 6/27/2024
1.6.102 77 6/27/2024
1.6.101 57 6/27/2024
1.6.100 61 6/25/2024
1.6.99 56 6/25/2024
1.6.98 54 6/25/2024
1.6.97 60 6/25/2024
1.6.96 65 6/25/2024
1.6.95 64 6/23/2024
1.6.94 58 5/9/2024
1.6.93 74 5/8/2024
1.6.92 65 5/7/2024
1.6.91 67 5/7/2024
1.6.90 67 5/7/2024
1.6.89 64 5/7/2024
1.6.88 66 5/7/2024
1.6.87 62 5/7/2024
1.6.86 73 5/7/2024
1.6.85 106 5/6/2024
1.6.84 119 5/6/2024
1.6.83 118 5/6/2024
1.6.82 113 5/6/2024
1.6.81 111 5/6/2024
1.6.80 125 5/6/2024
1.6.79 119 5/5/2024
1.6.78 123 5/4/2024
1.6.77 127 5/4/2024
1.6.76 97 4/24/2024
1.6.75 94 4/24/2024
1.6.74 94 4/24/2024
1.6.73 108 4/21/2024
1.6.72 90 4/18/2024
1.6.71 103 4/16/2024
1.6.70 112 4/16/2024
1.6.69 103 3/30/2024
1.6.68 102 3/30/2024
1.6.67 107 3/30/2024
1.6.66 97 3/30/2024
1.6.65 109 3/30/2024
1.6.64 88 3/29/2024
1.6.63 94 3/29/2024
1.6.62 103 3/28/2024
1.6.61 115 3/27/2024
1.6.60 112 3/27/2024
1.6.59 118 3/25/2024
1.6.58 114 3/25/2024
1.6.57 115 3/25/2024
1.6.56 123 3/24/2024
1.6.55 110 3/14/2024
1.6.54 125 3/14/2024
1.6.53 127 3/14/2024
1.6.52 121 3/1/2024
1.6.51 240 11/25/2023
1.6.50 125 11/21/2023
1.6.49 140 11/20/2023
1.6.48 121 11/19/2023
1.6.47 143 11/16/2023
1.6.46 138 11/8/2023
1.6.45 116 11/8/2023
1.6.44 131 11/8/2023
1.6.43 129 11/8/2023
1.6.42 133 11/5/2023
1.6.41 127 11/5/2023
1.6.40 134 11/5/2023
1.6.39 129 11/5/2023
1.6.38 139 11/5/2023
1.6.37 117 11/5/2023
1.6.36 130 11/4/2023
1.6.35 140 11/4/2023
1.6.34 169 10/29/2023
1.6.33 135 10/29/2023
1.6.32 158 10/20/2023
1.6.31 153 10/15/2023
1.6.30 141 10/15/2023
1.6.29 161 10/14/2023
1.6.28 140 10/13/2023
1.6.27 133 10/13/2023
1.6.26-preview 123 10/12/2023
1.6.25-preview 98 10/11/2023
1.6.24-preview 129 10/11/2023
1.6.23-preview 112 10/6/2023
1.6.22-preview 106 9/28/2023
1.6.21-preview 105 9/28/2023
1.6.20-preview 119 9/28/2023
1.6.19-preview 89 9/27/2023
1.6.18-preview 97 9/26/2023
1.6.17-preview 88 9/25/2023
1.6.16-preview 95 9/25/2023
1.6.15-preview 96 9/19/2023
1.6.14-preview 83 9/19/2023
1.6.13-preview 102 9/19/2023
1.6.12-preview 128 9/19/2023
1.6.11-preview 89 9/19/2023
1.6.10-preview 71 9/19/2023
1.6.9-preview 101 9/19/2023
1.6.8-preview 111 9/18/2023