Welcome to the Aspire Dashboard sample. This project showcases how to integrate Phi-3, a cutting-edge Small Language Model (SLM), with telemetry and logging using OpenTelemetry in a .NET environment.
The scenario covered by this project involves creating a chatbot using the Phi-3 model. The chatbot is designed to answer user questions in a humorous and concise manner, utilizing emojis when possible. The project also integrates telemetry and logging to monitor and trace the chatbot's performance and interactions.
The Program.cs
file is the main entry point of the application and is structured as follows:
-
Define Endpoints:
otlpEndPoint
andphi3EndPoint
are defined for telemetry and Phi-3 endpoints respectively.
-
Create Kernel and Add Phi-3 Chat Completion:
- A kernel builder is created using
Kernel.CreateBuilder()
. - Phi-3 chat completion is added to the kernel with the specified model ID, endpoint, and API key.
- A kernel builder is created using
-
Add OTLP Exporter for Logs:
- A
LoggerFactory
is created and configured to use OpenTelemetry for exporting logs. - The logger is set to include formatted messages and scopes, with a minimum log level of
Trace
.
- A
-
Build Kernel:
- The kernel is built using the configured builder.
-
Add Trace and Meter Providers:
- Tracer and meter providers are created using OpenTelemetry to monitor the
Microsoft.SemanticKernel
namespace. - OTLP exporters are added to both providers.
- Tracer and meter providers are created using OpenTelemetry to monitor the
-
Start Chat:
- A chat service is retrieved from the kernel.
- A chat history object is initialized with a system message defining the chatbot's behavior.
- A loop is started to continuously read user input, process it using the Phi-3 model, and display the response.
-
Logging:
- User questions and Phi-3 responses are logged using a helper method
AddLog
.
- User questions and Phi-3 responses are logged using a helper method
-
Helper Method:
AddLog
method retrieves the logger from the kernel's services and logs the provided message.
This setup ensures that the chatbot is not only functional but also monitored and traceable, providing valuable insights into its performance and interactions.
-
Open a terminal and navigate to the current project.
cd .\src\Sample04\
-
Run the project with the command
dotnet run
-
The project should run and send telemetry to the Aspire Dashboard.