Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
namespace BotSharp.Abstraction.MLTasks.Settings;

/// <summary>
/// Cost per 1K tokens
/// </summary>
public class LlmCostSetting
{
#region Text token
public float TextInputCost { get; set; } = 0f;
public float CachedTextInputCost { get; set; } = 0f;
public float CachedTextInputWriteCost { get; set; } = 0f;
public float TextOutputCost { get; set; } = 0f;
public string DefaultServiceTier { get; set; } = "standard";
public IList<LlmTextTokenCostTier>? TextTokenCostTiers { get; set; }
#endregion

#region Audio token
public float AudioInputCost { get; set; } = 0f;
public float CachedAudioInputCost { get; set; } = 0f;
public float AudioOutputCost { get; set; } = 0f;
#endregion

#region Image token
public float ImageInputCost { get; set; } = 0f;
public float CachedImageInputCost { get; set; } = 0f;
public float ImageOutputCost { get; set; } = 0f;
#endregion

#region Image
public IList<LlmImageCost>? ImageCosts { get; set; }
#endregion

public LlmTextTokenCostTier? GetTextTokenCostTier(long inputTokens, string? serviceTier = null)
{
var selectedServiceTier = string.IsNullOrWhiteSpace(serviceTier)
? DefaultServiceTier
: serviceTier;

return TextTokenCostTiers?.FirstOrDefault(x =>
string.Equals(x.ServiceTier, selectedServiceTier, StringComparison.OrdinalIgnoreCase)
&& (!x.InputTokensGreaterThan.HasValue || inputTokens > x.InputTokensGreaterThan.Value)
&& (!x.InputTokensLessThanOrEqual.HasValue || inputTokens <= x.InputTokensLessThanOrEqual.Value));
}
}

public class LlmTextTokenCostTier
{
public string ServiceTier { get; set; } = "standard";
public long? InputTokensGreaterThan { get; set; }
public long? InputTokensLessThanOrEqual { get; set; }
public float TextInputCost { get; set; }
public float CachedTextInputCost { get; set; }
public float CachedTextInputWriteCost { get; set; }
public float TextOutputCost { get; set; }
}

public class LlmImageCost
{
/// <summary>
/// Attributes: e.g., [quality]: "medium", [size] = "1024x1024"
/// </summary>
public Dictionary<string, string> Attributes { get; set; } = [];
public float Cost { get; set; } = 0f;
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,70 +176,6 @@ public class ModelParamSetting
public IEnumerable<string>? Options { get; set; }
}


/// <summary>
/// Cost per 1K tokens
/// </summary>
public class LlmCostSetting
{
#region Text token
public float TextInputCost { get; set; } = 0f;
public float CachedTextInputCost { get; set; } = 0f;
public float CachedTextInputWriteCost { get; set; } = 0f;
public float TextOutputCost { get; set; } = 0f;
public string DefaultServiceTier { get; set; } = "standard";
public IList<LlmTextTokenCostTier>? TextTokenCostTiers { get; set; }
#endregion

#region Audio token
public float AudioInputCost { get; set; } = 0f;
public float CachedAudioInputCost { get; set; } = 0f;
public float AudioOutputCost { get; set; } = 0f;
#endregion

#region Image token
public float ImageInputCost { get; set; } = 0f;
public float CachedImageInputCost { get; set; } = 0f;
public float ImageOutputCost { get; set; } = 0f;
#endregion

#region Image
public IList<LlmImageCost>? ImageCosts { get; set; }
#endregion

public LlmTextTokenCostTier? GetTextTokenCostTier(long inputTokens, string? serviceTier = null)
{
var selectedServiceTier = string.IsNullOrWhiteSpace(serviceTier)
? DefaultServiceTier
: serviceTier;

return TextTokenCostTiers?.FirstOrDefault(x =>
string.Equals(x.ServiceTier, selectedServiceTier, StringComparison.OrdinalIgnoreCase)
&& (!x.InputTokensGreaterThan.HasValue || inputTokens > x.InputTokensGreaterThan.Value)
&& (!x.InputTokensLessThanOrEqual.HasValue || inputTokens <= x.InputTokensLessThanOrEqual.Value));
}
}

public class LlmTextTokenCostTier
{
public string ServiceTier { get; set; } = "standard";
public long? InputTokensGreaterThan { get; set; }
public long? InputTokensLessThanOrEqual { get; set; }
public float TextInputCost { get; set; }
public float CachedTextInputCost { get; set; }
public float CachedTextInputWriteCost { get; set; }
public float TextOutputCost { get; set; }
}

public class LlmImageCost
{
/// <summary>
/// Attributes: e.g., [quality]: "medium", [size] = "1024x1024"
/// </summary>
public Dictionary<string, string> Attributes { get; set; } = [];
public float Cost { get; set; } = 0f;
}

public enum LlmModelType
{
All = 0,
Expand Down
Loading