Merge pull request #847 from iceljc/features/add-deep-seek

rename
This commit is contained in:
iceljc 2025-01-28 10:57:11 -06:00 committed by GitHub
commit 49f8565c71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 38 additions and 38 deletions

View file

@ -120,7 +120,7 @@ public interface IBotSharpRepository : IHaveServiceProvider
#endregion
#region Statistics
BotSharpStats? GetGlobalStats(string category, string group, DateTime recordTime) => throw new NotImplementedException();
BotSharpStats? GetGlobalStats(string metric, string dimension, DateTime recordTime) => throw new NotImplementedException();
bool SaveGlobalStats(BotSharpStats body) => throw new NotImplementedException();
#endregion

View file

@ -2,11 +2,11 @@ namespace BotSharp.Abstraction.Statistics.Models;
public class BotSharpStats
{
[JsonPropertyName("category")]
public string Category { get; set; } = null!;
[JsonPropertyName("metric")]
public string Metric { get; set; } = null!;
[JsonPropertyName("group")]
public string Group { get; set; } = null!;
[JsonPropertyName("dimension")]
public string Dimension { get; set; } = null!;
[JsonPropertyName("data")]
public IDictionary<string, double> Data { get; set; } = new Dictionary<string, double>();
@ -29,6 +29,6 @@ public class BotSharpStats
public override string ToString()
{
return $"{Category}-{Group}: {Data?.Count ?? 0} ({RecordTime})";
return $"{Metric}-{Dimension}: {Data?.Count ?? 0} ({RecordTime})";
}
}

View file

@ -2,8 +2,8 @@ namespace BotSharp.Abstraction.Statistics.Models;
public class BotSharpStatsInput
{
public string Category { get; set; }
public string Group { get; set; }
public string Metric { get; set; }
public string Dimension { get; set; }
public List<StatsKeyValuePair> Data { get; set; } = [];
public DateTime RecordTime { get; set; }
}

View file

