Skip to content

Commit 97f53e6

Browse files
committed
Add Chat
1 parent 09da01f commit 97f53e6

File tree

85 files changed

+10323
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+10323
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ ehthumbs.db
4444
/user-service/user-service/.env
4545
/backend/user-service/.env
4646
/frontend/.env
47+
/addon/chat/Chatio/obj
48+
/addon/chat/Chatio/Properties/PublishProfiles
49+
/addon/chat/Chatio/Properties/ServiceDependencies/Chatiox - Web Deploy
50+
/addon/chat/Chatio/.vs/Chatio
51+
/addon/chat/Chatio/bin

addon/chat/Chatio/Chatio.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<UserSecretsId>ebee6fc2-2cd0-4bfd-8580-ad97b28e9c5c</UserSecretsId>
8+
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.10" />
13+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.10" />
14+
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
15+
<PackageReference Include="MongoDB.Driver" Version="3.0.0" />
16+
<PackageReference Include="OpenAI" Version="2.0.0" />
17+
<PackageReference Include="StackExchange.Redis" Version="2.8.16" />
18+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
19+
</ItemGroup>
20+
21+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<ActiveDebugProfile>http</ActiveDebugProfile>
5+
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
6+
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
7+
<NameOfLastUsedPublishProfile>C:\Users\Wwj\source\repos\project_ai\Chatio\Properties\PublishProfiles\Chatiox - Web Deploy.pubxml</NameOfLastUsedPublishProfile>
8+
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
10+
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
11+
</PropertyGroup>
12+
</Project>

addon/chat/Chatio/Chatio.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.9.34723.18
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chatio", "Chatio.csproj", "{03BC4C39-81A2-4440-A442-2B93B0C68BFA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{03BC4C39-81A2-4440-A442-2B93B0C68BFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{03BC4C39-81A2-4440-A442-2B93B0C68BFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{03BC4C39-81A2-4440-A442-2B93B0C68BFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{03BC4C39-81A2-4440-A442-2B93B0C68BFA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {73C44709-CDEF-4DF9-8E10-62DE730AA6DE}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Chatio.Configurations;
2+
3+
public class MongoDbSettings
4+
{
5+
public string ConnectionString { get; set; } = null!;
6+
public string DatabaseName { get; set; } = null!;
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Chatio.Configurations;
2+
3+
public class OpenAiSettings
4+
{
5+
public required string ApiKey { get; set; }
6+
public required string DefaultChatModel { get; set; }
7+
public required string DefaultEmbeddingModel { get; set; }
8+
public double DefaultTemperature { get; set; }
9+
public double DefaultTopP { get; set; }
10+
public double DefaultFrequencyPenalty { get; set; }
11+
public double DefaultPresencePenalty { get; set; }
12+
public int DefaultMaxTokens { get; set; }
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using Chatio.Dtos;
2+
using Chatio.Services;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace Chatio.Controllers;
6+
7+
[ApiController]
8+
[Route("api/[controller]")]
9+
public class AssistantController : ControllerBase
10+
{
11+
private readonly AssistantService _assistantService;
12+
13+
public AssistantController(AssistantService assistantService)
14+
{
15+
_assistantService = assistantService;
16+
}
17+
[HttpPost("chat")]
18+
public async Task Chat([FromBody] ChatRequest request)
19+
{
20+
Response.ContentType = "text/event-stream";
21+
22+
await foreach (var message in _assistantService.StreamAssistantResponseWithRag(request.Message))
23+
{
24+
var encodedMessage = Uri.EscapeDataString(message);
25+
await Response.WriteAsync($"data: {encodedMessage}\n\n");
26+
await Response.Body.FlushAsync();
27+
}
28+
}
29+
30+
[HttpGet("info")]
31+
public async Task<IActionResult> GetAssistantInfo()
32+
{
33+
var assistant = await _assistantService.GetOrCreateAssistantAsync();
34+
var assistantDto = AssistantDto.FromModel(assistant); // Convert model to DTO
35+
return Ok(assistantDto);
36+
}
37+
38+
[HttpGet("history")]
39+
public async Task<IActionResult> GetConversationHistory()
40+
{
41+
var messages = await _assistantService.GetConversationHistoryAsync();
42+
var messageDtos = messages.Select(AIMessageDTO.FromModel).ToList();
43+
return Ok(messageDtos);
44+
}
45+
46+
47+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Chatio.Models;
2+
using Chatio.Services;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace Chatio.Controllers;
6+
7+
[ApiController]
8+
[Route("api/[controller]")]
9+
public class ProductController : ControllerBase
10+
{
11+
private readonly ProductService _productService;
12+
13+
public ProductController(ProductService productService)
14+
{
15+
_productService = productService;
16+
}
17+
18+
[HttpGet("{id}")]
19+
public async Task<ActionResult<ProductModel>> GetProduct(string id)
20+
{
21+
var product = await _productService.GetProductByIdAsync(id);
22+
23+
if (product == null)
24+
{
25+
return NotFound();
26+
}
27+
28+
return product;
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Chatio.Services;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace Chatio.Controllers;
5+
6+
[ApiController]
7+
[Route("api/vector-search")]
8+
public class VectorSearchController : ControllerBase
9+
{
10+
private readonly VectorSearchService _vectorSearchService;
11+
12+
public VectorSearchController(VectorSearchService vectorSearchService)
13+
{
14+
_vectorSearchService = vectorSearchService;
15+
}
16+
17+
[HttpPost("malls")]
18+
public async Task<IActionResult> SearchSimilarMalls([FromBody] string inputText)
19+
{
20+
var result = await _vectorSearchService.SearchSimilarShoppingMallsAsync(inputText);
21+
return Ok(result); // Return both mall items and similarity scores
22+
}
23+
24+
[HttpPost("shops")]
25+
public async Task<IActionResult> SearchSimilarShops([FromBody] string inputText)
26+
{
27+
var result = await _vectorSearchService.SearchSimilarShopsAsync(inputText);
28+
return Ok(result); // Return both shop items and similarity scores
29+
}
30+
31+
[HttpPost("products")]
32+
public async Task<IActionResult> SearchSimilarProducts([FromBody] string inputText)
33+
{
34+
var result = await _vectorSearchService.SearchSimilarProductsAsync(inputText);
35+
return Ok(result); // Return both product items and similarity scores
36+
}
37+
}

0 commit comments

Comments
 (0)