Skip to content

Commit 7241905

Browse files
committed
Improved Free and popups
1 parent a2a293a commit 7241905

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

FetchXmlBuilder/DockControls/AiChatControl.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal void Initialize()
8484
return;
8585
}
8686
var apikey = "";
87-
if (supplier.IsFree)
87+
if (supplier.Free)
8888
{
8989
logname = "AI-Free";
9090
if (IsFreeAiUser(fxb))
@@ -111,7 +111,7 @@ internal void Initialize()
111111
chatHistory = new ChatMessageHistory(panAiConversation, supplier?.Name, model?.Endpoint, model?.Name, apikey, fxb.settings.AiSettings.MyName);
112112
metaAttributes.Clear();
113113
SetTitle();
114-
if (supplier.IsFree && !IsFreeAiUser(fxb))
114+
if (supplier.Free && !IsFreeAiUser(fxb))
115115
{
116116
chatHistory.Add(ChatRole.Assistant, @"To use the free AI provider, you have to fill in a form.
117117
Please click the button (the three dots down-right) and select 'Ask for Free AI'.
@@ -165,7 +165,7 @@ internal static void PromptToUseForFree(PluginControlBase tool)
165165

166166
private void SetTitle()
167167
{
168-
Text = $"AI Chat - {supplier?.Name ?? "<no provider>"} - {model?.Name ?? "<no model>"}";
168+
Text = $"AI Chat - {supplier?.ToString() ?? "<no provider>"} - {model?.Name ?? "<no model>"}";
169169
TabText = Text;
170170
}
171171

@@ -286,7 +286,7 @@ private void SendChatToAI(object sender, EventArgs e = null)
286286
}
287287
catch (Exception ex)
288288
{
289-
fxb.LogError($"communicating with {supplier.Name}\n{ex.ExceptionDetails()}\n{ex.StackTrace}");
289+
fxb.LogError($"Communicating with {supplier}:\n{ex.ExceptionDetails()}\n{ex.StackTrace}");
290290
fxb.ShowErrorDialog(ex, "AI Chat", "An error occurred while trying to communicate with the AI.");
291291
}
292292
txtAiChat.Clear();
@@ -420,9 +420,12 @@ private void PopupMessageIfRelevant()
420420
{
421421
var supporting = Supporting.IsMonetarySupporting(fxb) || Supporting.IsPending(fxb);
422422
if (OnlineSettings.Instance.AiSupport.PopupByCallNos
423-
.FirstOrDefault(p => p.TimeToPopup(fxb.settings.AiSettings.Calls, supporting)) is PopupByCallNo popup)
423+
.FirstOrDefault(p => p.TimeToPopup(fxb.settings.AiSettings.Calls, supporting, supplier.Free)) is PopupByCallNo popup)
424424
{
425-
var message = popup.Message.Replace("{calls}", fxb.settings.AiSettings.Calls.ToString());
425+
var message = popup.Message
426+
.Replace("{calls}", fxb.settings.AiSettings.Calls.ToString())
427+
.Replace("{provider}", supplier.ToString())
428+
.Replace("{model}", model.Name);
426429
if (popup.SuggestsSupporting)
427430
{
428431
if (MessageBoxEx.Show(fxb, message, "AI Chat", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)

FetchXmlBuilder/Forms/Settings.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void btnOK_Click(object sender, EventArgs e)
195195
return;
196196
}
197197
if (cmbAiSupplier.SelectedItem is AiSupplier supplier &&
198-
supplier.IsFree &&
198+
supplier.Free &&
199199
cmbAiModel.SelectedItem is AiModel model &&
200200
string.IsNullOrEmpty(model.ApiKeyDecrypted))
201201
{
@@ -308,17 +308,17 @@ private void UpdateAiSettingsList()
308308
cmbAiModel.SelectedItem is AiModel model &&
309309
!string.IsNullOrWhiteSpace(txtAiApiKey.Text))
310310
{
311-
if (aisettingslist.FirstOrDefault(a => a.Supplier == supplier.Name && a.Model == model.Name) is AiSettings existing)
311+
if (aisettingslist.FirstOrDefault(a => a.Supplier == supplier.ToString() && a.Model == model.Name) is AiSettings existing)
312312
{
313313
existing.ApiKey = txtAiApiKey.Text;
314314
}
315315
else
316316
{
317317
aisettingslist.Add(new AiSettings
318318
{
319-
Supplier = supplier.Name,
319+
Supplier = supplier.ToString(),
320320
Model = model.Name,
321-
ApiKey = !supplier.IsFree ? txtAiApiKey.Text : ""
321+
ApiKey = !supplier.Free ? txtAiApiKey.Text : ""
322322
});
323323
}
324324
}
@@ -350,7 +350,7 @@ private void cmbAiSupplier_SelectedIndexChanged(object sender = null, EventArgs
350350
cmbAiModel.Items.Clear();
351351
if (cmbAiSupplier.SelectedItem is AiSupplier supplier)
352352
{
353-
tt.SetToolTip(picAiSupplier, $"Read about {supplier.Name} at {supplier.Url}");
353+
tt.SetToolTip(picAiSupplier, $"Read about {supplier} at {supplier.Url}");
354354
picAiSupplier.Tag = supplier.Url;
355355
cmbAiModel.Items.AddRange(supplier.Models.ToArray());
356356
if (supplier.Models.FirstOrDefault(m => m.Name == fxb.settings.AiSettings.Model) is AiModel model)
@@ -374,15 +374,15 @@ private void cmbAiModel_SelectedIndexChanged(object sender = null, EventArgs e =
374374
if (cmbAiSupplier.SelectedItem is AiSupplier supplier && cmbAiModel.SelectedItem is AiModel model)
375375
{
376376
picAiUrl.Tag = OnlineSettings.Instance.AiSupport.Supplier(cmbAiSupplier.Text)?.Models.FirstOrDefault(m => m.Name == cmbAiModel.Text)?.Url;
377-
if (supplier.IsFree)
377+
if (supplier.Free)
378378
{
379379
HandlingFreeAI();
380380
}
381381
else //if (sender != null)
382382
{
383383
LoadAiSettingsKey();
384384
}
385-
txtAiApiKey.Enabled = !supplier.IsFree;
385+
txtAiApiKey.Enabled = !supplier.Free;
386386
}
387387
else
388388
{

0 commit comments

Comments
 (0)