✨ Update project configuration and add AI chat functionality
- 🐳 Update `.dockerignore` to include `README.md` Exclude additional Docker-related files for cleaner builds. - 🔧 Modify `HealthController.cs` to use `IRestApiWrapper` Enhance health check functionality with REST API integration. - 🐋 Change exposed port in `Dockerfile` to `5245` Update build process to use configuration arguments. - 📦 Upgrade `Refit` package to version `7.2.1` Add `Refit.Newtonsoft.Json` for improved JSON handling. - 📜 Add using directives in `Brizco.Infrastructure.csproj` Include necessary namespaces for new functionality. - 🔗 Update `IRestApiWrapper` to include `IMetisRestApi` Enhance API wrapper with new Metis API integration. - 🛠️ Create `launch.json` for .NET Core debugging Simplify debugging process with Docker settings. - 📝 Add `tasks.json` for build and publish tasks Define tasks for building, publishing, and Docker operations. - 🤖 Introduce `AiController.cs` for AI chat bot endpoint Implement endpoint to handle chat requests using REST API. - 📂 Update `AiCommands.cs` with correct namespace Ensure proper organization and access to commands. - 🆕 Add new data classes for AI functionality Introduce `CreateSessionRequestDto`, `MetisMessageRequest`, etc. - 📡 Create `IMetisRestApi` interface for chat sessions Define API endpoints for managing chat interactions. --- Changes made by Amir.h KhademibrizAssistante
parent
9a4ac43e2a
commit
44361e73ce
|
@ -11,10 +11,10 @@
|
||||||
**/*.*proj.user
|
**/*.*proj.user
|
||||||
**/*.dbmdl
|
**/*.dbmdl
|
||||||
**/*.jfm
|
**/*.jfm
|
||||||
**/azds.yaml
|
|
||||||
**/bin
|
**/bin
|
||||||
**/charts
|
**/charts
|
||||||
**/docker-compose*
|
**/docker-compose*
|
||||||
|
**/compose*
|
||||||
**/Dockerfile*
|
**/Dockerfile*
|
||||||
**/node_modules
|
**/node_modules
|
||||||
**/npm-debug.log
|
**/npm-debug.log
|
||||||
|
@ -22,4 +22,4 @@
|
||||||
**/secrets.dev.yaml
|
**/secrets.dev.yaml
|
||||||
**/values.dev.yaml
|
**/values.dev.yaml
|
||||||
LICENSE
|
LICENSE
|
||||||
README.md
|
README.md
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": ".NET Core Launch (web)",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "launch",
|
||||||
|
"preLaunchTask": "build",
|
||||||
|
"program": "${workspaceFolder}/Brizco.Api/bin/Debug/net8.0/Brizco.Api.dll",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}/Brizco.Api",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"serverReadyAction": {
|
||||||
|
"action": "openExternally",
|
||||||
|
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"sourceFileMap": {
|
||||||
|
"/Views": "${workspaceFolder}/Views"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": ".NET Core Attach",
|
||||||
|
"type": "coreclr",
|
||||||
|
"request": "attach"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Docker .NET Launch",
|
||||||
|
"type": "docker",
|
||||||
|
"env": {
|
||||||
|
"ASPNETCORE_URLS": "http://+:80",
|
||||||
|
"TZ": "Asia/Tehran"
|
||||||
|
},
|
||||||
|
"request": "launch",
|
||||||
|
"DockerfileRunArguments": " --network=mother -p 32767:80",
|
||||||
|
"preLaunchTask": "docker-run: debug",
|
||||||
|
"netCore": {
|
||||||
|
"appProject": "${workspaceFolder}/Brizco.Api/Brizco.Api.csproj"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,101 @@
|
||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"build",
|
||||||
|
"${workspaceFolder}/Brizco.sln",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "publish",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"publish",
|
||||||
|
"${workspaceFolder}/Brizco.sln",
|
||||||
|
"/property:GenerateFullPaths=true",
|
||||||
|
"/consoleloggerparameters:NoSummary;ForceNoAlign"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "watch",
|
||||||
|
"command": "dotnet",
|
||||||
|
"type": "process",
|
||||||
|
"args": [
|
||||||
|
"watch",
|
||||||
|
"run",
|
||||||
|
"--project",
|
||||||
|
"${workspaceFolder}/Brizco.sln"
|
||||||
|
],
|
||||||
|
"problemMatcher": "$msCompile"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "docker-build",
|
||||||
|
"label": "docker-build: debug",
|
||||||
|
"dependsOn": [
|
||||||
|
"build"
|
||||||
|
],
|
||||||
|
"dockerBuild": {
|
||||||
|
"tag": "brizco:dev",
|
||||||
|
"target": "base",
|
||||||
|
"dockerfile": "${workspaceFolder}/Brizco.Api/Dockerfile",
|
||||||
|
"context": "${workspaceFolder}",
|
||||||
|
"pull": true
|
||||||
|
},
|
||||||
|
"netCore": {
|
||||||
|
"appProject": "${workspaceFolder}/Brizco.Api/Brizco.Api.csproj"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "docker-build",
|
||||||
|
"label": "docker-build: release",
|
||||||
|
"dependsOn": [
|
||||||
|
"build"
|
||||||
|
],
|
||||||
|
"dockerBuild": {
|
||||||
|
"tag": "brizco:latest",
|
||||||
|
"dockerfile": "${workspaceFolder}/Brizco.Api/Dockerfile",
|
||||||
|
"context": "${workspaceFolder}",
|
||||||
|
"platform": {
|
||||||
|
"os": "linux",
|
||||||
|
"architecture": "amd64"
|
||||||
|
},
|
||||||
|
"pull": true
|
||||||
|
},
|
||||||
|
"netCore": {
|
||||||
|
"appProject": "${workspaceFolder}/Brizco.Api/Brizco.Api.csproj"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "docker-run",
|
||||||
|
"label": "docker-run: debug",
|
||||||
|
"dependsOn": [
|
||||||
|
"docker-build: debug"
|
||||||
|
],
|
||||||
|
"dockerRun": {},
|
||||||
|
"netCore": {
|
||||||
|
"appProject": "${workspaceFolder}/Brizco.Api/Brizco.Api.csproj",
|
||||||
|
"enableDebugging": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "docker-run",
|
||||||
|
"label": "docker-run: release",
|
||||||
|
"dependsOn": [
|
||||||
|
"docker-build: release"
|
||||||
|
],
|
||||||
|
"dockerRun": {},
|
||||||
|
"netCore": {
|
||||||
|
"appProject": "${workspaceFolder}/Brizco.Api/Brizco.Api.csproj"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
using Brizco.Infrastructure.Models.Metis;
|
||||||
|
using Brizco.Infrastructure.RestServices;
|
||||||
|
|
||||||
|
namespace Brizco.Api.Controllers;
|
||||||
|
|
||||||
|
public class AiController : ICarterModule
|
||||||
|
{
|
||||||
|
public void AddRoutes(IEndpointRouteBuilder app)
|
||||||
|
{
|
||||||
|
var group = app.NewVersionedApi("Ai").MapGroup("api/ai");
|
||||||
|
group.MapGet("chat", ChatAsync)
|
||||||
|
.WithDisplayName("AiChatBot")
|
||||||
|
.HasApiVersion(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<IResult> ChatAsync([FromQuery]string message, [FromServices] IRestApiWrapper apiWrapper, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
|
||||||
|
var messageRequest = new MetisMessageRequest
|
||||||
|
{
|
||||||
|
message = new MetisMessage
|
||||||
|
{
|
||||||
|
content = message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var response = await apiWrapper.MetisRestApi.SendMessage("6519455b-9e7f-4faf-8b87-8f0073c730b0", messageRequest, "tpsg-pzDUto3eFhQE9oNzPlSsLZHTkeSvYf5");
|
||||||
|
//var json = response.Content.Replace("```json", "").Replace("```", "").Trim();
|
||||||
|
//var complex = JsonConvert.DeserializeObject<Complex>(json);
|
||||||
|
return TypedResults.Ok(response.Content);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
using MD.PersianDateTime.Standard;
|
using MD.PersianDateTime.Standard;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Brizco.Infrastructure.RestServices;
|
||||||
|
|
||||||
namespace Brizco.Api.Controllers;
|
namespace Brizco.Api.Controllers;
|
||||||
|
|
||||||
|
@ -14,15 +15,15 @@ public class HealthController : ICarterModule
|
||||||
.WithDisplayName("CheckHealth")
|
.WithDisplayName("CheckHealth")
|
||||||
.HasApiVersion(1.0);
|
.HasApiVersion(1.0);
|
||||||
}
|
}
|
||||||
public IResult GetHealth()
|
public async Task<IResult> GetHealth([FromServices] IRestApiWrapper apiWrapper)
|
||||||
{
|
{
|
||||||
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
||||||
var check = new HealthCheck
|
var check = new HealthCheck
|
||||||
{
|
{
|
||||||
Health = true,
|
Health = true,
|
||||||
Version = version ?? string.Empty,
|
Version = version ?? string.Empty,
|
||||||
StartAt = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("F"),
|
StartAt = Process.GetCurrentProcess().StartTime.ToString("F"),
|
||||||
StartAtPersian = new PersianDateTime(System.Diagnostics.Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
|
StartAtPersian = new PersianDateTime(Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
|
||||||
MachineName = Environment.MachineName
|
MachineName = Environment.MachineName
|
||||||
};
|
};
|
||||||
var process = Process.GetCurrentProcess();
|
var process = Process.GetCurrentProcess();
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
||||||
ENV ASPNETCORE_URLS=https://0.0.0.0:8010
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
EXPOSE 8010
|
EXPOSE 5245
|
||||||
|
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
ENV ASPNETCORE_URLS=http://+:5245
|
||||||
|
|
||||||
|
USER app
|
||||||
|
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
ARG configuration=Release
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY ["Brizco.Api.csproj", "Brizco.Api/"]
|
COPY ["Brizco.Api/Brizco.Api.csproj", "Brizco.Api/"]
|
||||||
RUN dotnet restore "Brizco.Api/Brizco.Api.csproj"
|
RUN dotnet restore "Brizco.Api/Brizco.Api.csproj"
|
||||||
COPY . .
|
COPY . .
|
||||||
WORKDIR "/src/Brizco.Api"
|
WORKDIR "/src/Brizco.Api"
|
||||||
RUN dotnet build "Brizco.Api.csproj" -c Release -o /app/build
|
RUN dotnet build "Brizco.Api.csproj" -c $configuration -o /app/build
|
||||||
|
|
||||||
FROM build AS publish
|
FROM build AS publish
|
||||||
RUN dotnet publish "Brizco.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
ARG configuration=Release
|
||||||
|
RUN dotnet publish "Brizco.Api.csproj" -c $configuration -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
FROM base AS final
|
FROM base AS final
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY --from=publish /app/publish .
|
COPY --from=publish /app/publish .
|
||||||
ENTRYPOINT ["dotnet", "Berizco.Api.dll"]
|
ENTRYPOINT ["dotnet", "Brizco.Api.dll"]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
namespace Brizco.Domain.CommandQueries.Commands;
|
|
@ -7,8 +7,9 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Refit" Version="7.1.2" />
|
<PackageReference Include="Refit" Version="7.2.1" />
|
||||||
<PackageReference Include="Marten" Version="7.23.0" />
|
<PackageReference Include="Marten" Version="7.23.0" />
|
||||||
|
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -29,10 +30,13 @@
|
||||||
<Using Include="Brizco.Core.Abstracts" />
|
<Using Include="Brizco.Core.Abstracts" />
|
||||||
<Using Include="Brizco.Domain.Models.Settings" />
|
<Using Include="Brizco.Domain.Models.Settings" />
|
||||||
<Using Include="Brizco.Infrastructure.Models" />
|
<Using Include="Brizco.Infrastructure.Models" />
|
||||||
|
<Using Include="Brizco.Infrastructure.Models.Metis" />
|
||||||
|
<Using Include="Brizco.Infrastructure.Models.RestApi.Metris" />
|
||||||
<Using Include="Brizco.Infrastructure.RestServices" />
|
<Using Include="Brizco.Infrastructure.RestServices" />
|
||||||
<Using Include="Brizco.Repository.Repositories.Marten" />
|
<Using Include="Brizco.Repository.Repositories.Marten" />
|
||||||
<Using Include="Microsoft.Extensions.Logging" />
|
<Using Include="Microsoft.Extensions.Logging" />
|
||||||
<Using Include="Microsoft.Extensions.Options" />
|
<Using Include="Microsoft.Extensions.Options" />
|
||||||
|
<Using Include="Newtonsoft.Json" />
|
||||||
<Using Include="Refit" />
|
<Using Include="Refit" />
|
||||||
<Using Include="System.Linq.Expressions" />
|
<Using Include="System.Linq.Expressions" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace Brizco.Infrastructure.Models.Metis;
|
||||||
|
|
||||||
|
public class CreateSessionRequestDto
|
||||||
|
{
|
||||||
|
public string BotId { get; set; } = string.Empty;
|
||||||
|
public MetisUser? User { get; set; }
|
||||||
|
public MetisMessageRequest? InitializeMessage { get; set; }
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
namespace Brizco.Infrastructure.Models.Metis;
|
||||||
|
|
||||||
|
public class MetisMessageRequest
|
||||||
|
{
|
||||||
|
public MetisMessage message { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MetisMessage
|
||||||
|
{
|
||||||
|
public string content { get; set; } = string.Empty;
|
||||||
|
public string type { get; set; } = "USER";
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
namespace Brizco.Infrastructure.Models.Metis;
|
||||||
|
|
||||||
|
public class MetisMessageResponse
|
||||||
|
{
|
||||||
|
public string Id { get; set; } = string.Empty;
|
||||||
|
public string Type { get; set; } = string.Empty;
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
public object Attachments { get; set; } = string.Empty;
|
||||||
|
public long Timestamp { get; set; }
|
||||||
|
public string FinishReason { get; set; } = string.Empty;
|
||||||
|
public object Citations { get; set; } = string.Empty;
|
||||||
|
public object ToolCalls { get; set; } = string.Empty;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Brizco.Infrastructure.Models.Metis;
|
||||||
|
|
||||||
|
public class MetisUser
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
public string Id { get; set; } = Guid.NewGuid().ToString("N").Substring(0, 8);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
namespace Brizco.Infrastructure.Models.RestApi.Metris;
|
||||||
|
|
||||||
|
public interface IMetisRestApi
|
||||||
|
{
|
||||||
|
[Post("/chat/session")]
|
||||||
|
public Task CreateSession(string sessionId, [Body]CreateSessionRequestDto request, [Header("x-api-key")] string metisToken);
|
||||||
|
|
||||||
|
[Post("/chat/session/{sessionId}/message")]
|
||||||
|
public Task<MetisMessageResponse> SendMessage(string sessionId, [Body]MetisMessageRequest request, [Header("x-api-key")] string metisToken);
|
||||||
|
|
||||||
|
[Post("/chat/session/{sessionId}/message/stream")]
|
||||||
|
public Task<MetisMessageResponse> SendStreamMessage(string sessionId, [Body]MetisMessageRequest request, [Header("x-api-key")] string metisToken);
|
||||||
|
}
|
|
@ -3,9 +3,16 @@
|
||||||
public interface IRestApiWrapper : IScopedDependency
|
public interface IRestApiWrapper : IScopedDependency
|
||||||
{
|
{
|
||||||
IKaveNegarRestApi KaveNegarRestApi { get; }
|
IKaveNegarRestApi KaveNegarRestApi { get; }
|
||||||
|
IMetisRestApi MetisRestApi { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RestApiWrapper : IRestApiWrapper
|
public class RestApiWrapper : IRestApiWrapper
|
||||||
{
|
{
|
||||||
|
private static readonly RefitSettings setting = new RefitSettings(new NewtonsoftJsonContentSerializer(new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||||
|
|
||||||
|
}));
|
||||||
public IKaveNegarRestApi KaveNegarRestApi => RestService.For<IKaveNegarRestApi>(RestAddress.BaseKaveNegar);
|
public IKaveNegarRestApi KaveNegarRestApi => RestService.For<IKaveNegarRestApi>(RestAddress.BaseKaveNegar);
|
||||||
|
public IMetisRestApi MetisRestApi => RestService.For<IMetisRestApi>("https://api.metisai.ir/api/v1", setting);
|
||||||
}
|
}
|
Loading…
Reference in New Issue