Skip to content

Commit

Permalink
added logging to chat controller to show chat function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
MSFTJim committed Apr 16, 2024
1 parent c3e4a24 commit bffd7bd
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TSA-API/tsaWaitTime/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion scripts/commands.azcli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
dotnet remove package Swashbuckle.AspNetCore.Annotations
sudo dotnet run --urls=http://localhost:5088
28 changes: 28 additions & 0 deletions webapi/Controllers/ChatController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public async Task<IActionResult> 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);

Expand Down Expand Up @@ -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.
}

}

/// <summary>
Expand Down Expand Up @@ -481,4 +507,6 @@ public async Task OpenAIAuthenticateRequestAsync(HttpRequestMessage request, str
{
await this.AuthenticateRequestAsync(request, cancellationToken);
}


}
12 changes: 6 additions & 6 deletions webapi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:",
Expand Down

0 comments on commit bffd7bd

Please sign in to comment.