@ -62,8 +62,8 @@ public class TokenStatistics : ITokenStatistics
var globalStats = _services.GetRequiredService<IBotSharpStatsService>();
var body = new BotSharpStatsInput
{
Category = StatsCategory.AgentLlmCost,
Group = message.CurrentAgentId,
Metric = StatsCategory.AgentLlmCost,
Dimension = message.CurrentAgentId,
RecordTime = DateTime.UtcNow,
Data = [
new StatsKeyValuePair("prompt_token_count_total", stats.PromptCount),

View file

@ -4,10 +4,10 @@ namespace BotSharp.Core.Repository;
public partial class FileRepository
{
public BotSharpStats? GetGlobalStats(string category, string group, DateTime recordTime)
public BotSharpStats? GetGlobalStats(string metric, string dimension, DateTime recordTime)
{
var baseDir = Path.Combine(_dbSettings.FileRepository, STATS_FOLDER);
var dir = Path.Combine(baseDir, category, recordTime.Year.ToString(), recordTime.Month.ToString("D2"));
var dir = Path.Combine(baseDir, metric, recordTime.Year.ToString(), recordTime.Month.ToString("D2"));
if (!Directory.Exists(dir)) return null;
var file = Directory.GetFiles(dir).FirstOrDefault(x => Path.GetFileName(x) == STATS_FILE);
@ -16,8 +16,8 @@ public partial class FileRepository
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)
var found = list?.FirstOrDefault(x => x.Metric.IsEqualTo(metric)
&& x.Dimension.IsEqualTo(dimension)
&& x.RecordTime == time);
return found;
}
@ -25,7 +25,7 @@ public partial class FileRepository
public bool SaveGlobalStats(BotSharpStats body)
{
var baseDir = Path.Combine(_dbSettings.FileRepository, STATS_FOLDER);
var dir = Path.Combine(baseDir, body.Category, body.RecordTime.Year.ToString(), body.RecordTime.Month.ToString("D2"));
var dir = Path.Combine(baseDir, body.Metric, body.RecordTime.Year.ToString(), body.RecordTime.Month.ToString("D2"));
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
@ -42,14 +42,14 @@ public partial class FileRepository
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)
var found = list?.FirstOrDefault(x => x.Metric.IsEqualTo(body.Metric)
&& x.Dimension.IsEqualTo(body.Dimension)
&& x.RecordTime == time);
if (found != null)
{
found.Category = body.Category;
found.Group = body.Group;
found.Metric = body.Metric;
found.Dimension = body.Dimension;
found.Data = body.Data;
found.RecordTime = body.RecordTime;
}

View file

@ -29,8 +29,8 @@ public class BotSharpStatsService : IBotSharpStatsService
if (!_settings.Enabled
|| string.IsNullOrEmpty(resourceKey)
|| input == null
|| string.IsNullOrEmpty(input.Category)
|| string.IsNullOrEmpty(input.Group))
|| string.IsNullOrEmpty(input.Metric)
|| string.IsNullOrEmpty(input.Dimension))
{
return false;
}
@ -39,13 +39,13 @@ public class BotSharpStatsService : IBotSharpStatsService
var res = locker.Lock(resourceKey, () =>
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var body = db.GetGlobalStats(input.Category, input.Group, input.RecordTime);
var body = db.GetGlobalStats(input.Metric, input.Dimension, input.RecordTime);
if (body == null)
{
var stats = new BotSharpStats
{
Category = input.Category,
Group = input.Group,
Metric = input.Metric,
Dimension = input.Dimension,
RecordTime = input.RecordTime,
Data = input.Data.ToDictionary(x => x.Key, x => x.Value)
};
@ -85,7 +85,7 @@ public class BotSharpStatsService : IBotSharpStatsService
}
catch (Exception ex)
{
_logger.LogError($"Error when updating global stats {input.Category}-{input.Group}. {ex.Message}\r\n{ex.InnerException}");
_logger.LogError($"Error when updating global stats {input.Metric}-{input.Dimension}. {ex.Message}\r\n{ex.InnerException}");
return false;
}
}

View file

@ -31,8 +31,8 @@ public class GlobalStatsConversationHook : ConversationHookBase
var body = new BotSharpStatsInput
{
Category = StatsCategory.AgentCall,
Group = message.CurrentAgentId,
Metric = StatsCategory.AgentCall,
Dimension = message.CurrentAgentId,
Data = [
new StatsKeyValuePair("agent_call_count", 1)
],

View file

@ -2,8 +2,8 @@ namespace BotSharp.Plugin.MongoStorage.Collections;
public class GlobalStatisticsDocument : MongoBase
{
public string Category { get; set; }
public string Group { get; set; }
public string Metric { get; set; }
public string Dimension { get; set; }
public IDictionary<string, double> Data { get; set; } = new Dictionary<string, double>();
public DateTime RecordTime { get; set; }
}

View file

@ -4,15 +4,15 @@ namespace BotSharp.Plugin.MongoStorage.Repository;
public partial class MongoRepository
{
public BotSharpStats? GetGlobalStats(string category, string group, DateTime recordTime)
public BotSharpStats? GetGlobalStats(string metric, string dimension, DateTime recordTime)
{
var time = BuildRecordTime(recordTime);
var builder = Builders<GlobalStatisticsDocument>.Filter;
var filters = new List<FilterDefinition<GlobalStatisticsDocument>>()
{
builder.Eq(x => x.Category, category),
builder.Eq(x => x.Group, group),
builder.Eq(x => x.Metric, metric),
builder.Eq(x => x.Dimension, dimension),
builder.Eq(x => x.RecordTime, time)
};
@ -22,8 +22,8 @@ public partial class MongoRepository
return new BotSharpStats
{
Category = found.Category,
Group = found.Group,
Metric = found.Metric,
Dimension = found.Dimension,
Data = found.Data,
RecordTime = found.RecordTime
};
@ -35,16 +35,16 @@ public partial class MongoRepository
var builder = Builders<GlobalStatisticsDocument>.Filter;
var filters = new List<FilterDefinition<GlobalStatisticsDocument>>()
{
builder.Eq(x => x.Category, body.Category),
builder.Eq(x => x.Group, body.Group),
builder.Eq(x => x.Metric, body.Metric),
builder.Eq(x => x.Dimension, body.Dimension),
builder.Eq(x => x.RecordTime, time)
};
var filterDef = builder.And(filters);
var updateDef = Builders<GlobalStatisticsDocument>.Update
.SetOnInsert(x => x.Id, Guid.NewGuid().ToString())
.Set(x => x.Category, body.Category)
.Set(x => x.Group, body.Group)
.Set(x => x.Metric, body.Metric)
.Set(x => x.Dimension, body.Dimension)
.Set(x => x.Data, body.Data)
.Set(x => x.RecordTime, time);