use snippet search optionally (#12236)

Add an additional flag which allows for hitting our new endpoint.
pull/12308/head
mrbean 12 months ago committed by GitHub
parent cce132d146
commit b7e559c7e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()
docs = []
for hit in results["hits"]:
for snippet in hit["snippets"]:
docs.append(Document(page_content=snippet))
return docs
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
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…
Cancel
Save