Skip to content

Commit 6a37ce6

Browse files
Improved provider logging (#551)
1 parent 70e64f2 commit 6a37ce6

25 files changed

+100
-82
lines changed

app/MindWork AI Studio/Agents/AgentBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ protected async Task AddAIResponseAsync(ChatThread thread, IContent lastUserProm
125125
// Use the selected provider to get the AI response.
126126
// By awaiting this line, we wait for the entire
127127
// content to be streamed.
128-
await aiText.CreateFromProviderAsync(this.ProviderSettings.CreateProvider(this.Logger), this.ProviderSettings.Model, lastUserPrompt, thread);
128+
await aiText.CreateFromProviderAsync(this.ProviderSettings.CreateProvider(), this.ProviderSettings.Model, lastUserPrompt, thread);
129129
}
130130
}

app/MindWork AI Studio/Assistants/AssistantBase.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ protected async Task<string> AddAIResponseAsync(DateTimeOffset time, bool hideCo
270270
// Use the selected provider to get the AI response.
271271
// By awaiting this line, we wait for the entire
272272
// content to be streamed.
273-
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.providerSettings.Model, this.lastUserPrompt, this.chatThread, this.cancellationTokenSource!.Token);
273+
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(), this.providerSettings.Model, this.lastUserPrompt, this.chatThread, this.cancellationTokenSource!.Token);
274274

275275
this.isProcessing = false;
276276
this.StateHasChanged();

app/MindWork AI Studio/Chat/ChatThread.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace AIStudio.Chat;
1010
/// </summary>
1111
public sealed record ChatThread
1212
{
13+
private static readonly ILogger<ChatThread> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ChatThread>();
14+
1315
/// <summary>
1416
/// The unique identifier of the chat thread.
1517
/// </summary>
@@ -82,9 +84,8 @@ public sealed record ChatThread
8284
/// </remarks>
8385
/// <param name="settingsManager">The settings manager instance to use.</param>
8486
/// <param name="chatThread">The chat thread to prepare the system prompt for.</param>
85-
/// <param name="logger">The logger instance to use.</param>
8687
/// <returns>The prepared system prompt.</returns>
87-
public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread chatThread, ILogger logger)
88+
public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread chatThread)
8889
{
8990
//
9091
// Use the information from the chat template, if provided. Otherwise, use the default system prompt
@@ -121,7 +122,7 @@ public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread ch
121122
// default system prompt:
122123
chatThread = chatThread with { SystemPrompt = systemPromptTextWithChatTemplate };
123124

124-
logger.LogInformation(logMessage);
125+
LOGGER.LogInformation(logMessage);
125126

126127
//
127128
// Add augmented data, if available:
@@ -139,9 +140,9 @@ public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread ch
139140
};
140141

141142
if(isAugmentedDataAvailable)
142-
logger.LogInformation("Augmented data is available for the chat thread.");
143+
LOGGER.LogInformation("Augmented data is available for the chat thread.");
143144
else
144-
logger.LogInformation("No augmented data is available for the chat thread.");
145+
LOGGER.LogInformation("No augmented data is available for the chat thread.");
145146

146147

147148
//
@@ -177,7 +178,7 @@ public string PrepareSystemPrompt(SettingsManager settingsManager, ChatThread ch
177178
}
178179
}
179180

180-
logger.LogInformation(logMessage);
181+
LOGGER.LogInformation(logMessage);
181182
return systemPromptText;
182183
}
183184

app/MindWork AI Studio/Components/ChatComponent.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ private async Task SendMessage(bool reuseLastUserPrompt = false)
528528
// Use the selected provider to get the AI response.
529529
// By awaiting this line, we wait for the entire
530530
// content to be streamed.
531-
this.ChatThread = await aiText.CreateFromProviderAsync(this.Provider.CreateProvider(this.Logger), this.Provider.Model, lastUserPrompt, this.ChatThread, this.cancellationTokenSource.Token);
531+
this.ChatThread = await aiText.CreateFromProviderAsync(this.Provider.CreateProvider(), this.Provider.Model, lastUserPrompt, this.ChatThread, this.cancellationTokenSource.Token);
532532
}
533533

534534
this.cancellationTokenSource = null;

app/MindWork AI Studio/Dialogs/EmbeddingProviderDialog.razor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ public partial class EmbeddingProviderDialog : MSGComponentBase, ISecretId
6969
[Parameter]
7070
public bool IsEditing { get; init; }
7171

72-
[Inject]
73-
private ILogger<ProviderDialog> Logger { get; init; } = null!;
74-
7572
[Inject]
7673
private RustService RustService { get; init; } = null!;
7774

