mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-05 06:33:20 +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
|
||||
endpoint_type: str = "web"
|
||||
|
||||
@root_validator(pre=True)
|
||||
def validate_client(
|
||||
@ -34,13 +35,22 @@ class YouRetriever(BaseRetriever):
|
||||
import requests
|
||||
|
||||
headers = {"X-API-Key": self.ydc_api_key}
|
||||
results = requests.get(
|
||||
f"https://api.ydc-index.io/search?query={query}",
|
||||
headers=headers,
|
||||
).json()
|
||||
if self.endpoint_type == "web":
|
||||
results = requests.get(
|
||||
f"https://api.ydc-index.io/search?query={query}",
|
||||
headers=headers,
|
||||
).json()
|
||||
|
||||
docs = []
|
||||
for hit in results["hits"]:
|
||||
for snippet in hit["snippets"]:
|
||||
docs.append(Document(page_content=snippet))
|
||||
return docs
|
||||
docs = []
|
||||
for hit in results["hits"]:
|
||||
for snippet in hit["snippets"]:
|
||||
docs.append(Document(page_content=snippet))
|
||||
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