Skip to content

Commit b25ecf1

Browse files
authored
Merge pull request #225 from iceljc/feature/add-log-setting
add log settings
2 parents af0a819 + bdb8372 commit b25ecf1

File tree

31 files changed

+288
-135
lines changed

31 files changed

+288
-135
lines changed

BotSharp.sln

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.WebDriver",
7373
EndProject
7474
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.ChatHub", "src\Plugins\BotSharp.Plugin.ChatHub\BotSharp.Plugin.ChatHub.csproj", "{EDCD9C20-2D9D-4098-A16E-03F97B306CB8}"
7575
EndProject
76-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.TelegramBots", "src\Plugins\BotSharp.Plugin.TelegramBots\BotSharp.Plugin.TelegramBots.csproj", "{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}"
76+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BotSharp.Plugin.TelegramBots", "src\Plugins\BotSharp.Plugin.TelegramBots\BotSharp.Plugin.TelegramBots.csproj", "{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}"
77+
EndProject
78+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Logger", "src\Infrastructure\BotSharp.Logger\BotSharp.Logger.csproj", "{5CA3335E-E6AD-46FD-B277-29BBC3A16500}"
7779
EndProject
7880
Global
7981
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -283,6 +285,14 @@ Global
283285
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|Any CPU.Build.0 = Release|Any CPU
284286
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|x64.ActiveCfg = Release|Any CPU
285287
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E}.Release|x64.Build.0 = Release|Any CPU
288+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
289+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Debug|Any CPU.Build.0 = Debug|Any CPU
290+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Debug|x64.ActiveCfg = Debug|Any CPU
291+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Debug|x64.Build.0 = Debug|Any CPU
292+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Release|Any CPU.ActiveCfg = Release|Any CPU
293+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Release|Any CPU.Build.0 = Release|Any CPU
294+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Release|x64.ActiveCfg = Release|Any CPU
295+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500}.Release|x64.Build.0 = Release|Any CPU
286296
EndGlobalSection
287297
GlobalSection(SolutionProperties) = preSolution
288298
HideSolutionNode = FALSE
@@ -320,6 +330,7 @@ Global
320330
{F06B22CB-B143-4680-8FFF-35B9E50E6C47} = {51AFE054-AE99-497D-A593-69BAEFB5106F}
321331
{EDCD9C20-2D9D-4098-A16E-03F97B306CB8} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
322332
{DCA18996-4D3A-4E98-BCD0-1FB77C59253E} = {64264688-0F5C-4AB0-8F2B-B59B717CCE00}
333+
{5CA3335E-E6AD-46FD-B277-29BBC3A16500} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
323334
EndGlobalSection
324335
GlobalSection(ExtensibilityGlobals) = postSolution
325336
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

src/Infrastructure/BotSharp.Abstraction/Conversations/Settings/ConversationSetting.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ public class ConversationSetting
77
public bool EnableKnowledgeBase { get; set; }
88
public bool ShowVerboseLog { get; set; }
99
public int MaxRecursiveDepth { get; set; } = 3;
10+
public bool EnableLlmCompletionLog { get; set; }
11+
public bool EnableExecutionLog { get; set; }
1012
}

src/Infrastructure/BotSharp.Abstraction/MLTasks/IContentGeneratingHook.cs renamed to src/Infrastructure/BotSharp.Abstraction/Loggers/IContentGeneratingHook.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace BotSharp.Abstraction.MLTasks;
1+
namespace BotSharp.Abstraction.Loggers;
22

33
/// <summary>
44
/// Model content generating hook, it can be used for logging, metrics and tracing.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace BotSharp.Abstraction.Loggers;
2+
3+
public interface IVerboseLogHook
4+
{
5+
void GenerateLog(string text);
6+
}

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ public interface IBotSharpRepository
3838
List<Conversation> GetConversations(ConversationFilter filter);
3939
void UpdateConversationTitle(string conversationId, string title);
4040
List<Conversation> GetLastConversations();
41-
void AddExectionLogs(string conversationId, List<string> logs);
42-
List<string> GetExectionLogs(string conversationId);
41+
#endregion
42+
43+
#region Execution Log
44+
void AddExecutionLogs(string conversationId, List<string> logs);
45+
List<string> GetExecutionLogs(string conversationId);
4346
#endregion
4447

