mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-23 15:19:33 +00:00
response parser for ArceeRetriever (#12270)
- **Description:** Response parser for arcee retriever, - **Issue:** follow-up pr on #11578 and [discussion](https://github.com/arcee-ai/arcee-python/issues/15#issuecomment-1759874053), - **Dependencies:** NA This pr implements a parser for the response from ArceeRetreiver to convert to langchain `Document`. This closes the loop of generation and retrieval for Arcee DALMs in langchain. The reference for the response parser is [api-docs:retrieve](https://api.arcee.ai/docs#/v2/retrieve_model) Attaching screenshot of working implementation: <img width="1984" alt="Screenshot 2023-10-25 at 7 42 34 PM" src="https://github.com/langchain-ai/langchain/assets/65639964/026987b9-34b2-4e4b-b87d-69fcd0c6641a"> \*api key deleted --- Successful tests, lints, etc. ```shell Re-run pytest with --snapshot-update to delete unused snapshots. ==================================================================================================================== slowest 5 durations ===================================================================================================================== 1.56s call tests/unit_tests/schema/runnable/test_runnable.py::test_retrying 0.63s call tests/unit_tests/schema/runnable/test_runnable.py::test_map_astream 0.33s call tests/unit_tests/schema/runnable/test_runnable.py::test_map_stream_iterator_input 0.30s call tests/unit_tests/schema/runnable/test_runnable.py::test_map_astream_iterator_input 0.20s call tests/unit_tests/indexes/test_indexing.py::test_cleanup_with_different_batchsize ======================================================================================================= 1265 passed, 270 skipped, 32 warnings in 6.55s ======================================================================================================= [ "." = "" ] || poetry run black . All done! ✨ 🍰 ✨ 1871 files left unchanged. [ "." = "" ] || poetry run ruff --select I --fix . ./scripts/check_pydantic.sh . ./scripts/check_imports.sh poetry run ruff . [ "." = "" ] || poetry run black . --check All done! ✨ 🍰 ✨ 1871 files would be left unchanged. [ "." = "" ] || poetry run mypy . Success: no issues found in 1868 source files poetry run codespell --toml pyproject.toml poetry run codespell --toml pyproject.toml -w ``` Co-authored-by: Shubham Kushwaha <shwu@Shubhams-MacBook-Pro.local>
This commit is contained in:
parent
c26ec7789f
commit
07c2649753
@ -59,6 +59,43 @@ class DALMFilter(BaseModel):
|
||||
return values
|
||||
|
||||
|
||||
class ArceeDocumentSource(BaseModel):
|
||||
"""Source of an Arcee document."""
|
||||
|
||||
document: str
|
||||
name: str
|
||||
id: str
|
||||
|
||||
|
||||
class ArceeDocument(BaseModel):
|
||||
"""Arcee document."""
|
||||
|
||||
index: str
|
||||
id: str
|
||||
score: float
|
||||
source: ArceeDocumentSource
|
||||
|
||||
|
||||
class ArceeDocumentAdapter:
|
||||
"""Adapter for Arcee documents"""
|
||||
|
||||
@classmethod
|
||||
def adapt(cls, arcee_document: ArceeDocument) -> Document:
|
||||
"""Adapts an `ArceeDocument` to a langchain's `Document` object."""
|
||||
return Document(
|
||||
page_content=arcee_document.source.document,
|
||||
metadata={
|
||||
# arcee document; source metadata
|
||||
"name": arcee_document.source.name,
|
||||
"source_id": arcee_document.source.id,
|
||||
# arcee document metadata
|
||||
"index": arcee_document.index,
|
||||
"id": arcee_document.id,
|
||||
"score": arcee_document.score,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class ArceeWrapper:
|
||||
"""Wrapper for Arcee API."""
|
||||
|
||||
@ -172,7 +209,7 @@ class ArceeWrapper:
|
||||
|
||||
response = self._make_request(
|
||||
method="post",
|
||||
route=ArceeRoute.generate,
|
||||
route=ArceeRoute.generate.value,
|
||||
body=self._make_request_body_for_models(
|
||||
prompt=prompt,
|
||||
**kwargs,
|
||||
@ -196,10 +233,13 @@ class ArceeWrapper:
|
||||
|
||||
response = self._make_request(
|
||||
method="post",
|
||||
route=ArceeRoute.retrieve,
|
||||
route=ArceeRoute.retrieve.value,
|
||||
body=self._make_request_body_for_models(
|
||||
prompt=query,
|
||||
**kwargs,
|
||||
),
|
||||
)
|
||||
return [Document(**doc) for doc in response["documents"]]
|
||||
return [
|
||||
ArceeDocumentAdapter.adapt(ArceeDocument(**doc))
|
||||
for doc in response["results"]
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user