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

Update retrieval mode #10

Merged
merged 2 commits into from
Mar 1, 2024
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
2 changes: 1 addition & 1 deletion backend/server/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ async def extract_from_content(
"instructions": extractor.instruction,
}
)
return ExtractResponse(extracted=[result.extracted])
return result
22 changes: 22 additions & 0 deletions backend/tests/unit_tests/api/test_api_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from uuid import UUID

from langchain.text_splitter import CharacterTextSplitter
from langchain_community.embeddings import FakeEmbeddings
from langchain_core.runnables import RunnableLambda

from tests.db import get_async_client
Expand All @@ -23,11 +24,20 @@ def mock_text_splitter(*args, **kwargs):
return CharacterTextSplitter()


def mock_embeddings(*args, **kwargs):
return FakeEmbeddings(size=10)


@patch(
"server.extraction_runnable.extraction_runnable",
new=RunnableLambda(mock_extraction_runnable),
)
@patch(
"server.retrieval.extraction_runnable",
new=RunnableLambda(mock_extraction_runnable),
)
@patch("server.extraction_runnable.TokenTextSplitter", mock_text_splitter)
@patch("server.retrieval.OpenAIEmbeddings", mock_embeddings)
async def test_extract_from_file() -> None:
"""Test extract from file API."""
async with get_async_client() as client:
Expand Down Expand Up @@ -67,6 +77,18 @@ async def test_extract_from_file() -> None:
assert response.status_code == 200
assert response.json() == {"data": ["Test Conte"]}

# Test retrieval
response = await client.post(
"/extract",
data={
"extractor_id": extractor_id,
"text": "Test Content",
"mode": "retrieval",
},
)
assert response.status_code == 200
assert response.json() == {"data": ["Test Conte"]}

# We'll use multi-form data here.
# Create a named temporary file
with tempfile.NamedTemporaryFile(mode="w+t", delete=False) as f:
Expand Down
Loading