4548
#region LLM Completion Log

src/Infrastructure/BotSharp.Core/BotSharpServiceCollectionExtensions.cs renamed to src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222

2323
namespace BotSharp.Core;
2424

25-
public static class BotSharpServiceCollectionExtensions
25+
public static class BotSharpCoreExtensions
2626
{
27-
public static IServiceCollection AddBotSharp(this IServiceCollection services, IConfiguration config)
27+
public static IServiceCollection AddBotSharpCore(this IServiceCollection services, IConfiguration config)
2828
{
2929
services.AddScoped<IUserService, UserService>();
3030

src/Infrastructure/BotSharp.Core/Evaluations/ExecutionLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public void Append(string conversationId, string content)
2121
content = content.Replace("\r\n", " ").Replace("\n", " ");
2222
content = Regex.Replace(content, @"\s+", " ");
2323
var db = _services.GetRequiredService<IBotSharpRepository>();
24-
db.AddExectionLogs(conversationId, new List<string> { content });
24+
db.AddExecutionLogs(conversationId, new List<string> { content });
2525
}
2626
}

src/Infrastructure/BotSharp.Core/Repository/BotSharpDbContext.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,31 +168,34 @@ public void UpdateConversationStatus(string conversationId, string status)
168168
{
169169
throw new NotImplementedException();
170170
}
171+
#endregion
172+
171173

172-
public void AddExectionLogs(string conversationId, List<string> logs)
174+
#region User
175+
public User? GetUserByEmail(string email)
173176
{
174177
throw new NotImplementedException();
175178
}
176179

177-
public List<string> GetExectionLogs(string conversationId)
180+
public User? GetUserById(string id)
178181
{
179182
throw new NotImplementedException();
180183
}
181-
#endregion
182-
183184

184-
#region User
185-
public User? GetUserByEmail(string email)
185+
public void CreateUser(User user)
186186
{
187187
throw new NotImplementedException();
188188
}
189+
#endregion
189190

190-
public User? GetUserById(string id)
191+
192+
#region Execution Log
193+
public void AddExecutionLogs(string conversationId, List<string> logs)
191194
{
192195
throw new NotImplementedException();
193196
}
194197

195-
public void CreateUser(User user)
198+
public List<string> GetExecutionLogs(string conversationId)
196199
{
197200
throw new NotImplementedException();
198201
}

src/Infrastructure/BotSharp.Core/Repository/FileRepository.cs

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
using MongoDB.Driver;
77
using BotSharp.Abstraction.Routing.Models;
88
using BotSharp.Abstraction.Repositories.Filters;
9-
using BotSharp.Abstraction.Utilities;
10-
using BotSharp.Abstraction.Conversations.Models;
119

1210
namespace BotSharp.Core.Repository;
1311

@@ -789,33 +787,6 @@ public List<Conversation> GetLastConversations()
789787
.Select(g => g.OrderByDescending(x => x.CreatedTime).First())
790788
.ToList();
791789
}
792-
793-
public void AddExectionLogs(string conversationId, List<string> logs)
794-
{
795-
if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return;
796-
797-
var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId);
798-
if (!Directory.Exists(dir))
799-
{
800-
Directory.CreateDirectory(dir);
801-
}
802-
803-
var file = Path.Combine(dir, "execution.log");
804-
File.AppendAllLines(file, logs);
805-
}
806-
807-
public List<string> GetExectionLogs(string conversationId)
808-
{
809-
var logs = new List<string>();
810-
if (string.IsNullOrEmpty(conversationId)) return logs;
811-
812-
var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId);
813-
if (!Directory.Exists(dir)) return logs;
814-
815-
var file = Path.Combine(dir, "execution.log");
816-
logs = File.ReadAllLines(file)?.ToList() ?? new List<string>();
817-
return logs;
818-
}
819790
#endregion
820791

821792
#region User
@@ -843,6 +814,35 @@ public void CreateUser(User user)
843814
}
844815
#endregion
845816

