Skip to content

Conversation

marcominerva
Copy link
Owner

This pull request introduces significant updates to the DatabaseGpt project, including upgrading the target framework to .NET 9.0, replacing the ChatGptNet library with Microsoft's Azure.AI.OpenAI and Microsoft.Extensions.AI libraries, and enhancing caching and resilience mechanisms. These changes modernize the project, improve performance, and simplify dependencies.

Framework and Package Upgrades:

  • Updated the target framework from .NET 8.0 to .NET 9.0 across all projects (.csproj files). [1] [2] [3] [4] [5] [6] [7]
  • Upgraded package dependencies to their latest versions, including Dapper, Npgsql, Microsoft.Data.SqlClient, and Swashbuckle.AspNetCore. [1] [2] [3] [4] [5] [6]

Transition to Azure AI Libraries:

  • Replaced ChatGptNet with Azure.AI.OpenAI and Microsoft.Extensions.AI libraries for chat functionality, introducing AzureOpenAIClient and IChatClient for handling chat-based operations. [1] [2] [3]
  • Updated the Program.cs file to configure Azure OpenAI services and integrate the new chat client into the dependency injection container. [1] [2]

Caching and Resilience Enhancements:

  • Introduced a hybrid caching mechanism using Microsoft.Extensions.Caching.Hybrid to store chat history, ensuring better performance and scalability. [1] [2]
  • Enhanced resilience by logging failed queries in the chat history and retrying operations where appropriate. [1] [2]

Codebase Simplification and Cleanup:

  • Removed the ColumnEntity class and refactored its usage to directly query strings, simplifying the SqlServerDatabaseGptProvider. [1] [2]
  • Streamlined DatabaseGptServiceCollectionExtensions by removing redundant overloads and simplifying service registration. [1] [2]

Configuration Changes:

  • Updated appsettings.json to reflect the new Azure OpenAI configuration format, removing legacy fields like Provider and Organization.

Updated target framework to .NET 9.0 across multiple projects.
Updated various package references for compatibility and new features.
Replaced `ChatGptNet` with `Azure.AI.OpenAI` in `Program.cs`, enhancing chat client management.
Modified `ConfigureServices` to include `HybridCache` and improve service setup.
Refactored `DatabaseGptClient` to manage chat history and cache more effectively.
Added `MessageLimit` property to `DatabaseGptSettings` for better message control.
Streamlined `AddDatabaseGpt` extension methods for improved clarity and dependency injection.
- Updated `Swashbuckle.AspNetCore` package version to `8.1.2`.
- Modified `appsettings.json` to remove outdated properties and add `Endpoint` and `DeploymentName`.
- Removed `ColumnEntity` class and adjusted related code in `SqlServerDatabaseGptProvider`.
- Enhanced error handling in `DatabaseGptClient` with a `try-catch` block for query execution.
- Updated `CreateSessionAsync` to ensure proper GUID assignment for `sessionId`.
- Changed chat history management to use `request` instead of `question`.
@marcominerva marcominerva requested a review from Copilot May 27, 2025 13:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the DatabaseGpt project by upgrading to .NET 9.0, swapping in Azure AI libraries for OpenAI interactions, and strengthening caching and resilience while cleaning up deprecated types.

  • Updated all projects from net8.0 to net9.0 and bumped key package versions.
  • Replaced ChatGptNet with Azure.AI.OpenAI/Microsoft.Extensions.AI and added a hybrid cache.
  • Refactored SQL provider to return raw column definitions and removed the ColumnEntity class.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/DatabaseGpt/Settings/DatabaseGptSettings.cs Added new MessageLimit setting to cap chat history.
src/DatabaseGpt/DatabaseGptServiceCollectionExtensions.cs Simplified AddDatabaseGpt overloads and removed ChatGptNet references.
src/DatabaseGpt/DatabaseGptClient.cs Integrated IChatClient, hybrid cache, and resilience; added GetChatHistoryAsync/UpdateCacheAsync.
src/DatabaseGpt.SqlServer/SqlServerDatabaseGptProvider.cs Switched from ColumnEntity mapping to raw string query, removed model class.
samples/DatabaseGptConsole/appsettings.json Changed configuration to Azure OpenAI format (endpoint, deployment).
samples/DatabaseGptConsole/Program.cs Configured AzureOpenAIClient, registered hybrid cache and chat client.
Comments suppressed due to low confidence (3)

src/DatabaseGpt/DatabaseGptClient.cs:188

  • [nitpick] Consider adding unit tests for UpdateCacheAsync and GetChatHistoryAsync, specifically covering trimming logic when chat.Count exceeds MessageLimit and cache set/retrieve behaviors.
private async Task UpdateCacheAsync(Guid conversationId, ChatHistory chat, CancellationToken cancellationToken)

src/DatabaseGpt.SqlServer/SqlServerDatabaseGptProvider.cs:70

  • The SQL query still selects multiple columns for ColumnEntity, but QueryAsync<string> maps a single string. Either update the SQL to return a single concatenated column definition or restore the correct mapping shape.
var columns = await connection.QueryAsync<string>(query, new { schema = table.Schema, table = table.Name, excludedColumns });

samples/DatabaseGptConsole/appsettings.json:7

  • The sample Program.cs reads ChatGPT:ApiKey, but the JSON no longer defines an ApiKey property. Add "ApiKey": "" under the ChatGPT section or update the code to match the new schema.
"Endpoint": "",

Updated the CodeQL configuration by replacing the previous setup with a new structure. The new configuration includes refined triggers for `push` and `pull_request` events, specifying branches and paths. Job settings have been streamlined, enhancing the setup for the .NET SDK and CodeQL analysis. Overall organization and clarity of the workflow have been improved while retaining previous comments and instructions.
@marcominerva marcominerva merged commit f4c6151 into develop May 27, 2025
2 of 3 checks passed
@marcominerva marcominerva deleted the functions branch May 27, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant