Skip to content

Commit

Permalink
修复异常错误
Browse files Browse the repository at this point in the history
  • Loading branch information
239573049 committed Dec 16, 2024
1 parent 3d242ed commit e47f057
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Thor.Service/Infrastructure/Helper/TokenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static TokenHelper()
/// <param name="content"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetTotalTokens(params string[] content)
public static int GetTotalTokens(params string?[] content)
{
return content.Sum((s => RefGetTokens(ref s)));
}
Expand Down
10 changes: 3 additions & 7 deletions src/Thor.Service/Service/ChatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,6 @@ await userService.ConsumeAsync(user!.Id, (long)quota, (int)requestToken, token?.
// 判断请求token数量是否超过额度
if (quota > user.ResidualCredit) throw new InsufficientQuotaException("账号余额不足请充值");

var circuitBreaker = new CircuitBreaker(3, TimeSpan.FromSeconds(10));

ThorChatCompletionsResponse result = await openService.ChatCompletionsAsync(request, platformOptions);

await context.Response.WriteAsJsonAsync(result);
Expand All @@ -883,7 +881,7 @@ await userService.ConsumeAsync(user!.Id, (long)quota, (int)requestToken, token?.
else
{
responseToken =
TokenHelper.GetTotalTokens(result?.Choices?.Select(x => x.Delta?.Content).ToArray());
TokenHelper.GetTotalTokens(result?.Choices?.Select(x => x.Delta?.Content).ToArray() ?? []);
}
}
else
Expand All @@ -896,13 +894,11 @@ await userService.ConsumeAsync(user!.Id, (long)quota, (int)requestToken, token?.
// 判断请求token数量是否超过额度
if (quota > user.ResidualCredit) throw new InsufficientQuotaException("账号余额不足请充值");

var circuitBreaker = new CircuitBreaker(3, TimeSpan.FromSeconds(10));

ThorChatCompletionsResponse result = await openService.ChatCompletionsAsync(request, platformOptions);
var result = await openService.ChatCompletionsAsync(request, platformOptions);

await context.Response.WriteAsJsonAsync(result);

responseToken = TokenHelper.GetTokens(result.Choices.FirstOrDefault()?.Delta.Content ?? string.Empty);
responseToken = TokenHelper.GetTokens(result.Choices?.FirstOrDefault()?.Delta.Content ?? string.Empty);
}

if (request.ResponseFormat?.JsonSchema is not null)
Expand Down

0 comments on commit e47f057

Please sign in to comment.