From bffd7bd78e839b6d84be677b9a58302739807961 Mon Sep 17 00:00:00 2001 From: Jim Vacca <33520581+MSFTJim@users.noreply.github.com> Date: Tue, 16 Apr 2024 20:35:47 +0000 Subject: [PATCH] added logging to chat controller to show chat function calls --- TSA-API/tsaWaitTime/Program.cs | 2 +- scripts/commands.azcli | 4 +++- webapi/Controllers/ChatController.cs | 28 ++++++++++++++++++++++++++++ webapi/appsettings.json | 12 ++++++------ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/TSA-API/tsaWaitTime/Program.cs b/TSA-API/tsaWaitTime/Program.cs index 131366f62..f386d8c51 100644 --- a/TSA-API/tsaWaitTime/Program.cs +++ b/TSA-API/tsaWaitTime/Program.cs @@ -57,7 +57,7 @@ //return TypedResults.Ok(new { WaitTime = waitTime }); }) -.WithDescription("Calculates the TSA wait time for a given airport code") +.WithDescription("Calculates the TSA wait time for an airport when provided a 3 digit code as a string") //.WithDisplayName("Calculates the TSA wait time for a given airport code") .WithName("TSA Wait Time API") .WithOpenApi(); diff --git a/scripts/commands.azcli b/scripts/commands.azcli index 35c58e378..9a403ab59 100644 --- a/scripts/commands.azcli +++ b/scripts/commands.azcli @@ -15,6 +15,7 @@ sudo ./start-frontend.sh # test api - http://localhost:40443/healthz +Can you tell me the TSA wait time for JFK? # TSA WaitTime API dotnet new web -n tsaWaitTime @@ -26,4 +27,5 @@ dotnet add package Microsoft.AspNetCore.OpenApi --version 8.0.4 dotnet add package Microsoft.SemanticKernel --version 1.7.1 dotnet remove package Microsoft.SemanticKernel dotnet add package Swashbuckle.AspNetCore.Annotations -dotnet remove package Swashbuckle.AspNetCore.Annotations \ No newline at end of file +dotnet remove package Swashbuckle.AspNetCore.Annotations +sudo dotnet run --urls=http://localhost:5088 diff --git a/webapi/Controllers/ChatController.cs b/webapi/Controllers/ChatController.cs index 56fb28216..cdbf5bbc4 100644 --- a/webapi/Controllers/ChatController.cs +++ b/webapi/Controllers/ChatController.cs @@ -118,6 +118,10 @@ public async Task ChatAsync( var openApiPluginAuthHeaders = this.GetPluginAuthHeaders(this.HttpContext.Request.Headers); await this.RegisterFunctionsAsync(kernel, openApiPluginAuthHeaders, contextVariables); +#pragma warning disable SKEXP0004 // this is for evaluation purposes only + kernel.FunctionFilters.Add(new FirstFunctionFilter()); +#pragma warning restore SKEXP0004 // this is for evaluation purposes only + // Register hosted plugins that have been enabled await this.RegisterHostedFunctionsAsync(kernel, chat!.EnabledPlugins); @@ -405,6 +409,28 @@ public void Dispose() this.Dispose(disposing: true); GC.SuppressFinalize(this); } +#pragma warning disable SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + private sealed class FirstFunctionFilter : IFunctionFilter +#pragma warning restore SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + { + //private readonly ITestOutputHelper _output; + + public FirstFunctionFilter() + { + //this._output = output; + } + +#pragma warning disable SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + public void OnFunctionInvoking(FunctionInvokingContext context) => + Console.WriteLine($"{nameof(FirstFunctionFilter)}.{nameof(OnFunctionInvoking)} - {context.Function.Name}.{context.Function.Description}"); +#pragma warning restore SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + +#pragma warning disable SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + public void OnFunctionInvoked(FunctionInvokedContext context) => + Console.WriteLine($"{nameof(FirstFunctionFilter)}.{nameof(OnFunctionInvoked)} - {context.Function.Name}.{context.Function.Description}"); +#pragma warning restore SKEXP0004 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed. + } + } /// @@ -481,4 +507,6 @@ public async Task OpenAIAuthenticateRequestAsync(HttpRequestMessage request, str { await this.AuthenticateRequestAsync(request, cancellationToken); } + + } diff --git a/webapi/appsettings.json b/webapi/appsettings.json index d31d41a8e..6ec7cab60 100644 --- a/webapi/appsettings.json +++ b/webapi/appsettings.json @@ -124,12 +124,12 @@ "Prompts": { "CompletionTokenLimit": 4096, "ResponseTokenLimit": 1024, - "ORIGSystemDescription": "This is a chat between an intelligent AI bot named Copilot and one or more participants. SK stands for Semantic Kernel, the AI platform used to build the bot. The AI was trained on data through 2021 and is not aware of events that have occurred since then. It also has no ability to access data on the Internet, so it should not claim that it can or say that it will go and look things up. Try to be concise with your answers, though it is not required. Knowledge cutoff: {{$knowledgeCutoff}} / Current date: {{TimePlugin.Now}}.", - "SystemDescription": "This is a chat between an intelligent AI bot named Ace and one or more participants. Ace is an intelligent chatbot designed to assist with travel information for the New York/New Jersey Port Authority. It leverages advanced AI technology to provide real-time updates, answer queries, and offer guidance to travelers navigating the NY/NJ transit system. If the question is not about the NY/NJ Transit, politely decline to answer it. Try to be concise with your answers, though it is not required. Knowledge cutoff: {{$knowledgeCutoff}} / Current date: {{TimePlugin.Now}}.", - "ORIGSystemResponse": "Either return [silence] or provide a response to the last message. ONLY PROVIDE A RESPONSE IF the last message WAS ADDRESSED TO THE 'BOT' OR 'COPILOT'. If it appears the last message was not for you, send [silence] as the bot response.", - "SystemResponse": "Either return [silence] or provide a response to the last message. ONLY PROVIDE A RESPONSE IF the last message WAS ADDRESSED TO THE 'ACE', 'BOT' OR 'COPILOT'. If it appears the last message was not for you, send [silence] as the bot response.", - "ORIGInitialBotMessage": "Hello, thank you for democratizing AI's productivity benefits with open source! How can I help you today?", - "InitialBotMessage": "Hello! I'm **Ace**, your digital assistant for all things related to the New York/New Jersey Port Authority. I'm here to provide you with real-time updates, answer your queries, and guide you through the NY/NJ transit system. Whether you need information on bus and train schedules, delays, cancellations, or platform changes, I've got you covered. How can I assist you today?", + "SystemDescription": "This is a chat between an intelligent AI bot named Copilot and one or more participants. SK stands for Semantic Kernel, the AI platform used to build the bot. The AI was trained on data through 2021 and is not aware of events that have occurred since then. It also has no ability to access data on the Internet, so it should not claim that it can or say that it will go and look things up. Try to be concise with your answers, though it is not required. Knowledge cutoff: {{$knowledgeCutoff}} / Current date: {{TimePlugin.Now}}.", + "TSASystemDescription": "This is a chat between an intelligent AI bot named Ace and one or more participants. Ace is an intelligent chatbot designed to assist with travel information for the New York/New Jersey Port Authority. It leverages advanced AI technology to provide real-time updates, answer queries, and offer guidance to travelers navigating the NY/NJ transit system. If the question is not about the NY/NJ Transit, politely decline to answer it. Try to be concise with your answers, though it is not required. Knowledge cutoff: {{$knowledgeCutoff}} / Current date: {{TimePlugin.Now}}.", + "SystemResponse": "Either return [silence] or provide a response to the last message. ONLY PROVIDE A RESPONSE IF the last message WAS ADDRESSED TO THE 'BOT' OR 'COPILOT'. If it appears the last message was not for you, send [silence] as the bot response.", + "TSASystemResponse": "Either return [silence] or provide a response to the last message. ONLY PROVIDE A RESPONSE IF the last message WAS ADDRESSED TO THE 'ACE', 'BOT' OR 'COPILOT'. If it appears the last message was not for you, send [silence] as the bot response.", + "InitialBotMessage": "Hello, thank you for democratizing AI's productivity benefits with open source! How can I help you today?", + "TSAInitialBotMessage": "Hello! I'm **Ace**, your digital assistant for all things related to the New York/New Jersey Port Authority. I'm here to provide you with real-time updates, answer your queries, and guide you through the NY/NJ transit system. Whether you need information on bus and train schedules, delays, cancellations, or platform changes, I've got you covered. How can I assist you today?", "KnowledgeCutoffDate": "Saturday, January 1, 2022", "SystemAudience": "Below is a chat history between an intelligent AI bot named Copilot with one or more participants.", "SystemAudienceContinuation": "Using the provided chat history, generate a list of names of the participants of this chat. Do not include 'bot' or 'copilot'.The output should be a single rewritten sentence containing only a comma separated list of names. DO NOT offer additional commentary. DO NOT FABRICATE INFORMATION.\nParticipants:",