From a13ee395c74c04f0d3d676dde8d52fcec452371c Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sat, 18 Oct 2025 13:23:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20x-api-key=20?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=B9=B6=E6=89=A9=E5=B1=95=20Anthropic=20?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=AD=97=E6=AE=B5=EF=BC=8C=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E8=B0=83=E7=94=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/OpenApiService.cs | 13 +++++++++---- .../Dtos/Anthropic/AnthropicChatCompletionDto.cs | 2 ++ .../Chats/AnthropicChatCompletionsService.cs | 2 +- .../Chats/ClaudiaChatCompletionsService.cs | 5 +++++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/OpenApiService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/OpenApiService.cs index f701bc26..23cf473c 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/OpenApiService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Application/Services/OpenApiService.cs @@ -193,11 +193,16 @@ public class OpenApiService : ApplicationService private string? GetTokenByHttpContext(HttpContext httpContext) { - // 获取Authorization头 - string authHeader = httpContext.Request.Headers["Authorization"]; + // 优先从 x-api-key 获取 + string apiKeyHeader = httpContext.Request.Headers["x-api-key"]; + if (!string.IsNullOrWhiteSpace(apiKeyHeader)) + { + return apiKeyHeader.Trim(); + } - // 检查是否有Bearer token - if (authHeader != null && authHeader.StartsWith("Bearer ")) + // 再检查 Authorization 头 + string authHeader = httpContext.Request.Headers["Authorization"]; + if (!string.IsNullOrWhiteSpace(authHeader) && authHeader.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) { return authHeader.Substring("Bearer ".Length).Trim(); } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Dtos/Anthropic/AnthropicChatCompletionDto.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Dtos/Anthropic/AnthropicChatCompletionDto.cs index 65c82081..7f25afc3 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Dtos/Anthropic/AnthropicChatCompletionDto.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain.Shared/Dtos/Anthropic/AnthropicChatCompletionDto.cs @@ -94,6 +94,8 @@ public class AnthropicChatCompletionDtoContentBlock [JsonPropertyName("tool_use_id")] public string? ToolUseId { get; set; } [JsonPropertyName("content")] public object? Content { get; set; } + + [JsonPropertyName("text")] public string? Text { get; set; } } public class AnthropicChatCompletionDto diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs index bba2f091..1552af59 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs @@ -169,7 +169,7 @@ public class AnthropicChatCompletionsService( var result = JsonSerializer.Deserialize(data, ThorJsonSerializer.DefaultOptions); - + result.SupplementalMultiplier(AnthropicChatCompletionsService.ClaudeMultiplier); yield return (eventType, result); } diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/ClaudiaChatCompletionsService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/ClaudiaChatCompletionsService.cs index 18fb1a46..6a24dcdf 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/ClaudiaChatCompletionsService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/ClaudiaChatCompletionsService.cs @@ -536,6 +536,11 @@ public sealed class ClaudiaChatCompletionsService( toolName = result.ContentBlock.Name; } + if (toolId is null) + { + continue; + } + yield return new ThorChatCompletionsResponse() { Choices =