@@ -244,7 +241,7 @@ private async Task Store()
244241
private async Task ReloadModels()
245242
{
246243
var currentEmbeddingProviderSettings = this.CreateEmbeddingProviderSettings();
247-
var provider = currentEmbeddingProviderSettings.CreateProvider(this.Logger);
244+
var provider = currentEmbeddingProviderSettings.CreateProvider();
248245
if(provider is NoProvider)
249246
return;
250247

app/MindWork AI Studio/Dialogs/PandocDialog.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public partial class PandocDialog : MSGComponentBase
3333
[CascadingParameter]
3434
private IMudDialogInstance MudDialog { get; set; } = null!;
3535

36-
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger("PandocDialog");
36+
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger(nameof(PandocDialog));
3737
private static readonly string LICENCE_URI = "https://raw.githubusercontent.com/jgm/pandoc/refs/heads/main/COPYING.md";
3838
private static string LATEST_PANDOC_VERSION = string.Empty;
3939

app/MindWork AI Studio/Dialogs/ProviderDialog.razor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ public partial class ProviderDialog : MSGComponentBase, ISecretId
7878
[Parameter]
7979
public bool IsEditing { get; init; }
8080

81-
[Inject]
82-
private ILogger<ProviderDialog> Logger { get; init; } = null!;
83-
8481
[Inject]
8582
private RustService RustService { get; init; } = null!;
8683

@@ -253,7 +250,7 @@ private async Task Store()
253250
private async Task ReloadModels()
254251
{
255252
var currentProviderSettings = this.CreateProviderSettings();
256-
var provider = currentProviderSettings.CreateProvider(this.Logger);
253+
var provider = currentProviderSettings.CreateProvider();
257254
if(provider is NoProvider)
258255
return;
259256

app/MindWork AI Studio/Pages/Writer.razor.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using AIStudio.Components;
33
using AIStudio.Provider;
44

5-
using Microsoft.AspNetCore.Components;
65
using Microsoft.AspNetCore.Components.Web;
76

87
using Timer = System.Timers.Timer;
@@ -11,9 +10,6 @@ namespace AIStudio.Pages;
1110

1211
public partial class Writer : MSGComponentBase
1312
{
14-
[Inject]
15-
private ILogger<Chat> Logger { get; init; } = null!;
16-
1713
private static readonly Dictionary<string, object?> USER_INPUT_ATTRIBUTES = new();
1814
private readonly Timer typeTimer = new(TimeSpan.FromMilliseconds(1_500));
1915

@@ -121,7 +117,7 @@ You are an assistant who helps with writing documents. You receive a sample
121117
this.isStreaming = true;
122118
this.StateHasChanged();
123119

124-
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(this.Logger), this.providerSettings.Model, lastUserPrompt, this.chatThread);
120+
this.chatThread = await aiText.CreateFromProviderAsync(this.providerSettings.CreateProvider(), this.providerSettings.Model, lastUserPrompt, this.chatThread);
125121
this.suggestion = aiText.Text;
126122

127123
this.isStreaming = false;

app/MindWork AI Studio/Provider/AlibabaCloud/ProviderAlibabaCloud.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
namespace AIStudio.Provider.AlibabaCloud;
1111

12-
public sealed class ProviderAlibabaCloud(ILogger logger) : BaseProvider("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/", logger)
12+
public sealed class ProviderAlibabaCloud() : BaseProvider("https://dashscope-intl.aliyuncs.com/compatible-mode/v1/", LOGGER)
1313
{
14+
private static readonly ILogger<ProviderAlibabaCloud> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAlibabaCloud>();
1415

1516
#region Implementation of IProvider
1617

@@ -32,7 +33,7 @@ public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(
3233
var systemPrompt = new Message
3334
{
3435
Role = "system",
35-
Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread, this.logger),
36+
Content = chatThread.PrepareSystemPrompt(settingsManager, chatThread),
3637
};
3738

3839
// Prepare the AlibabaCloud HTTP chat request:

app/MindWork AI Studio/Provider/Anthropic/ProviderAnthropic.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
namespace AIStudio.Provider.Anthropic;
1111

12-
public sealed class ProviderAnthropic(ILogger logger) : BaseProvider("https://api.anthropic.com/v1/", logger)
12+
public sealed class ProviderAnthropic() : BaseProvider("https://api.anthropic.com/v1/", LOGGER)
1313
{
14+
private static readonly ILogger<ProviderAnthropic> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ProviderAnthropic>();
15+
1416
#region Implementation of IProvider
1517

1618
public override string Id => LLMProviders.ANTHROPIC.ToName();
@@ -49,7 +51,7 @@ public override async IAsyncEnumerable<ContentStreamChunk> StreamChatCompletion(
4951
}
5052
}).ToList()],
5153

52-
System = chatThread.PrepareSystemPrompt(settingsManager, chatThread, this.logger),
54+
System = chatThread.PrepareSystemPrompt(settingsManager, chatThread),
5355
MaxTokens = 4_096,
5456

5557
// Right now, we only support streaming completions:

0 commit comments

Comments
 (0)