Skip to content

Commit

Permalink
Add optional Beta flag for QA requests (#74)
Browse files Browse the repository at this point in the history
Allows for testing out new beta implementations, if they are available.

Setting this to true will only change the behavior if there is a currently running beta available.

Disclaimer: Pricing, performance, and behavior are subject to change at any time for beta implementations. Please be  aware of this before using. You can always reach out to [email protected] if you have questions.
  • Loading branch information
benbrandt authored Dec 30, 2022
1 parent 7be998c commit 9ef5320
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.7.1

- Add beta flag for QA requests

## 2.7.0

- Add manual on readthedocs
Expand Down
20 changes: 18 additions & 2 deletions aleph_alpha_client/aleph_alpha_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ def qa(
request: QaRequest,
model: Optional[str] = None,
checkpoint: Optional[str] = None,
beta: bool = False,
) -> QaResponse:
"""Answers a question about documents.
Expand All @@ -1233,6 +1234,13 @@ def qa(
Need to set exactly one of model_name and checkpoint_name.
beta (bool, optional, default False):
Opt-in use of new beta implementations of the QA endpoint, if available. Setting this to true will only change the
behavior if there is a currently running beta available.
Disclaimer: Pricing, performance, and behavior are subject to change at any time for beta implementations. Please be
aware of this before using. You can always reach out to [email protected] if you have questions.
Examples:
>>> request = QaRequest(
query="Who likes pizza?",
Expand All @@ -1241,7 +1249,7 @@ def qa(
>>> response = client.qa(request, model="luminous-extended")
"""
response = self._post_request(
"qa",
"qa/beta" if beta else "qa",
request,
model,
checkpoint,
Expand Down Expand Up @@ -1709,6 +1717,7 @@ async def qa(
request: QaRequest,
model: Optional[str] = None,
checkpoint: Optional[str] = None,
beta: bool = True,
) -> QaResponse:
"""Answers a question about documents.
Expand All @@ -1727,6 +1736,13 @@ async def qa(
Need to set exactly one of model_name and checkpoint_name.
beta (bool, optional, default False):
Opt-in use of new beta implementations of the QA endpoint, if available. Setting this to true will only change the
behavior if there is a currently running beta available.
Disclaimer: Pricing, performance, and behavior are subject to change at any time for beta implementations. Please be
aware of this before using. You can always reach out to [email protected] if you have questions.
Examples:
>>> request = QaRequest(
query="Who likes pizza?",
Expand All @@ -1735,7 +1751,7 @@ async def qa(
>>> response = await client.qa(request, model="luminous-extended")
"""
response = await self._post_request(
"qa",
"qa/beta" if beta else "qa",
request,
model,
checkpoint,
Expand Down
2 changes: 1 addition & 1 deletion aleph_alpha_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.7.0"
__version__ = "2.7.1"
26 changes: 26 additions & 0 deletions tests/test_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,29 @@ def test_qa_with_client_against_checkpoint(
# The response should exist in the form of a json dict
assert len(response["answers"]) == 1
assert response["model_version"] is not None


def test_can_send_beta_request_and_no_model(sync_client: Client):
# when posting a QA request with a QaRequest object
request = QaRequest(
query="Who likes pizza?",
documents=[Document.from_prompt(["Andreas likes pizza."])],
)

response = sync_client.qa(request, beta=True)

# the response should exist and be in the form of a named tuple class
assert len(response.answers) == 1
assert response.model_version is not None


async def test_can_send_async_beta_request_and_no_model(async_client: AsyncClient):
request = QaRequest(
query="Who likes pizza?",
documents=[Document.from_text("Andreas likes pizza.")],
)

response = await async_client.qa(request, beta=True)
assert len(response.answers) == 1
assert response.model_version is not None
assert response.answers[0].score > 0.0

0 comments on commit 9ef5320

Please sign in to comment.