Skip to content

Commit

Permalink
Update to .NET 8.0 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
marcominerva committed Dec 19, 2023
1 parent b14809d commit b3227be
Show file tree
Hide file tree
Showing 1,907 changed files with 3,598 additions and 3,394 deletions.
7 changes: 7 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions SearchGpt.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{69BEC74E-A82F-48AA-A418-2001765A2361}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SearchGpt.Shared", "src\SearchGpt.Shared\SearchGpt.Shared.csproj", "{9B491DB4-5DF5-4961-947D-D4DE8C465A34}"
Expand Down
10 changes: 5 additions & 5 deletions src/SearchGpt.BusinessLayer/SearchGpt.BusinessLayer.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Search.Documents" Version="11.4.0" />
<PackageReference Include="ChatGptNet" Version="2.5.4" />
<PackageReference Include="OperationResultTools" Version="1.0.12" />
<PackageReference Include="TinyHelpers" Version="2.0.35" />
<PackageReference Include="Azure.Search.Documents" Version="11.5.1" />
<PackageReference Include="ChatGptNet" Version="3.0.6" />
<PackageReference Include="OperationResultTools" Version="1.0.15" />
<PackageReference Include="TinyHelpers" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 2 additions & 10 deletions src/SearchGpt.BusinessLayer/Services/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
using Azure.Search.Documents;
using Azure.Search.Documents.Models;
using ChatGptNet;
using ChatGptNet.Extensions;
using ChatGptNet.Models;
using OperationResults;
using SearchGpt.BusinessLayer.Services.Interfaces;
using SearchGpt.Shared.Models;

namespace SearchGpt.BusinessLayer.Services;

public class ChatService : IChatService
public class ChatService(IChatGptClient chatGptClient, SearchClient searchClient) : IChatService
{
private readonly IChatGptClient chatGptClient;
private readonly SearchClient searchClient;

private static readonly SearchOptions searchOptions;

private const string ContentFilteredMessage = "***** (The response was filtered by the content filtering system. Please modify your prompt and retry. To learn more about content filtering policies please read the documentation: https://go.microsoft.com/fwlink/?linkid=2198766)";
Expand All @@ -29,12 +27,6 @@ static ChatService()
searchOptions.Select.Add("content");
}

public ChatService(IChatGptClient chatGptClient, SearchClient searchClient)
{
this.chatGptClient = chatGptClient;
this.searchClient = searchClient;
}

public async Task<Result<ChatResponse>> AskAsync(ChatRequest request)
{
var question = await SetupAsync(request);
Expand Down
2 changes: 1 addition & 1 deletion src/SearchGpt.Shared/SearchGpt.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

Expand Down
16 changes: 8 additions & 8 deletions src/SearchGpt/Endpoints/ChatEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using SearchGpt.BusinessLayer.Services.Interfaces;
using SearchGpt.Shared.Models;
using MinimalHelpers.Routing;
using MinimalHelpers.Routing;
using OperationResults.AspNetCore.Http;
using SearchGpt.BusinessLayer.Services.Interfaces;
using SearchGpt.Shared.Models;

namespace SearchGpt.Endpoints;

public class ChatEndpoints : IEndpointRouteHandler
public class ChatEndpoints : IEndpointRouteHandlerBuilder
{
public void MapEndpoints(IEndpointRouteBuilder endpoints)
public static void MapEndpoints(IEndpointRouteBuilder endpoints)
{
var chatGroupApi = endpoints.MapGroup("/api/chat");

Expand All @@ -28,15 +28,15 @@ public void MapEndpoints(IEndpointRouteBuilder endpoints)
.WithOpenApi();
}

public async Task<IResult> AskAsync(ChatRequest request, IChatService chatService, HttpContext httpContext)
public static async Task<IResult> AskAsync(ChatRequest request, IChatService chatService, HttpContext httpContext)
{
var result = await chatService.AskAsync(request);

var response = httpContext.CreateResponse(result);
return response;
}

public IAsyncEnumerable<string> StreamAsync(ChatRequest request, IChatService chatService, HttpContext httpContext)
public static IAsyncEnumerable<string> StreamAsync(ChatRequest request, IChatService chatService, HttpContext httpContext)
{
async IAsyncEnumerable<string> Stream()
{
Expand All @@ -53,7 +53,7 @@ async IAsyncEnumerable<string> Stream()
return Stream();
}

public async Task<IResult> DeleteAsync(Guid conversationId, IChatService chatService, HttpContext httpContext)
public static async Task<IResult> DeleteAsync(Guid conversationId, IChatService chatService, HttpContext httpContext)
{
var result = await chatService.DeleteAsync(conversationId);

Expand Down
36 changes: 36 additions & 0 deletions src/SearchGpt/ExceptionHandlers/DefaultExceptionHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;

namespace SearchGpt.ExceptionHandlers;

public class DefaultExceptionHandler(IProblemDetailsService problemDetailsService, IWebHostEnvironment webHostEnvironment) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(HttpContext httpContext, Exception exception, CancellationToken cancellationToken)
{
var problemDetails = new ProblemDetails
{
Status = httpContext.Response.StatusCode,
Title = exception.GetType().FullName,
Detail = exception.Message,
Instance = httpContext.Request.Path
};

problemDetails.Extensions["traceId"] = Activity.Current?.Id ?? httpContext.TraceIdentifier;

if (webHostEnvironment.IsDevelopment())
{
problemDetails.Extensions["stackTrace"] = exception.StackTrace;
}

await problemDetailsService.WriteAsync(new()
{
HttpContext = httpContext,
AdditionalMetadata = httpContext.Features.Get<IExceptionHandlerFeature>()?.Endpoint?.Metadata,
ProblemDetails = problemDetails,
Exception = exception
});

return true;
}
}
34 changes: 3 additions & 31 deletions src/SearchGpt/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
using Azure;
using Azure.Search.Documents;
using ChatGptNet;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.OpenApi.Models;
using MinimalHelpers.OpenApi;
using MinimalHelpers.Routing;
using OperationResults.AspNetCore.Http;
using SearchGpt.BusinessLayer.Services;
using SearchGpt.BusinessLayer.Services.Interfaces;
using SearchGpt.BusinessLayer.Settings;
using SearchGpt.ExceptionHandlers;
using SearchGpt.Extensions;
using SearchGpt.Swagger;
using TinyHelpers.AspNetCore.Extensions;
Expand Down Expand Up @@ -43,6 +42,7 @@
return client;
});

builder.Services.AddExceptionHandler<DefaultExceptionHandler>();
builder.Services.AddProblemDetails(options =>
{
options.CustomizeProblemDetails = context =>
Expand Down Expand Up @@ -71,7 +71,6 @@
options.SwaggerDoc("v1", new OpenApiInfo { Title = "SearchGpt API", Version = "v1" });
options.AddDefaultResponse();
options.AddMissingSchemas();
});
}

