Skip to content

Commit 1e2b031

Browse files
Fix #85 (#228)
## Purpose <!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? --> * ... ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [ ] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. -->
1 parent afeccfd commit 1e2b031

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

app/backend/Extensions/SearchClientExtensions.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace MinimalApi.Extensions;
44

55
internal static class SearchClientExtensions
66
{
7-
internal static async Task<string> QueryDocumentsAsync(
7+
internal static async Task<SupportingContentRecord[]> QueryDocumentsAsync(
88
this SearchClient searchClient,
99
string? query = null,
1010
float[]? embedding = null,
@@ -68,7 +68,7 @@ internal static async Task<string> QueryDocumentsAsync(
6868
// "sourcepage": "Northwind_Standard_Benefits_Details-24.pdf",
6969
// "sourcefile": "Northwind_Standard_Benefits_Details.pdf"
7070
// }
71-
var sb = new StringBuilder();
71+
var sb = new List<SupportingContentRecord>();
7272
foreach (var doc in searchResult.GetResults())
7373
{
7474
doc.Document.TryGetValue("sourcepage", out var sourcePageValue);
@@ -94,11 +94,10 @@ internal static async Task<string> QueryDocumentsAsync(
9494
if (sourcePageValue is string sourcePage && contentValue is string content)
9595
{
9696
content = content.Replace('\r', ' ').Replace('\n', ' ');
97-
sb.AppendLine($"{sourcePage}:{content}");
97+
sb.Add(new SupportingContentRecord(sourcePage,content));
9898
}
9999
}
100-
documentContents = sb.ToString();
101100

102-
return documentContents;
101+
return sb.ToArray();
103102
}
104103
}

app/backend/Services/ReadRetrieveReadChatService.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,17 @@ standard plan AND dental AND employee benefit.
7777

7878
// step 2
7979
// use query to search related docs
80-
var documentContents = await _searchClient.QueryDocumentsAsync(query, embeddings, overrides, cancellationToken);
80+
var documentContentList = await _searchClient.QueryDocumentsAsync(query, embeddings, overrides, cancellationToken);
8181

82-
if (string.IsNullOrEmpty(documentContents))
82+
string documentContents = string.Empty;
83+
if (documentContentList.Length == 0)
8384
{
8485
documentContents = "no source available.";
8586
}
87+
else
88+
{
89+
documentContents = string.Join("\r", documentContentList.Select(x =>$"{x.Title}:{x.Content}"));
90+
}
8691

8792
Console.WriteLine(documentContents);
8893
// step 3
@@ -152,7 +157,7 @@ Return the follow-up question as a json string list.
152157
}
153158
}
154159
return new ApproachResponse(
155-
DataPoints: documentContents.Split('\r'),
160+
DataPoints: documentContentList,
156161
Answer: ans,
157162
Thoughts: thoughts,
158163
CitationBaseUrl: _configuration.ToCitationBaseUrl());

app/frontend/Components/SupportingContent.razor.Parser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ namespace ClientApp.Components;
44

55
public sealed partial class SupportingContent
66
{
7-
internal static ParsedSupportingContentItem ParseSupportingContent(string item)
7+
internal static ParsedSupportingContentItem ParseSupportingContent(SupportingContentRecord item)
88
{
99
// Assumes the item starts with the file name followed by : and the content.
1010
// Example: "sdp_corporate.pdf: this is the content that follows".
11-
var parts = item.Split(":");
12-
var title = parts[0];
11+
var title = item.Title;
12+
var content = item.Content;
1313

14-
return parts is { Length: 2 } ? new ParsedSupportingContentItem(title, parts[1].Trim()) : new ParsedSupportingContentItem(title);
14+
return new ParsedSupportingContentItem(title, content.Trim());
1515
}
1616
}
1717

app/frontend/Components/SupportingContent.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ClientApp.Components;
44

55
public sealed partial class SupportingContent
66
{
7-
[Parameter, EditorRequired] public required string[] DataPoints { get; set; }
7+
[Parameter, EditorRequired] public required SupportingContentRecord[] DataPoints { get; set; }
88

99
private ParsedSupportingContentItem[] _supportingContent = [];
1010

app/shared/Shared/Models/ApproachResponse.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Shared.Models;
44

5+
public record SupportingContentRecord(string Title, string Content);
56
public record ApproachResponse(
67
string Answer,
78
string? Thoughts,
8-
string[] DataPoints,
9+
SupportingContentRecord[] DataPoints, // title, content
910
string CitationBaseUrl,
1011
string? Error = null);

app/tests/ClientApp.Tests/SupportingContentParserTests.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
using Shared.Models;
4+
35
namespace ClientApp.Tests;
46

57
#pragma warning disable CA1416 // Validate platform compatibility
@@ -12,14 +14,14 @@ public static IEnumerable<object[]> ParserInput
1214
{
1315
yield return new object[]
1416
{
15-
"test.pdf:blah blah",
17+
new SupportingContentRecord("test.pdf","blah blah"),
1618
"test.pdf",
1719
"blah blah",
1820
};
1921

2022
yield return new object[]
2123
{
22-
"sdp_corporate.pdf: this is the content that follows",
24+
new SupportingContentRecord("sdp_corporate.pdf", "this is the content that follows"),
2325
"sdp_corporate.pdf",
2426
"this is the content that follows",
2527
};
@@ -28,7 +30,7 @@ public static IEnumerable<object[]> ParserInput
2830

2931
[Theory, MemberData(nameof(ParserInput))]
3032
public void SupportingContentCorrectlyParsesText(
31-
string supportingContent,
33+
SupportingContentRecord supportingContent,
3234
string expectedTitle,
3335
string? expectedContent)
3436
{

0 commit comments

Comments
 (0)