Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duckduckgo search and websearch retriever #87

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
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