Skip to content

Features/add deep seek #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2025
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
11 changes: 11 additions & 0 deletions BotSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Crontab", "sr
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\Infrastructure\BotSharp.Core.Rules\BotSharp.Core.Rules.csproj", "{AFD64412-4D6A-452E-82A2-79E5D8842E29}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -509,6 +511,14 @@ Global
{AFD64412-4D6A-452E-82A2-79E5D8842E29}.Release|Any CPU.Build.0 = Release|Any CPU
{AFD64412-4D6A-452E-82A2-79E5D8842E29}.Release|x64.ActiveCfg = Release|Any CPU
{AFD64412-4D6A-452E-82A2-79E5D8842E29}.Release|x64.Build.0 = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Debug|x64.ActiveCfg = Debug|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Debug|x64.Build.0 = Debug|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -569,6 +579,7 @@ Global
{7DA2DCD0-551B-432E-AA5C-22DDD3ED459B} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace BotSharp.Abstraction.Statistics.Enums;

public static class StatCategory
public static class StatsCategory
{
public static string LlmCost = "llm-cost";
public static string AgentLlmCost = "agent-llm-cost";
public static string AgentCall = "agent-call";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BotSharp.Abstraction.Statistics.Enums;

public enum StatsOperation
{
Add = 1,
Subtract = 2,
Reset = 3
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BotSharpStats
public string Group { get; set; } = null!;

[JsonPropertyName("data")]
public IDictionary<string, object> Data { get; set; } = new Dictionary<string, object>();
public IDictionary<string, double> Data { get; set; } = new Dictionary<string, double>();

private DateTime innerRecordTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace BotSharp.Abstraction.Statistics.Models;

public class BotSharpStatsInput
{
public string Category { get; set; }
public string Group { get; set; }
public List<StatsKeyValuePair> Data { get; set; } = [];
public DateTime RecordTime { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using BotSharp.Abstraction.Statistics.Enums;

namespace BotSharp.Abstraction.Statistics.Models;

public class StatsKeyValuePair
{
public string Key { get; set; }
public double Value { get; set; }
public StatsOperation Operation { get; set; }

public StatsKeyValuePair()
{

}

public StatsKeyValuePair(string key, double value, StatsOperation operation = StatsOperation.Add)
{
Key = key;
Value = value;
Operation = operation;
}

public override string ToString()
{
return $"[{Key}]: {Value} ({Operation})";
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using BotSharp.Abstraction.Statistics.Models;

namespace BotSharp.Abstraction.Statistics.Services;

public interface IBotSharpStatsService
{
bool UpdateStats(string resourceKey, BotSharpStatsInput input);
}
2 changes: 1 addition & 1 deletion src/Infrastructure/BotSharp.Core/Agents/AgentPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
services.AddScoped<ILlmProviderService, LlmProviderService>();
services.AddScoped<IAgentService, AgentService>();
services.AddScoped<IAgentHook, BasicAgentHook>();
services.AddScoped<IBotSharpStatService, BotSharpStatService>();
services.AddScoped<IBotSharpStatsService, BotSharpStatsService>();

services.AddScoped(provider =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,20 @@ public void AddToken(TokenStatsModel stats, RoleDialogModel message)
stat.SetState("llm_total_cost", total_cost, isNeedVersion: false, source: StateSource.Application);


var globalStats = _services.GetRequiredService<IBotSharpStatService>();
var body = new BotSharpStats
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
var body = new BotSharpStatsInput
{
Category = StatCategory.LlmCost,
Group = $"Agent: {message.CurrentAgentId}",
Data = new Dictionary<string, object>
{
{ "prompt_token_count_total", stats.PromptCount },
{ "completion_token_count_total", stats.CompletionCount },
{ "prompt_cost_total", deltaPromptCost },
{ "completion_cost_total", deltaCompletionCost }
},
RecordTime = DateTime.UtcNow
Category = StatsCategory.AgentLlmCost,
Group = message.CurrentAgentId,
RecordTime = DateTime.UtcNow,
Data = [
new StatsKeyValuePair("prompt_token_count_total", stats.PromptCount),
new StatsKeyValuePair("completion_token_count_total", stats.CompletionCount),
new StatsKeyValuePair("prompt_cost_total", deltaPromptCost),
new StatsKeyValuePair("completion_cost_total", deltaCompletionCost)
]
};
globalStats.UpdateLlmCost(body);
globalStats.UpdateStats("global-llm-cost", body);
}

public void PrintStatistics()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ public partial class FileRepository
var file = Directory.GetFiles(dir).FirstOrDefault(x => Path.GetFileName(x) == STATS_FILE);
if (file == null) return null;

var time = BuildRecordTime(recordTime);
var text = File.ReadAllText(file);
var list = JsonSerializer.Deserialize<List<BotSharpStats>>(text, _options);
var found = list?.FirstOrDefault(x => x.Category.IsEqualTo(category)
&& x.Group.IsEqualTo(group)
&& x.RecordTime == recordTime);
&& x.RecordTime == time);
return found;
}

Expand All @@ -38,11 +39,12 @@ public bool SaveGlobalStats(BotSharpStats body)
}
else
{
var time = BuildRecordTime(body.RecordTime);
var text = File.ReadAllText(file);
var list = JsonSerializer.Deserialize<List<BotSharpStats>>(text, _options);
var found = list?.FirstOrDefault(x => x.Category.IsEqualTo(body.Category)
&& x.Group.IsEqualTo(body.Group)
&& x.RecordTime == body.RecordTime);
&& x.RecordTime == time);

if (found != null)
{
Expand All @@ -65,4 +67,12 @@ public bool SaveGlobalStats(BotSharpStats body)

return true;
}

#region Private methods
private DateTime BuildRecordTime(DateTime date)
{
var recordDate = new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0);
return DateTime.SpecifyKind(recordDate, DateTimeKind.Utc);
}
#endregion
}

This file was deleted.

Loading