Skip to content

Commit

Permalink
duckduckgo search and websearch retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Khoroshev committed Dec 5, 2023
1 parent e14cdb0 commit 47abbca
Show file tree
Hide file tree
Showing 6 changed files with 586 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/libs/LangChain.Core/LangChain.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
<None Remove="Chains\QuestionAnswering\**" />
</ItemGroup>

<ItemGroup Label="Usings">
<Using Remove="System.Net.Http" />
</ItemGroup>

<PropertyGroup Label="NuGet">
<Description>LangChain core classes.</Description>
<PackageTags>$(PackageTags);core</PackageTags>
Expand All @@ -32,6 +28,7 @@

<ItemGroup Condition="'$(TargetFramework)'=='net4.6.2'">
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
Expand Down
32 changes: 32 additions & 0 deletions src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using LangChain.Callback;
using LangChain.Docstore;
using LangChain.Utilities;

namespace LangChain.Retrievers;

public sealed class WebSearchRetriever : BaseRetriever

Check warning on line 7 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'WebSearchRetriever'
{
private readonly IWebSearch _webSearch;
private readonly int _k;

public WebSearchRetriever(IWebSearch webSearch, int k = 10)

Check warning on line 12 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'WebSearchRetriever.WebSearchRetriever(IWebSearch, int)'
{
_webSearch = webSearch;
_k = k;
}

protected override async Task<IEnumerable<Document>> GetRelevantDocumentsCoreAsync(

Check warning on line 18 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Nullability of type of parameter 'runManager' doesn't match overridden member (possibly because of nullability attributes).

Check warning on line 18 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Missing XML comment for publicly visible type or member 'WebSearchRetriever.GetRelevantDocumentsCoreAsync(string, CallbackManagerForRetrieverRun)'
string query,
CallbackManagerForRetrieverRun runManager = null)

Check warning on line 20 in src/libs/LangChain.Core/Retrievers/WebSearchRetriever.cs

View workflow job for this annotation

GitHub Actions / Build and test / Build, test and publish

Cannot convert null literal to non-nullable reference type.
{
var searchResult = await _webSearch.ResultsAsync(query, _k);

return searchResult.Select(v => new Document(
v.Body,
new Dictionary<string, object>()
{
["title"] = v.Title,
["link"] = v.Link
}));
}
}
Loading

0 comments on commit 47abbca

Please sign in to comment.