SA-29 added models and interface

This commit is contained in:
shchoholiev-opflo 2023-10-14 02:12:25 +00:00
parent 9b0410fb1f
commit bdc3e658cc
5 changed files with 64 additions and 6 deletions

View File

@ -0,0 +1,13 @@
using ShoppingAssistantApi.Application.Models.OpenAi;
namespace ShoppingAssistantApi.Application.IServices;
public interface IOpenAiService
{
Task<OpenAiMessage> GetChatCompletion(ChatCompletionRequest chat, CancellationToken cancellationToken);
/// <summary>
/// Retrieves a stream of tokens (pieces of words) based on provided chat.
/// </summary>
IAsyncEnumerable<string> GetChatCompletionStream(ChatCompletionRequest chat, CancellationToken cancellationToken);
}

View File

@ -0,0 +1,14 @@
namespace ShoppingAssistantApi.Application.Models.OpenAi;
public class ChatCompletionRequest
{
public string Model { get; set; } = "gpt-3.5-turbo";
public List<OpenAiMessage> Messages { get; set; }
public double Temperature { get; set; } = 0.7;
public int MaxTokens { get; set; } = 256;
public bool Stream { get; set; } = false;
}

View File

@ -0,0 +1,10 @@
using ShoppingAssistantApi.Domain.Enums;
namespace ShoppingAssistantApi.Application.Models.OpenAi;
public class OpenAiMessage
{
public OpenAiRole Role { get; set; }
public string Content { get; set; }
}

View File

@ -0,0 +1,8 @@
namespace ShoppingAssistantApi.Domain.Enums;
public enum OpenAiRole
{
System,
User,
Assistant
}

View File

@ -1,11 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ShoppingAssistantApi.Application.IServices;
using ShoppingAssistantApi.Application.Models.OpenAi;
namespace ShoppingAssistantApi.Infrastructure.Services;
public class OpenAiService
public class OpenAiService : IOpenAiService
{
private readonly HttpClient _httpClient;
public OpenAiService(HttpClient client)
{
_httpClient = client;
}
public Task<OpenAiMessage> GetChatCompletion(ChatCompletionRequest chat, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
public IAsyncEnumerable<string> GetChatCompletionStream(ChatCompletionRequest chat, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}