Expand Down Expand Up @@ -101,34 +100,7 @@

app.UseWhen(context => context.IsApiRequest(), builder =>
{
if (!app.Environment.IsDevelopment())
{
// Error handling
builder.UseExceptionHandler(new ExceptionHandlerOptions
{
AllowStatusCode404Response = true,
ExceptionHandler = async (HttpContext context) =>
{
var problemDetailsService = context.RequestServices.GetService<IProblemDetailsService>();
var exceptionHandlerFeature = context.Features.Get<IExceptionHandlerFeature>();
var error = exceptionHandlerFeature?.Error;
// Write as JSON problem details
await problemDetailsService.WriteAsync(new()
{
HttpContext = context,
AdditionalMetadata = exceptionHandlerFeature?.Endpoint?.Metadata,
ProblemDetails =
{
Status = context.Response.StatusCode,
Title = error?.GetType().FullName ?? "An error occurred while processing your request",
Detail = error?.Message
}
});
}
});
}
builder.UseExceptionHandler();
builder.UseStatusCodePages();
});

Expand Down
12 changes: 6 additions & 6 deletions src/SearchGpt/SearchGpt.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<SourceRevisionId>build$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</SourceRevisionId>
<Company>Marco Minerva</Company>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.396" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
<PackageReference Include="MinimalHelpers.OpenApi" Version="1.0.4" />
<PackageReference Include="MinimalHelpers.Routing" Version="1.0.17" />
<PackageReference Include="OperationResultTools.AspNetCore.Http" Version="1.0.14" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="MinimalHelpers.OpenApi" Version="2.0.3" />
<PackageReference Include="MinimalHelpers.Routing" Version="2.0.3" />
<PackageReference Include="OperationResultTools.AspNetCore.Http" Version="1.0.17" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="TinyHelpers.AspNetCore" Version="2.0.24" />
<PackageReference Include="TinyHelpers.AspNetCore" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/SearchGpt/libman.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"destination": "wwwroot/lib/bootstrap"
},
{
"library": "bootstrap-icons@1.11.1",
"library": "bootstrap-icons@1.11.2",
"destination": "wwwroot/lib/bootstrap-icons"
},
{
"library": "jquery@3.7.1",
"destination": "wwwroot/lib/jquery"
},
{
"library": "alpinejs@3.13.1",
"library": "alpinejs@3.13.3",
"destination": "wwwroot/lib/alpinejs"
},
{
"library": "marked@9.1.0",
"library": "marked@11.1.0",
"destination": "wwwroot/lib/marked"
}
]
Expand Down
Loading

0 comments on commit b3227be

Please sign in to comment.