feat: 兼容cline
This commit is contained in:
@@ -36,27 +36,31 @@ public class OpenApiService : ApplicationService
|
||||
/// <param name="input"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
[HttpPost("openApi/v1/chat/completions")]
|
||||
public async Task ChatCompletionsAsync(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>();
|
||||
foreach (var aiChatContextDto in input.Messages)
|
||||
{
|
||||
if (aiChatContextDto.Role == "assistant")
|
||||
{
|
||||
history.Add(ChatMessage.CreateAssistantMessage(aiChatContextDto.Content));
|
||||
history.Add(ChatMessage.CreateAssistantMessage(aiChatContextDto.ConvertContent()));
|
||||
}
|
||||
else if (aiChatContextDto.Role == "user")
|
||||
{
|
||||
history.Add(ChatMessage.CreateUserMessage(aiChatContextDto.Content));
|
||||
history.Add(ChatMessage.CreateUserMessage(aiChatContextDto.ConvertContent()));
|
||||
}
|
||||
else if (aiChatContextDto.Role == "system")
|
||||
{
|
||||
history.Add(ChatMessage.CreateSystemMessage(aiChatContextDto.ConvertContent()));
|
||||
}
|
||||
}
|
||||
|
||||
//是否使用流式传输
|
||||
if (input.Stream)
|
||||
if (input.Stream == true)
|
||||
{
|
||||
//ai网关代理httpcontext
|
||||
await _aiGateWayManager.CompleteChatStreamForStatisticsAsync(_httpContextAccessor.HttpContext, input.Model,
|
||||
|
||||
Reference in New Issue
Block a user