feat: 兼容cline
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAiDto;
|
||||
using System.Collections;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Yi.Framework.AiHub.Application.Contracts.Dtos.OpenAiDto;
|
||||
|
||||
public class ChatCompletionsInput
|
||||
{
|
||||
public List<OpenAiMessage> Messages { get; set; }
|
||||
|
||||
public bool Stream { get; set; }
|
||||
public bool? Stream { get; set; }
|
||||
|
||||
public string? Prompt { get; set; }
|
||||
public string Model { get; set; }
|
||||
@@ -16,6 +19,32 @@ public class ChatCompletionsInput
|
||||
|
||||
public class OpenAiMessage
|
||||
{
|
||||
public string Role { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string? Role { get; set; }
|
||||
public object? Content { get; set; }
|
||||
|
||||
public string ConvertContent()
|
||||
{
|
||||
if (Content is string content)
|
||||
{
|
||||
return content;
|
||||
}
|
||||
|
||||
if (Content is JsonElement jsonElement && jsonElement.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
var contentItems = jsonElement.Deserialize<List<ContentItem>>();
|
||||
var currentContentItem = contentItems.FirstOrDefault();
|
||||
if (currentContentItem.type == "text")
|
||||
{
|
||||
return currentContentItem.text;
|
||||
}
|
||||
}
|
||||
|
||||
throw new UserFriendlyException("当前格式暂不支持");
|
||||
}
|
||||
}
|
||||
|
||||
public class ContentItem
|
||||
{
|
||||
public string? type { get; set; }
|
||||
public string? text { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user