feat: 新增支持Prompt
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Dm.util;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using OpenAI.Chat;
|
||||
@@ -36,13 +37,17 @@ public class OpenApiService : ApplicationService
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/chat/completions")]
|
||||
public async Task ChatCompletionsAsync([FromBody]ChatCompletionsInput input, CancellationToken cancellationToken)
|
||||
public async Task ChatCompletionsAsync([FromBody] ChatCompletionsInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
//前面都是校验,后面才是真正的调用
|
||||
var httpContext = this._httpContextAccessor.HttpContext;
|
||||
|
||||
|
||||
var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext));
|
||||
var history = new List<ChatMessage>();
|
||||
if (!string.IsNullOrWhiteSpace(input.Prompt))
|
||||
{
|
||||
history.add(ChatMessage.CreateSystemMessage(input.Prompt));
|
||||
}
|
||||
foreach (var aiChatContextDto in input.Messages)
|
||||
{
|
||||
if (aiChatContextDto.Role == "assistant")
|
||||
@@ -53,7 +58,7 @@ public class OpenApiService : ApplicationService
|
||||
{
|
||||
history.Add(ChatMessage.CreateUserMessage(aiChatContextDto.ConvertContent()));
|
||||
}
|
||||
else if (aiChatContextDto.Role == "system")
|
||||
else if (aiChatContextDto.Role == "system")
|
||||
{
|
||||
history.Add(ChatMessage.CreateSystemMessage(aiChatContextDto.ConvertContent()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user