Skip to content

Commit 4d13cd2

Browse files
authored
Merge pull request #1126 from iceljc/features/refine-vector-store
add reasoning effort level
2 parents 26ff3ce + b556040 commit 4d13cd2

6 files changed

Lines changed: 45 additions & 5 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<PackageVersion Include="Whisper.net.Runtime" Version="1.8.1" />
4747
<PackageVersion Include="NCrontab" Version="3.3.3" />
4848
<PackageVersion Include="Azure.AI.OpenAI" Version="2.2.0-beta.5" />
49-
<PackageVersion Include="OpenAI" Version="2.3.0" />
49+
<PackageVersion Include="OpenAI" Version="2.2.0-beta.4" />
5050
<PackageVersion Include="MailKit" Version="4.11.0" />
5151
<PackageVersion Include="Microsoft.Data.Sqlite" Version="8.0.8" />
5252
<PackageVersion Include="MySql.Data" Version="9.0.0" />

src/Infrastructure/BotSharp.Abstraction/Agents/Constants/LlmConstant.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ namespace BotSharp.Abstraction.Agents.Constants;
33
public static class LlmConstant
44
{
55
public const int DEFAULT_MAX_OUTPUT_TOKEN = 1024;
6+
public const string DEFAULT_REASONING_EFFORT_LEVEL = "low";
67
}

src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentLlmConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ public class AgentLlmConfig
3434
[JsonPropertyName("max_output_tokens")]
3535
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
3636
public int? MaxOutputTokens { get; set; }
37+
38+
/// <summary>
39+
/// Reasoning effort level
40+
/// </summary>
41+
[JsonPropertyName("reasoning_effort_level")]
42+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
43+
public string? ReasoningEffortLevel { get; set; }
3744
}

src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentLlmConfigMongoElement.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class AgentLlmConfigMongoElement
1010
public bool IsInherit { get; set; }
1111
public int MaxRecursionDepth { get; set; }
1212
public int? MaxOutputTokens { get; set; }
13+
public string? ReasoningEffortLevel { get; set; }
1314

1415
public static AgentLlmConfigMongoElement? ToMongoElement(AgentLlmConfig? config)
1516
{
@@ -21,7 +22,8 @@ public class AgentLlmConfigMongoElement
2122
Model = config.Model,
2223
IsInherit = config.IsInherit,
2324
MaxRecursionDepth = config.MaxRecursionDepth,
24-
MaxOutputTokens = config.MaxOutputTokens
25+
MaxOutputTokens = config.MaxOutputTokens,
26+
ReasoningEffortLevel = config.ReasoningEffortLevel
2527
};
2628
}
2729

@@ -35,7 +37,8 @@ public class AgentLlmConfigMongoElement
3537
Model = config.Model,
3638
IsInherit = config.IsInherit,
3739
MaxRecursionDepth = config.MaxRecursionDepth,
38-
MaxOutputTokens = config.MaxOutputTokens
40+
MaxOutputTokens = config.MaxOutputTokens,
41+
ReasoningEffortLevel = config.ReasoningEffortLevel
3942
};
4043
}
4144
}

src/Plugins/BotSharp.Plugin.OpenAI/Providers/Chat/ChatCompletionProvider.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,42 @@ private ChatCompletionOptions InitChatCompletionOption(Agent agent)
504504
? tokens
505505
: agent.LlmConfig?.MaxOutputTokens ?? LlmConstant.DEFAULT_MAX_OUTPUT_TOKEN;
506506

507+
var level = state.GetState("reasoning_effort_level")
508+
.IfNullOrEmptyAs(agent?.LlmConfig?.ReasoningEffortLevel ?? string.Empty)
509+
.IfNullOrEmptyAs(LlmConstant.DEFAULT_REASONING_EFFORT_LEVEL);
510+
var reasoningEffortLevel = ParseReasoningEffortLevel(level);
511+
507512
return new ChatCompletionOptions()
508513
{
509514
Temperature = temperature,
510-
MaxOutputTokenCount = maxTokens
515+
MaxOutputTokenCount = maxTokens,
516+
ReasoningEffortLevel = reasoningEffortLevel
511517
};
512518
}
513519

520+
private ChatReasoningEffortLevel? ParseReasoningEffortLevel(string? level)
521+
{
522+
if (string.IsNullOrWhiteSpace(level) || !_defaultTemperature.ContainsKey(_model))
523+
{
524+
return null;
525+
}
526+
527+
var effortLevel = ChatReasoningEffortLevel.Low;
528+
switch (level.ToLower())
529+
{
530+
case "medium":
531+
effortLevel = ChatReasoningEffortLevel.Medium;
532+
break;
533+
case "high":
534+
effortLevel = ChatReasoningEffortLevel.High;
535+
break;
536+
default:
537+
break;
538+
}
539+
540+
return effortLevel;
541+
}
542+
514543
public void SetModelName(string model)
515544
{
516545
_model = model;

src/Plugins/BotSharp.Plugin.Qdrant/QdrantDb.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ public async Task<bool> DeleteCollectionShapshot(string collectionName, string s
629629
return new OrderBy
630630
{
631631
Key = sort.Field,
632-
Direction = sort.Order == "asc" ? Direction.Asc : Direction.Desc
632+
Direction = sort.Order.IsEqualTo("asc") ? Direction.Asc : Direction.Desc
633633
};
634634
}
635635

0 commit comments

Comments
 (0)