-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: Added better formatting for responses from Bing Searches & Abil…
…ity to use custom Bing Search endpoint. (#5673) Motivation and Context Returning just the page snippet from a Bing search results in a lack of context or ability to follow up on a response. This PR addresses that by adding better formatting for Bing Search responses via the "Plugins.Web" package. It also adds a method to use a custom endpoint for Bing Search. Description Formatting Changes Previous response format example: ![image](https://github.com/microsoft/semantic-kernel/assets/95053834/afad8167-0495-4a99-8975-b2090920cfd4) New response format example: ![image](https://github.com/microsoft/semantic-kernel/assets/95053834/afad8167-0495-4a99-8975-b2090920cfd4) As can be seen by the examples provided, the new response format contains much more context & provides the user with the URL of the search result so that they can click through and read further. This can be obtained programmatically later on using regex matching, then could be fed into the "[Search Url Plugin](https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Plugins/Plugins.Web/SearchUrlPlugin.cs)", to scrape the page directly, before finally summarizing and returning a complete summary of the page to the user. Endpoint Changes The ability to use a custom endpoint for Bing Search also enables a path to use an API Management instance as a front end for the Bing Search API. This is required by some end users for scenarios such as enterprise logging and usage counting for cross charge. The default behaviour for the BingConnector is to target the Bing Search endpoint directly. It is entirely optional to use a custom endpoint. Doing so, does not introduce any other code change requirements to achieve use of Bing Search. Contribution Checklist The code builds clean without any errors or warnings The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#dev-scripts) raises no violations All unit tests pass, and I have added new tests where possible I didn't break anyone 😄 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Mark Karle <mkarle@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Lee Miller <lemiller@microsoft.com> Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com> Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com> Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Co-authored-by: Lisa Harrylock <lisaharrylock@gmail.com> Co-authored-by: Shay Rojansky <roji@roji.org> Co-authored-by: Anthony Puppo <anthonyosx@gmail.com> Co-authored-by: Weihan Li <weihanli@outlook.com> Co-authored-by: Jadyn <jadyn.wong@live.com> Co-authored-by: Matthew Bolaños <matthewbolanos@gmail.com> Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com> Co-authored-by: Weihan Li <weihan.li@iherb.com> Co-authored-by: Gina Triolo <51341242+gitri-ms@users.noreply.github.com> Co-authored-by: Jib <Jibzade@gmail.com> Co-authored-by: feiyun0112 <feiyun0112@gmail.com> Co-authored-by: Adarsh Acharya <132294330+AdarshAcharya5@users.noreply.github.com> Co-authored-by: Abby Harrison <abby.harrison@microsoft.com> Co-authored-by: Jib <jib.adegunloye@mongodb.com> Co-authored-by: Steven Silvester <steven.silvester@ieee.org> Co-authored-by: Roybott <RoyHerrod@Outlook.com> Co-authored-by: John Liu <107901166+johnliu55-msft@users.noreply.github.com> Co-authored-by: zhaozhiming <zhaozhiming@users.noreply.github.com> Co-authored-by: Hiroshi Yoshioka <40815708+hyoshioka0128@users.noreply.github.com> Co-authored-by: SergeyMenshykh <sergemenshikh@gmail.com> Co-authored-by: Sun Zhigang <sunner@gmail.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: RonSijm <RonSijm@users.noreply.github.com> Co-authored-by: Joowon <joowon.kim@dm.snu.ac.kr> Co-authored-by: Devis Lucato <dluc@users.noreply.github.com> Co-authored-by: Devis Lucato <devis@microsoft.com> Co-authored-by: Gil LaHaye <gillahaye@microsoft.com> Co-authored-by: kevin-m-kent <38162246+kevin-m-kent@users.noreply.github.com> Co-authored-by: Kevin Kent <kevinkent@NU-kkent-M.local>
- Loading branch information
1 parent
4edaa13
commit 9d52fef
Showing
6 changed files
with
182 additions
and
53 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Microsoft.SemanticKernel.Plugins.Web; | ||
|
||
/// <summary> | ||
/// A sealed class containing the deserialized response from the respective Web Search API. | ||
/// </summary> | ||
/// <returns>A WebPage object containing the Web Search API response data.</returns> | ||
[SuppressMessage("Performance", "CA1056:Change the type of parameter 'uri'...", | ||
Justification = "A constant Uri cannot be defined, as required by this class")] | ||
public sealed class WebPage | ||
{ | ||
/// <summary> | ||
/// The name of the result. | ||
/// </summary> | ||
[JsonPropertyName("name")] | ||
public string Name { get; set; } = string.Empty; | ||
/// <summary> | ||
/// The URL of the result. | ||
/// </summary> | ||
[JsonPropertyName("url")] | ||
public string Url { get; set; } = string.Empty; | ||
/// <summary> | ||
/// The result snippet. | ||
/// </summary> | ||
[JsonPropertyName("snippet")] | ||
public string Snippet { get; set; } = string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// A sealed class containing the deserialized response from the respective Web Search API. | ||
/// </summary> | ||
/// <returns>A WebPages? object containing the WebPages array from a Search API response data or null.</returns> | ||
public sealed class WebSearchResponse | ||
{ | ||
/// <summary> | ||
/// A nullable WebPages object containing the Web Search API response data. | ||
/// </summary> | ||
[JsonPropertyName("webPages")] | ||
public WebPages? WebPages { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// A sealed class containing the deserialized response from the Web respective Search API. | ||
/// </summary> | ||
/// <returns>A WebPages array object containing the Web Search API response data.</returns> | ||
[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "Required by the Web Search API")] | ||
public sealed class WebPages | ||
{ | ||
/// <summary> | ||
/// a nullable WebPage array object containing the Web Search API response data. | ||
/// </summary> | ||
[JsonPropertyName("value")] | ||
public WebPage[]? Value { get; set; } | ||
} |
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