feat: 新增claude接口转换支持
This commit is contained in:
@@ -279,13 +279,10 @@ public class ThorChatCompletionsRequest
|
||||
|
||||
[JsonPropertyName("thinking")] public ThorChatClaudeThinking? Thinking { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 参数验证
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public IEnumerable<ValidationResult> Validate()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
[JsonPropertyName("enable_thinking")] public bool? EnableThinking { get; set; }
|
||||
|
||||
[JsonPropertyName("web_search_options")]
|
||||
public ThorChatWebSearchOptions? WebSearchOptions { get; set; } = null;
|
||||
|
||||
[JsonPropertyName("reasoning_effort")] public string? ReasoningEffort { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
|
||||
public class ThorChatWebSearchOptions
|
||||
{
|
||||
[JsonPropertyName("search_context_size")]
|
||||
public string? SearchContextSize { get; set; }
|
||||
|
||||
[JsonPropertyName("user_location")]
|
||||
public ThorUserLocation? UserLocation { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ThorUserLocation
|
||||
{
|
||||
[JsonPropertyName("type")] public required string Type { get; set; }
|
||||
|
||||
[JsonPropertyName("approximate")]
|
||||
public ThorUserLocationApproximate? Approximate { get; set; }
|
||||
}
|
||||
|
||||
public sealed class ThorUserLocationApproximate
|
||||
{
|
||||
[JsonPropertyName("city")]
|
||||
public string? City { get; set; }
|
||||
|
||||
[JsonPropertyName("country")]
|
||||
public string? Country { get; set; }
|
||||
|
||||
[JsonPropertyName("region")]
|
||||
public string? Region { get; set; }
|
||||
|
||||
[JsonPropertyName("timezone")]
|
||||
public string? Timezone { get; set; }
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Shared.Dtos.OpenAi;
|
||||
|
||||
@@ -25,56 +26,96 @@ public class ThorToolFunctionPropertyDefinition
|
||||
/// 表示字符串类型的函数对象
|
||||
/// </summary>
|
||||
String,
|
||||
|
||||
/// <summary>
|
||||
/// 表示整数类型的函数对象
|
||||
/// </summary>
|
||||
Integer,
|
||||
|
||||
/// <summary>
|
||||
/// 表示数字(包括浮点数等)类型的函数对象
|
||||
/// </summary>
|
||||
Number,
|
||||
|
||||
/// <summary>
|
||||
/// 表示对象类型的函数对象
|
||||
/// </summary>
|
||||
Object,
|
||||
|
||||
/// <summary>
|
||||
/// 表示数组类型的函数对象
|
||||
/// </summary>
|
||||
Array,
|
||||
|
||||
/// <summary>
|
||||
/// 表示布尔类型的函数对象
|
||||
/// </summary>
|
||||
Boolean,
|
||||
|
||||
/// <summary>
|
||||
/// 表示空值类型的函数对象
|
||||
/// </summary>
|
||||
Null
|
||||
}
|
||||
|
||||
public string typeStr = "object";
|
||||
|
||||
public string[] Types;
|
||||
|
||||
/// <summary>
|
||||
/// 必填的。函数参数对象类型。默认值为“object”。
|
||||
/// </summary>
|
||||
[JsonPropertyName("type")]
|
||||
public object Type { get; set; } = "object";
|
||||
public object Type
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Types is { Length: > 0 })
|
||||
{
|
||||
return Types;
|
||||
}
|
||||
|
||||
return typeStr;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value is JsonElement str)
|
||||
{
|
||||
switch (str.ValueKind)
|
||||
{
|
||||
case JsonValueKind.String:
|
||||
typeStr = value?.ToString();
|
||||
break;
|
||||
case JsonValueKind.Array:
|
||||
Types = JsonSerializer.Deserialize<string[]>(value?.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
typeStr = value?.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可选。“函数参数”列表,作为从参数名称映射的字典
|
||||
/// 对于描述类型的对象,可能还有可能的枚举值等等。
|
||||
/// </summary>
|
||||
[JsonPropertyName("properties")]
|
||||
public IDictionary<string, ThorToolFunctionPropertyDefinition?>? Properties { get; set; }
|
||||
public IDictionary<string, ThorToolFunctionPropertyDefinition>? Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可选。列出必需的“function arguments”列表。
|
||||
/// </summary>
|
||||
[JsonPropertyName("required")]
|
||||
public List<string>? Required { get; set; }
|
||||
public string[]? Required { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可选。是否允许附加属性。默认值为true。
|
||||
/// </summary>
|
||||
[JsonPropertyName("additionalProperties")]
|
||||
public bool? AdditionalProperties { get; set; }
|
||||
public object? AdditionalProperties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 可选。参数描述。
|
||||
@@ -219,11 +260,12 @@ public class ThorToolFunctionPropertyDefinition
|
||||
/// <param name="description"></param>
|
||||
/// <param name="enum"></param>
|
||||
/// <returns></returns>
|
||||
public static ThorToolFunctionPropertyDefinition DefineObject(IDictionary<string, ThorToolFunctionPropertyDefinition>? properties,
|
||||
List<string>? required,
|
||||
bool? additionalProperties,
|
||||
string? description,
|
||||
List<string>? @enum)
|
||||
public static ThorToolFunctionPropertyDefinition DefineObject(
|
||||
IDictionary<string, ThorToolFunctionPropertyDefinition>? properties,
|
||||
string[]? required,
|
||||
object? additionalProperties,
|
||||
string? description,
|
||||
List<string>? @enum)
|
||||
{
|
||||
return new ThorToolFunctionPropertyDefinition
|
||||
{
|
||||
@@ -242,7 +284,6 @@ public class ThorToolFunctionPropertyDefinition
|
||||
/// </summary>
|
||||
/// <param name="type">要转换的类型</param>
|
||||
/// <returns>给定类型的字符串表示形式</returns>
|
||||
|
||||
public static string ConvertTypeToString(FunctionObjectTypes type)
|
||||
{
|
||||
return type switch
|
||||
|
||||
Reference in New Issue
Block a user