feat: 新增支持Prompt

This commit is contained in:
ccnetcore
2025-07-09 23:11:57 +08:00
parent d59f40dfba
commit 17412d7de7

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http; using Dm.util;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using OpenAI.Chat; using OpenAI.Chat;
@@ -43,6 +44,10 @@ public class OpenApiService : ApplicationService
var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext)); var userId = await _tokenManager.GetUserIdAsync(GetTokenByHttpContext(httpContext));
var history = new List<ChatMessage>(); var history = new List<ChatMessage>();
if (!string.IsNullOrWhiteSpace(input.Prompt))
{
history.add(ChatMessage.CreateSystemMessage(input.Prompt));
}
foreach (var aiChatContextDto in input.Messages) foreach (var aiChatContextDto in input.Messages)
{ {
if (aiChatContextDto.Role == "assistant") if (aiChatContextDto.Role == "assistant")