add reasoning effort level
This commit is contained in:
parent
26ff3ce677
commit
b556040d8f
|
|
@ -46,7 +46,7 @@
|
|||
<PackageVersion Include="Whisper.net.Runtime" Version="1.8.1" />
|
||||
<PackageVersion Include="NCrontab" Version="3.3.3" />
|
||||
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.5" />
|
||||
<PackageVersion Include="OpenAI" Version="2.3.0" />
|
||||
<PackageVersion Include="OpenAI" Version="2.2.0-beta.4" />
|
||||
<PackageVersion Include="MailKit" Version="4.11.0" />
|
||||
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.8" />
|
||||
<PackageVersion Include="MySql.Data" Version="9.0.0" />
|
||||
|
|
|
|||
|
|
@ -3,4 +3,5 @@ namespace BotSharp.Abstraction.Agents.Constants;
|
|||
public static class LlmConstant
|
||||
{
|
||||
public const int DEFAULT_MAX_OUTPUT_TOKEN = 1024;
|
||||
public const string DEFAULT_REASONING_EFFORT_LEVEL = "low";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,11 @@ public class AgentLlmConfig
|
|||
[JsonPropertyName("max_output_tokens")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public int? MaxOutputTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Reasoning effort level
|
||||
/// </summary>
|
||||
[JsonPropertyName("reasoning_effort_level")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? ReasoningEffortLevel { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public class AgentLlmConfigMongoElement
|
|||
public bool IsInherit { get; set; }
|
||||
public int MaxRecursionDepth { get; set; }
|
||||
public int? MaxOutputTokens { get; set; }
|
||||
public string? ReasoningEffortLevel { get; set; }
|
||||
|
||||
public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config)
|
||||
{
|
||||
|
|
@ -21,7 +22,8 @@ public class AgentLlmConfigMongoElement
|
|||
Model = config.Model,
|
||||
IsInherit = config.IsInherit,
|
||||
MaxRecursionDepth = config.MaxRecursionDepth,
|
||||
MaxOutputTokens = config.MaxOutputTokens
|
||||
MaxOutputTokens = config.MaxOutputTokens,
|
||||
ReasoningEffortLevel = config.ReasoningEffortLevel
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -35,7 +37,8 @@ public class AgentLlmConfigMongoElement
|
|||
Model = config.Model,
|
||||
IsInherit = config.IsInherit,
|
||||
MaxRecursionDepth = config.MaxRecursionDepth,
|
||||
MaxOutputTokens = config.MaxOutputTokens
|
||||
MaxOutputTokens = config.MaxOutputTokens,
|
||||
ReasoningEffortLevel = config.ReasoningEffortLevel
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -504,13 +504,42 @@ public class ChatCompletionProvider : IChatCompletion
|
|||
? tokens
|
||||
: agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN;
|
||||
|
||||
var level = state.GetState("reasoning_effort_level")
|
||||
.IfNullOrEmptyAs(agent?.LlmConfig?.ReasoningEffortLevel ?? string.Empty)
|
||||
.IfNullOrEmptyAs(LlmConstant.DEFAULT_REASONING_EFFORT_LEVEL);
|
||||
var reasoningEffortLevel = ParseReasoningEffortLevel(level);
|
||||
|
||||
return new ChatCompletionOptions()
|
||||
{
|
||||
Temperature = temperature,
|
||||
MaxOutputTokenCount = maxTokens
|
||||
MaxOutputTokenCount = maxTokens,
|
||||
ReasoningEffortLevel = reasoningEffortLevel
|
||||
};
|
||||
}
|
||||
|
||||
private ChatReasoningEffortLevel? ParseReasoningEffortLevel(string? level)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(level) || !_defaultTemperature.ContainsKey(_model))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var effortLevel = ChatReasoningEffortLevel.Low;
|
||||
switch (level.ToLower())
|
||||
{
|
||||
case "medium":
|
||||
effortLevel = ChatReasoningEffortLevel.Medium;
|
||||
break;
|
||||
case "high":
|
||||
effortLevel = ChatReasoningEffortLevel.High;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return effortLevel;
|
||||
}
|
||||
|
||||
public void SetModelName(string model)
|
||||
{
|
||||
_model = model;
|
||||
|
|
|
|||
|
|
@ -629,7 +629,7 @@ public class QdrantDb : IVectorDb
|
|||
return new OrderBy
|
||||
{
|
||||
Key = sort.Field,
|
||||
Direction = sort.Order == "asc" ? Direction.Asc : Direction.Desc
|
||||
Direction = sort.Order.IsEqualTo("asc") ? Direction.Asc : Direction.Desc
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue