feat: 增加 Claude 模型 Token 使用量倍数调整功能
This commit is contained in:
@@ -32,6 +32,25 @@ public class AnthropicStreamDto
|
||||
PromptTokensDetails = null,
|
||||
CompletionTokensDetails = null
|
||||
};
|
||||
|
||||
|
||||
public void SupplementalMultiplier(double multiplier)
|
||||
{
|
||||
if (this.Usage is not null)
|
||||
{
|
||||
this.Usage.CacheCreationInputTokens =
|
||||
(int)Math.Round((this.Usage.CacheCreationInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.CacheReadInputTokens =
|
||||
(int)Math.Round((this.Usage.CacheReadInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.InputTokens =
|
||||
(int)Math.Round((this.Usage.InputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.OutputTokens =
|
||||
(int)Math.Round((this.Usage.OutputTokens ?? 0) * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnthropicStreamErrorDto
|
||||
@@ -93,7 +112,7 @@ public class AnthropicChatCompletionDto
|
||||
|
||||
public object stop_sequence { get; set; }
|
||||
|
||||
public AnthropicCompletionDtoUsage Usage { get; set; }
|
||||
public AnthropicCompletionDtoUsage? Usage { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ThorUsageResponse TokenUsage => new ThorUsageResponse
|
||||
@@ -108,6 +127,24 @@ public class AnthropicChatCompletionDto
|
||||
PromptTokensDetails = null,
|
||||
CompletionTokensDetails = null
|
||||
};
|
||||
|
||||
public void SupplementalMultiplier(double multiplier)
|
||||
{
|
||||
if (this.Usage is not null)
|
||||
{
|
||||
this.Usage.CacheCreationInputTokens =
|
||||
(int)Math.Round((this.Usage?.CacheCreationInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.CacheReadInputTokens =
|
||||
(int)Math.Round((this.Usage?.CacheReadInputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.InputTokens =
|
||||
(int)Math.Round((this.Usage?.InputTokens ?? 0) * multiplier);
|
||||
|
||||
this.Usage.OutputTokens =
|
||||
(int)Math.Round((this.Usage?.OutputTokens ?? 0) * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AnthropicChatCompletionDtoContent
|
||||
|
||||
@@ -60,4 +60,19 @@ public record ThorChatCompletionsResponse
|
||||
/// </summary>
|
||||
[JsonPropertyName("error")]
|
||||
public ThorError? Error { get; set; }
|
||||
|
||||
public void SupplementalMultiplier(double multiplier)
|
||||
{
|
||||
if (this.Usage is not null)
|
||||
{
|
||||
this.Usage.InputTokens =
|
||||
(int)Math.Round((this.Usage.InputTokens ?? 0) * multiplier);
|
||||
this.Usage.OutputTokens =
|
||||
(int)Math.Round((this.Usage.OutputTokens ?? 0) * multiplier);
|
||||
this.Usage.CompletionTokens =
|
||||
(int)Math.Round((this.Usage.CompletionTokens ?? 0) * multiplier);
|
||||
this.Usage.PromptTokens =
|
||||
(int)Math.Round((this.Usage.PromptTokens ?? 0) * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user