mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-21 14:18:52 +00:00
use snippet search optionally (#12236)
Add an additional flag which allows for hitting our new endpoint.
This commit is contained in:
parent
cce132d146
commit
b7e559c7e1
@ -17,6 +17,7 @@ class YouRetriever(BaseRetriever):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
ydc_api_key: str
|
ydc_api_key: str
|
||||||
|
endpoint_type: str = "web"
|
||||||
|
|
||||||
@root_validator(pre=True)
|
@root_validator(pre=True)
|
||||||
def validate_client(
|
def validate_client(
|
||||||
@ -34,6 +35,7 @@ class YouRetriever(BaseRetriever):
|
|||||||
import requests
|
import requests
|
||||||
|
|
||||||
headers = {"X-API-Key": self.ydc_api_key}
|
headers = {"X-API-Key": self.ydc_api_key}
|
||||||
|
if self.endpoint_type == "web":
|
||||||
results = requests.get(
|
results = requests.get(
|
||||||
f"https://api.ydc-index.io/search?query={query}",
|
f"https://api.ydc-index.io/search?query={query}",
|
||||||
headers=headers,
|
headers=headers,
|
||||||
@ -44,3 +46,11 @@ class YouRetriever(BaseRetriever):
|
|||||||
for snippet in hit["snippets"]:
|
for snippet in hit["snippets"]:
|
||||||
docs.append(Document(page_content=snippet))
|
docs.append(Document(page_content=snippet))
|
||||||
return docs
|
return docs
|
||||||
|
elif self.endpoint_type == "snippet":
|
||||||
|
results = requests.get(
|
||||||
|
f"https://api.ydc-index.io/snippet_search?query={query}",
|
||||||
|
headers=headers,
|
||||||
|
).json()
|
||||||
|
return [Document(page_content=snippet) for snippet in results]
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Invalid endpoint type provided {self.endpoint_type}")
|
||||||
|
Loading…
Reference in New Issue
Block a user