817+
#region Execution Log
818+
public void AddExecutionLogs(string conversationId, List<string> logs)
819+
{
820+
if (string.IsNullOrEmpty(conversationId) || logs.IsNullOrEmpty()) return;
821+
822+
var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId);
823+
if (!Directory.Exists(dir))
824+
{
825+
Directory.CreateDirectory(dir);
826+
}
827+
828+
var file = Path.Combine(dir, "execution.log");
829+
File.AppendAllLines(file, logs);
830+
}
831+
832+
public List<string> GetExecutionLogs(string conversationId)
833+
{
834+
var logs = new List<string>();
835+
if (string.IsNullOrEmpty(conversationId)) return logs;
836+
837+
var dir = Path.Combine(_dbSettings.FileRepository, "conversations", conversationId);
838+
if (!Directory.Exists(dir)) return logs;
839+
840+
var file = Path.Combine(dir, "execution.log");
841+
logs = File.ReadAllLines(file)?.ToList() ?? new List<string>();
842+
return logs;
843+
}
844+
#endregion
845+
846846
#region LLM Completion Log
847847
public void SaveLlmCompletionLog(LlmCompletionLog log)
848848
{
@@ -855,6 +855,7 @@ public void SaveLlmCompletionLog(LlmCompletionLog log)
855855
Directory.CreateDirectory(logDir);
856856
}
857857

858+
log.Id = Guid.NewGuid().ToString();
858859
var index = GetLlmCompletionLogIndex(logDir, log.MessageId);
859860
var file = Path.Combine(logDir, $"{log.MessageId}.{index}.log");
860861
File.WriteAllText(file, JsonSerializer.Serialize(log, _options));
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
<LangVersion>$(LangVersion)</LangVersion>
6+
<VersionPrefix>$(BotSharpVersion)</VersionPrefix>
7+
<GeneratePackageOnBuild>$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
8+
</PropertyGroup>
9+
10+
<PropertyGroup>
11+
<Authors>Haiping Chen</Authors>
12+
<Company>SciSharp STACK</Company>
13+
<Product>LL Application Framework</Product>
14+
<Description>
15+
Open source LLM application framework to build scalable, flexible and robust AI system.
16+
</Description>
17+
<RepositoryType>git</RepositoryType>
18+
<RepositoryUrl>https://github.com/SciSharp/BotSharp</RepositoryUrl>
19+
<PackageTags>Chatbot, Bot, LLM, AI, ChatGPT, OpenAI</PackageTags>
20+
<PackageReleaseNotes>Support dialogue status tracking.</PackageReleaseNotes>
21+
<Copyright>Since 2018 Haiping Chen</Copyright>
22+
<PackageProjectUrl>https://github.com/SciSharp/BotSharp</PackageProjectUrl>
23+
<PackageIconUrl>https://raw.githubusercontent.com/SciSharp/BotSharp/master/docs/static/logos/BotSharp.png</PackageIconUrl>
24+
<PackageLicenseUrl>https://raw.githubusercontent.com/SciSharp/BotSharp/master/LICENSE</PackageLicenseUrl>
25+
<PackageIcon>Icon.png</PackageIcon>
26+
<Nullable>enable</Nullable>
27+
</PropertyGroup>
28+
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
30+
<DefineConstants>TRACE;DEBUG</DefineConstants>
31+
<NoWarn>1701;1702</NoWarn>
32+
</PropertyGroup>
33+
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
35+
<DefineConstants>TRACE;</DefineConstants>
36+
<NoWarn>1701;1702</NoWarn>
37+
</PropertyGroup>
38+
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
40+
<NoWarn>1701;1702</NoWarn>
41+
</PropertyGroup>
42+
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
44+
<NoWarn>1701;1702</NoWarn>
45+
</PropertyGroup>
46+
47+
<ItemGroup>
48+
<None Include="..\..\..\arts\Icon.png">
49+
<Pack>True</Pack>
50+
<PackagePath>\</PackagePath>
51+
</None>
52+
</ItemGroup>
53+
54+
<ItemGroup>
55+
<ProjectReference Include="..\BotSharp.Abstraction\BotSharp.Abstraction.csproj" />
56+
</ItemGroup>
57+
58+
</Project>

0 commit comments

Comments
 (0)