mirror of
https://github.com/Shchoholiev/shopping-assistant-api.git
synced 2025-04-12 01:48:49 +00:00
SA-29 all bugs fixed
This commit is contained in:
parent
5ddd5c9ada
commit
ef35d6dea2
@ -1,93 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using ShoppingAssistantApi.Application.IServices;
|
|
||||||
using ShoppingAssistantApi.Application.Models.OpenAi;
|
|
||||||
using ShoppingAssistantApi.Domain.Enums;
|
|
||||||
|
|
||||||
namespace ShoppingAssistantApi.Api.Controllers;
|
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class WeatherForecastController : ControllerBase
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
|
||||||
|
|
||||||
private readonly IOpenAiService _openAiService;
|
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger, IOpenAiService openAiService)
|
|
||||||
{
|
|
||||||
_openAiService = openAiService;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet(Name = "GetWeatherForecast")]
|
|
||||||
public IEnumerable<WeatherForecast> Get()
|
|
||||||
{
|
|
||||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
||||||
})
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("open-ai-test-simple")]
|
|
||||||
public async Task<OpenAiMessage> OpenAiTest(string text)
|
|
||||||
{
|
|
||||||
return await _openAiService.GetChatCompletion(new ChatCompletionRequest
|
|
||||||
{
|
|
||||||
Messages = new List<OpenAiMessage>
|
|
||||||
{
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.System.RequestConvert(),
|
|
||||||
Content = "You are a Shopping Assistant that helps people find product recommendations. Ask user additional questions if more context needed.\nYou must return data with one of the prefixes:\n[Question] - return question. Each question must have suggestions.\n[Options] - return semicolon separated suggestion how to answer to a question\n[Message] - return text\n[Products] - return semicolon separated product names"
|
|
||||||
},
|
|
||||||
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.Assistant.RequestConvert(),
|
|
||||||
Content = "[Question] What are you looking for?\n[Options] Bicycle, Laptop"
|
|
||||||
},
|
|
||||||
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.User.RequestConvert(),
|
|
||||||
Content = text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpPost("open-ai-test-streamed")]
|
|
||||||
public IAsyncEnumerable<string> OpenAiTestStrean(string text)
|
|
||||||
{
|
|
||||||
return _openAiService.GetChatCompletionStream(new ChatCompletionRequest
|
|
||||||
{
|
|
||||||
Messages = new List<OpenAiMessage>
|
|
||||||
{
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.System.RequestConvert(),
|
|
||||||
Content = "You are a Shopping Assistant that helps people find product recommendations. Ask user additional questions if more context needed.\nYou must return data with one of the prefixes:\n[Question] - return question. Each question must have suggestions.\n[Options] - return semicolon separated suggestion how to answer to a question\n[Message] - return text\n[Products] - return semicolon separated product names"
|
|
||||||
},
|
|
||||||
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.Assistant.RequestConvert(),
|
|
||||||
Content = "[Question] What are you looking for?\n[Options] Bicycle, Laptop"
|
|
||||||
},
|
|
||||||
|
|
||||||
new OpenAiMessage
|
|
||||||
{
|
|
||||||
Role = OpenAiRole.User.RequestConvert(),
|
|
||||||
Content = text
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, CancellationToken.None);
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,7 +12,7 @@ builder.Services.AddJWTTokenAuthentication(builder.Configuration);
|
|||||||
builder.Services.AddMapper();
|
builder.Services.AddMapper();
|
||||||
builder.Services.AddInfrastructure();
|
builder.Services.AddInfrastructure();
|
||||||
builder.Services.AddServices();
|
builder.Services.AddServices();
|
||||||
builder.Services.AddOpenAiHttpClient(builder.Configuration);
|
builder.Services.AddHttpClient(builder.Configuration);
|
||||||
builder.Services.AddGraphQl();
|
builder.Services.AddGraphQl();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
|
@ -21,4 +21,8 @@
|
|||||||
<ProjectReference Include="..\ShoppingAssistantApi.Persistance\ShoppingAssistantApi.Persistance.csproj" />
|
<ProjectReference Include="..\ShoppingAssistantApi.Persistance\ShoppingAssistantApi.Persistance.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Controllers\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
namespace ShoppingAssistantApi.Api;
|
|
||||||
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateOnly Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
}
|
|
@ -22,15 +22,15 @@ public static class ServicesExtention
|
|||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IServiceCollection AddOpenAiHttpClient(this IServiceCollection services, IConfiguration configuration)
|
public static IServiceCollection AddHttpClient(this IServiceCollection services, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
services.AddHttpClient(
|
services.AddHttpClient(
|
||||||
"OpenAiHttpClient",
|
"OpenAiHttpClient",
|
||||||
client =>
|
client =>
|
||||||
{
|
{
|
||||||
client.BaseAddress = new Uri(configuration.GetValue<string>("OpenAi:OpenAiApiUri"));
|
client.BaseAddress = new Uri(configuration.GetValue<string>("ApiUri"));
|
||||||
client.DefaultRequestHeaders.Authorization =
|
client.DefaultRequestHeaders.Authorization =
|
||||||
new AuthenticationHeaderValue("Bearer", configuration.GetValue<string>("OpenAi:OpenAiApiKey"));
|
new AuthenticationHeaderValue("Bearer", configuration.GetValue<string>("ApiKey"));
|
||||||
});
|
});
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
Loading…
Reference in New Issue
Block a user