Compare commits
1 Commits
master
...
brizAssist
Author | SHA1 | Date |
---|---|---|
|
44361e73ce |
|
@ -11,10 +11,10 @@
|
|||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
|
|
|
@ -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 System.Diagnostics;
|
||||
using Brizco.Infrastructure.RestServices;
|
||||
|
||||
namespace Brizco.Api.Controllers;
|
||||
|
||||
|
@ -14,15 +15,15 @@ public class HealthController : ICarterModule
|
|||
.WithDisplayName("CheckHealth")
|
||||
.HasApiVersion(1.0);
|
||||
}
|
||||
public IResult GetHealth()
|
||||
public async Task<IResult> GetHealth([FromServices] IRestApiWrapper apiWrapper)
|
||||
{
|
||||
var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
|
||||
var check = new HealthCheck
|
||||
{
|
||||
Health = true,
|
||||
Version = version ?? string.Empty,
|
||||
StartAt = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("F"),
|
||||
StartAtPersian = new PersianDateTime(System.Diagnostics.Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
|
||||
StartAt = Process.GetCurrentProcess().StartTime.ToString("F"),
|
||||
StartAtPersian = new PersianDateTime(Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
|
||||
MachineName = Environment.MachineName
|
||||
};
|
||||
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
|
||||
ENV ASPNETCORE_URLS=https://0.0.0.0:8010
|
||||
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
|
||||
COPY ["Brizco.Api.csproj", "Brizco.Api/"]
|
||||
COPY ["Brizco.Api/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 Release -o /app/build
|
||||
RUN dotnet build "Brizco.Api.csproj" -c $configuration -o /app/build
|
||||
|
||||
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
|
||||
WORKDIR /app
|
||||
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>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Refit" Version="7.1.2" />
|
||||
<PackageReference Include="Refit" Version="7.2.1" />
|
||||
<PackageReference Include="Marten" Version="7.23.0" />
|
||||
<PackageReference Include="Refit.Newtonsoft.Json" Version="7.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -29,10 +30,13 @@
|
|||
<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>
|
||||
|
|
|
@ -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
|
||||
{
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue