-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into v0.20-json-schema
- Loading branch information
Showing
8 changed files
with
55 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logging | ||
|
||
## Setting | ||
To initialize the logging feature, set up the following flags in `Conversation`. Each flag can display or record specific content during conversation. | ||
|
||
* `ShowVerboseLog`: print conversation details or prompt in console. | ||
* `EnableLlmCompletionLog`: log LLM completion results, e.g., real-time prompt sent to LLM and response generated from LLm. | ||
* `EnableExecutionLog`: log details after events, e.g., receiving message, executing function, generating response, etc. | ||
|
||
|
||
```json | ||
"Conversation": { | ||
"ShowVerboseLog": false, | ||
"EnableLlmCompletionLog": false, | ||
"EnableExecutionLog": true | ||
} | ||
``` | ||
|
||
### Usage | ||
To enable the logging functionality, add the following line of code in `Program.cs`. | ||
|
||
```csharp | ||
builder.Services.AddBotSharpLogger(builder.Configuration); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
src/Infrastructure/BotSharp.Abstraction/Loggers/IVerboseLogHook.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 29 additions & 4 deletions
33
src/Infrastructure/BotSharp.Logger/Hooks/VerboseLogHook.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
using BotSharp.Abstraction.Agents; | ||
using BotSharp.Abstraction.Agents.Enums; | ||
|
||
namespace BotSharp.Logger.Hooks; | ||
|
||
public class VerboseLogHook : IVerboseLogHook | ||
public class VerboseLogHook : IContentGeneratingHook | ||
{ | ||
private readonly ConversationSetting _convSettings; | ||
private readonly ILogger<VerboseLogHook> _logger; | ||
private readonly IServiceProvider _services; | ||
|
||
public VerboseLogHook(ConversationSetting convSettings, ILogger<VerboseLogHook> logger) | ||
public VerboseLogHook( | ||
ConversationSetting convSettings, | ||
IServiceProvider serivces, | ||
ILogger<VerboseLogHook> logger) | ||
{ | ||
_convSettings = convSettings; | ||
_services = serivces; | ||
_logger = logger; | ||
} | ||
|
||
public void GenerateLog(string text) | ||
public async Task BeforeGenerating(Agent agent, List<RoleDialogModel> conversations) | ||
{ | ||
if (!_convSettings.ShowVerboseLog) return; | ||
|
||
var dialog = conversations.Last(); | ||
var log = $"{dialog.Role}: {dialog.Content}"; | ||
_logger.LogInformation(log); | ||
} | ||
|
||
public async Task AfterGenerated(RoleDialogModel message, TokenStatsModel tokenStats) | ||
{ | ||
if (!_convSettings.ShowVerboseLog) return; | ||
|
||
_logger.LogInformation(text); | ||
var agentService = _services.GetRequiredService<IAgentService>(); | ||
var agent = await agentService.LoadAgent(message.CurrentAgentId); | ||
|
||
var log = message.Role == AgentRole.Function ? | ||
$"[{agent.Name}]: {message.FunctionName}({message.FunctionArgs})" : | ||
$"[{agent.Name}]: {message.Content}"; | ||
|
||
_logger.LogInformation(tokenStats.Prompt); | ||
_logger.LogInformation(log); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters