Compare commits

..

No commits in common. "brizAssistante" and "master" have entirely different histories.

14 changed files with 15 additions and 260 deletions

View File

@ -11,10 +11,10 @@
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log

44
.vscode/launch.json vendored
View File

@ -1,44 +0,0 @@
{
"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"
}
}
]
}

101
.vscode/tasks.json vendored
View File

@ -1,101 +0,0 @@
{
"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"
}
}
]
}

View File

@ -1,31 +0,0 @@
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);
}
}

View File

@ -1,6 +1,5 @@
using MD.PersianDateTime.Standard;
using System.Diagnostics;
using Brizco.Infrastructure.RestServices;
namespace Brizco.Api.Controllers;
@ -15,15 +14,15 @@ public class HealthController : ICarterModule
.WithDisplayName("CheckHealth")
.HasApiVersion(1.0);
}
public async Task<IResult> GetHealth([FromServices] IRestApiWrapper apiWrapper)
public IResult GetHealth()
{
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
var check = new HealthCheck
{
Health = true,
Version = version ?? string.Empty,
StartAt = Process.GetCurrentProcess().StartTime.ToString("F"),
StartAtPersian = new PersianDateTime(Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
StartAt = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("F"),
StartAtPersian = new PersianDateTime(System.Diagnostics.Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
MachineName = Environment.MachineName
};
var process = Process.GetCurrentProcess();

View File

@ -1,24 +1,22 @@
#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
ENV ASPNETCORE_URLS=https://0.0.0.0:8010
WORKDIR /app
EXPOSE 5245
EXPOSE 8010
ENV ASPNETCORE_URLS=http://+:5245
USER app
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG configuration=Release
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["Brizco.Api/Brizco.Api.csproj", "Brizco.Api/"]
COPY ["Brizco.Api.csproj", "Brizco.Api/"]
RUN dotnet restore "Brizco.Api/Brizco.Api.csproj"
COPY . .
WORKDIR "/src/Brizco.Api"
RUN dotnet build "Brizco.Api.csproj" -c $configuration -o /app/build
RUN dotnet build "Brizco.Api.csproj" -c Release -o /app/build
FROM build AS publish
ARG configuration=Release
RUN dotnet publish "Brizco.Api.csproj" -c $configuration -o /app/publish /p:UseAppHost=false
RUN dotnet publish "Brizco.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Brizco.Api.dll"]
ENTRYPOINT ["dotnet", "Berizco.Api.dll"]

View File

@ -1 +0,0 @@
namespace Brizco.Domain.CommandQueries.Commands;

View File

@ -7,9 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Refit" Version="7.2.1" />
<PackageReference Include="Refit" Version="7.1.2" />
<PackageReference Include="Marten" Version="7.23.0" />
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
</ItemGroup>
<ItemGroup>
@ -30,13 +29,10 @@
<Using Include="Brizco.Core.Abstracts" />
<Using Include="Brizco.Domain.Models.Settings" />
<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.Repository.Repositories.Marten" />
<Using Include="Microsoft.Extensions.Logging" />
<Using Include="Microsoft.Extensions.Options" />
<Using Include="Newtonsoft.Json" />
<Using Include="Refit" />
<Using Include="System.Linq.Expressions" />
</ItemGroup>

View File

@ -1,9 +0,0 @@
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; }
}

View File

@ -1,12 +0,0 @@
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";
}

View File

@ -1,13 +0,0 @@
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;
}

View File

@ -1,7 +0,0 @@
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);
}

View File

@ -1,13 +0,0 @@
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);
}

View File

@ -3,16 +3,9 @@
public interface IRestApiWrapper : IScopedDependency
{
IKaveNegarRestApi KaveNegarRestApi { get; }
IMetisRestApi MetisRestApi { get; }
}
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 IMetisRestApi MetisRestApi => RestService.For<IMetisRestApi>("https://api.metisai.ir/api/v1", setting);
}