Skip to content

Commit 9587a07

Browse files
Showing sources coming from data providers (#559)
1 parent c3bbcac commit 9587a07

File tree

30 files changed

+223
-90
lines changed

30 files changed

+223
-90
lines changed

app/MindWork AI Studio/Agents/AgentDataSourceSelection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public override async Task<ContentBlock> ProcessInput(ContentBlock input, IDicti
131131

132132
#endregion
133133

134-
public async Task<List<SelectedDataSource>> PerformSelectionAsync(IProvider provider, IContent lastPrompt, ChatThread chatThread, AllowedSelectedDataSources dataSources, CancellationToken token = default)
134+
public async Task<List<SelectedDataSource>> PerformSelectionAsync(IProvider provider, IContent lastUserPrompt, ChatThread chatThread, AllowedSelectedDataSources dataSources, CancellationToken token = default)
135135
{
136136
logger.LogInformation("The AI should select the appropriate data sources.");
137137

@@ -154,7 +154,7 @@ public async Task<List<SelectedDataSource>> PerformSelectionAsync(IProvider prov
154154
//
155155
// 2. Prepare the current system and user prompts as input for the agent:
156156
//
157-
var lastPromptContent = lastPrompt switch
157+
var lastPromptContent = lastUserPrompt switch
158158
{
159159
ContentText text => text.Text,
160160

app/MindWork AI Studio/Agents/AgentRetrievalContextValidation.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ public void SetLLMProvider(IProvider provider)
147147
/// <summary>
148148
/// Validate all retrieval contexts against the last user and the system prompt.
149149
/// </summary>
150-
/// <param name="lastPrompt">The last user prompt.</param>
150+
/// <param name="lastUserPrompt">The last user prompt.</param>
151151
/// <param name="chatThread">The chat thread.</param>
152152
/// <param name="retrievalContexts">All retrieval contexts to validate.</param>
153153
/// <param name="token">The cancellation token.</param>
154154
/// <returns>The validation results.</returns>
155-
public async Task<IReadOnlyList<RetrievalContextValidationResult>> ValidateRetrievalContextsAsync(IContent lastPrompt, ChatThread chatThread, IReadOnlyList<IRetrievalContext> retrievalContexts, CancellationToken token = default)
155+
public async Task<IReadOnlyList<RetrievalContextValidationResult>> ValidateRetrievalContextsAsync(IContent lastUserPrompt, ChatThread chatThread, IReadOnlyList<IRetrievalContext> retrievalContexts, CancellationToken token = default)
156156
{
157157
// Check if the retrieval context validation is enabled:
158158
if (!this.SettingsManager.ConfigurationData.AgentRetrievalContextValidation.EnableRetrievalContextValidation)
@@ -178,7 +178,7 @@ public async Task<IReadOnlyList<RetrievalContextValidationResult>> ValidateRetri
178178
await semaphore.WaitAsync(token);
179179

180180
// Start the next validation task:
181-
validationTasks.Add(this.ValidateRetrievalContextAsync(lastPrompt, chatThread, retrievalContext, token, semaphore));
181+
validationTasks.Add(this.ValidateRetrievalContextAsync(lastUserPrompt, chatThread, retrievalContext, token, semaphore));
182182
}
183183

184184
// Wait for all validation tasks to complete:
@@ -193,13 +193,13 @@ public async Task<IReadOnlyList<RetrievalContextValidationResult>> ValidateRetri
193193
/// can call this method in parallel for each retrieval context. You might use
194194
/// the ValidateRetrievalContextsAsync method to validate all retrieval contexts.
195195
/// </remarks>
196-
/// <param name="lastPrompt">The last user prompt.</param>
196+
/// <param name="lastUserPrompt">The last user prompt.</param>
197197
/// <param name="chatThread">The chat thread.</param>
198198
/// <param name="retrievalContext">The retrieval context to validate.</param>
199199
/// <param name="token">The cancellation token.</param>
200200
/// <param name="semaphore">The optional semaphore to limit the number of parallel validations.</param>
201201
/// <returns>The validation result.</returns>
202-
public async Task<RetrievalContextValidationResult> ValidateRetrievalContextAsync(IContent lastPrompt, ChatThread chatThread, IRetrievalContext retrievalContext, CancellationToken token = default, SemaphoreSlim? semaphore = null)
202+
public async Task<RetrievalContextValidationResult> ValidateRetrievalContextAsync(IContent lastUserPrompt, ChatThread chatThread, IRetrievalContext retrievalContext, CancellationToken token = default, SemaphoreSlim? semaphore = null)
203203
{
204204
try
205205
{
@@ -214,7 +214,7 @@ public async Task<RetrievalContextValidationResult> ValidateRetrievalContextAsyn
214214
//
215215
// 1. Prepare the current system and user prompts as input for the agent:
216216
//
217-
var lastPromptContent = lastPrompt switch
217+
var lastPromptContent = lastUserPrompt switch
218218
{
219219
ContentText text => text.Text,
220220

app/MindWork AI Studio/Assistants/I18N/allTexts.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,9 +4882,6 @@ UI_TEXT_CONTENT["AISTUDIO::PROVIDER::LLMPROVIDERSEXTENSIONS::T3424652889"] = "Un
48824882
-- no model selected
48834883
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::MODEL::T2234274832"] = "no model selected"
48844884

4885-
-- Sources
4886-
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::SOURCEEXTENSIONS::T2730980305"] = "Sources"
4887-
48884885
-- Use no chat template
48894886
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CHATTEMPLATE::T4258819635"] = "Use no chat template"
48904887

@@ -5641,6 +5638,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T1015418291"] = "No u
56415638
-- Failed to install update automatically. Please try again manually.
56425639
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T3709709946"] = "Failed to install update automatically. Please try again manually."
56435640

5641+
-- Sources provided by the data providers
5642+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4174900468"] = "Sources provided by the data providers"
5643+
5644+
-- Sources provided by the AI
5645+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4261248356"] = "Sources provided by the AI"
5646+
56445647
-- The hostname is not a valid HTTP(S) URL.
56455648
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL."
56465649

app/MindWork AI Studio/Chat/ContentBlockComponent.razor

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@using AIStudio.Tools
22
@using MudBlazor
33
@using AIStudio.Components
4-
@using AIStudio.Provider
54
@inherits AIStudio.Components.MSGComponentBase
65
<MudCard Class="@this.CardClasses" Outlined="@true">
76
<MudCardHeader>

app/MindWork AI Studio/Chat/ContentImage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public sealed class ContentImage : IContent, IImageSource
3131
public List<Source> Sources { get; set; } = [];
3232

3333
/// <inheritdoc />
34-
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default)
34+
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastUserPrompt, ChatThread? chatChatThread, CancellationToken token = default)
3535
{
3636
throw new NotImplementedException();
3737
}

app/MindWork AI Studio/Chat/ContentText.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace AIStudio.Chat;
1111
/// </summary>
1212
public sealed class ContentText : IContent
1313
{
14+
private static readonly ILogger<ContentText> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ContentText>();
15+
1416
/// <summary>
1517
/// The minimum time between two streaming events, when the user
1618
/// enables the energy saving mode.
@@ -39,30 +41,28 @@ public sealed class ContentText : IContent
3941
public List<Source> Sources { get; set; } = [];
4042

4143
/// <inheritdoc />
42-
public async Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatThread, CancellationToken token = default)
44+
public async Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastUserPrompt, ChatThread? chatThread, CancellationToken token = default)
4345
{
4446
if(chatThread is null)
4547
return new();
4648

4749
if(!chatThread.IsLLMProviderAllowed(provider))
4850
{
49-
var logger = Program.SERVICE_PROVIDER.GetService<ILogger<ContentText>>()!;
50-
logger.LogError("The provider is not allowed for this chat thread due to data security reasons. Skipping the AI process.");
51+
LOGGER.LogError("The provider is not allowed for this chat thread due to data security reasons. Skipping the AI process.");
5152
return chatThread;
5253
}
5354

5455
// Call the RAG process. Right now, we only have one RAG process:
55-
if (lastPrompt is not null)
56+
if (lastUserPrompt is not null)
5657
{
5758
try
5859
{
5960
var rag = new AISrcSelWithRetCtxVal();
60-
chatThread = await rag.ProcessAsync(provider, lastPrompt, chatThread, token);
61+
chatThread = await rag.ProcessAsync(provider, lastUserPrompt, chatThread, token);
6162
}
6263
catch (Exception e)
6364
{
64-
var logger = Program.SERVICE_PROVIDER.GetService<ILogger<ContentText>>()!;
65-
logger.LogError(e, "Skipping the RAG process due to an error.");
65+
LOGGER.LogError(e, "Skipping the RAG process due to an error.");
6666
}
6767
}
6868

app/MindWork AI Studio/Chat/IContent.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ public interface IContent
4141
/// <summary>
4242
/// The provided sources, if any.
4343
/// </summary>
44+
/// <remarks>
45+
/// We cannot use ISource here because System.Text.Json does not support
46+
/// interface serialization. So we have to use a concrete class.
47+
/// </remarks>
4448
[JsonIgnore]
4549
public List<Source> Sources { get; set; }
4650

4751
/// <summary>
4852
/// Uses the provider to create the content.
4953
/// </summary>
50-
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastPrompt, ChatThread? chatChatThread, CancellationToken token = default);
54+
public Task<ChatThread> CreateFromProviderAsync(IProvider provider, Model chatModel, IContent? lastUserPrompt, ChatThread? chatChatThread, CancellationToken token = default);
5155

5256
/// <summary>
5357
/// Creates a deep copy

app/MindWork AI Studio/Plugins/languages/de-de-43065dbc-78d0-45b7-92be-f14c2926e2dc/plugin.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,9 +4884,6 @@ UI_TEXT_CONTENT["AISTUDIO::PROVIDER::LLMPROVIDERSEXTENSIONS::T3424652889"] = "Un
48844884
-- no model selected
48854885
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::MODEL::T2234274832"] = "Kein Modell ausgewählt"
48864886

4887-
-- Sources
4888-
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::SOURCEEXTENSIONS::T2730980305"] = "Quellen"
4889-
48904887
-- Use no chat template
48914888
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CHATTEMPLATE::T4258819635"] = "Keine Chat-Vorlage verwenden"
48924889

@@ -5643,6 +5640,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T1015418291"] = "Kein
56435640
-- Failed to install update automatically. Please try again manually.
56445641
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T3709709946"] = "Fehler bei der automatischen Installation des Updates. Bitte versuchen Sie es manuell erneut."
56455642

5643+
-- Sources provided by the data providers
5644+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4174900468"] = "Von den Datenanbietern bereitgestellte Quellen"
5645+
5646+
-- Sources provided by the AI
5647+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4261248356"] = "Von der KI bereitgestellte Quellen"
5648+
56465649
-- The hostname is not a valid HTTP(S) URL.
56475650
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "Der Hostname ist keine gültige HTTP(S)-URL."
56485651

app/MindWork AI Studio/Plugins/languages/en-us-97dfb1ba-50c4-4440-8dfa-6575daf543c8/plugin.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,9 +4884,6 @@ UI_TEXT_CONTENT["AISTUDIO::PROVIDER::LLMPROVIDERSEXTENSIONS::T3424652889"] = "Un
48844884
-- no model selected
48854885
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::MODEL::T2234274832"] = "no model selected"
48864886

4887-
-- Sources
4888-
UI_TEXT_CONTENT["AISTUDIO::PROVIDER::SOURCEEXTENSIONS::T2730980305"] = "Sources"
4889-
48904887
-- Use no chat template
48914888
UI_TEXT_CONTENT["AISTUDIO::SETTINGS::CHATTEMPLATE::T4258819635"] = "Use no chat template"
48924889

@@ -5643,6 +5640,12 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T1015418291"] = "No u
56435640
-- Failed to install update automatically. Please try again manually.
56445641
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SERVICES::UPDATESERVICE::T3709709946"] = "Failed to install update automatically. Please try again manually."
56455642

5643+
-- Sources provided by the data providers
5644+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4174900468"] = "Sources provided by the data providers"
5645+
5646+
-- Sources provided by the AI
5647+
UI_TEXT_CONTENT["AISTUDIO::TOOLS::SOURCEEXTENSIONS::T4261248356"] = "Sources provided by the AI"
5648+
56465649
-- The hostname is not a valid HTTP(S) URL.
56475650
UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::DATASOURCEVALIDATION::T1013354736"] = "The hostname is not a valid HTTP(S) URL."
56485651

app/MindWork AI Studio/Provider/OpenAI/ChatCompletionAnnotationStreamLine.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public IList<ISource> GetSources()
3030
{
3131
// Check if the annotation is of the expected type and extract the source information:
3232
if (annotation is ChatCompletionAnnotatingURL urlAnnotation)
33-
sources.Add(new Source(urlAnnotation.UrlCitation.Title, urlAnnotation.UrlCitation.URL));
33+
sources.Add(new Source(urlAnnotation.UrlCitation.Title, urlAnnotation.UrlCitation.URL, SourceOrigin.LLM));
3434

3535
//
3636
// Check for the unexpected annotation type of the Responses API.
@@ -46,7 +46,7 @@ public IList<ISource> GetSources()
4646
// we are calling the chat completion endpoint.
4747
//
4848
if (annotation is ResponsesAnnotatingUrlCitationData citationData)
49-
sources.Add(new Source(citationData.Title, citationData.URL));
49+
sources.Add(new Source(citationData.Title, citationData.URL, SourceOrigin.LLM));
5050
}
5151
}
5252

0 commit comments

Comments
 (0)