feat: 支持 x-api-key 认证并扩展 Anthropic 响应字段,优化工具调用处理
This commit is contained in:
@@ -193,11 +193,16 @@ public class OpenApiService : ApplicationService
|
|||||||
|
|
||||||
private string? GetTokenByHttpContext(HttpContext httpContext)
|
private string? GetTokenByHttpContext(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
// 获取Authorization头
|
// 优先从 x-api-key 获取
|
||||||
string authHeader = httpContext.Request.Headers["Authorization"];
|
string apiKeyHeader = httpContext.Request.Headers["x-api-key"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(apiKeyHeader))
|
||||||
|
{
|
||||||
|
return apiKeyHeader.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
// 检查是否有Bearer token
|
// 再检查 Authorization 头
|
||||||
if (authHeader != null && authHeader.StartsWith("Bearer "))
|
string authHeader = httpContext.Request.Headers["Authorization"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(authHeader) && authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return authHeader.Substring("Bearer ".Length).Trim();
|
return authHeader.Substring("Bearer ".Length).Trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ public class AnthropicChatCompletionDtoContentBlock
|
|||||||
[JsonPropertyName("tool_use_id")] public string? ToolUseId { get; set; }
|
[JsonPropertyName("tool_use_id")] public string? ToolUseId { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("content")] public object? Content { get; set; }
|
[JsonPropertyName("content")] public object? Content { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("text")] public string? Text { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AnthropicChatCompletionDto
|
public class AnthropicChatCompletionDto
|
||||||
|
|||||||
@@ -536,6 +536,11 @@ public sealed class ClaudiaChatCompletionsService(
|
|||||||
toolName = result.ContentBlock.Name;
|
toolName = result.ContentBlock.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (toolId is null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
yield return new ThorChatCompletionsResponse()
|
yield return new ThorChatCompletionsResponse()
|
||||||
{
|
{
|
||||||
Choices =
|
Choices =
|
||||||
|
|||||||
Reference in New Issue
Block a user