Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ginkgobioworks/ginkgo-ai-client int…
Browse files Browse the repository at this point in the history
…o zulko/batched-batches
  • Loading branch information
Valentin Zulkower committed Nov 18, 2024
2 parents a4448fe + 9127fb9 commit 866399e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ginkgo_ai_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(
self.cause = cause
self.query = query
self.result_url = result_url
message = self._format_error_message()
super().__init__(message)

def _format_error_message(self):
cause_str = f"{self.cause.__class__.__name__}: {self.cause}"
Expand Down
17 changes: 16 additions & 1 deletion ginkgo_ai_client/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
from abc import ABC, abstractmethod

import pydantic

from ginkgo_ai_client.utils import fasta_sequence_iterator, IteratorWithLength


class QueryBase(pydantic.BaseModel, ABC):
query_name: Optional[str] = None
"""Base class for all queries. It's functions are:
- Specify the mandatory class methods `to_request_params` and `parse_response`
- Provide a better error message when a user forgets to use named arguments only.
Without that tweak, the default error message from pydantic is very technical
and confusing to new users.
"""

def __new__(cls, *args, **kwargs):
if args:
raise TypeError(
f"Invalid initialization: {cls.__name__} does not accept unnamed "
f"arguments. Please name all inputs, for instance "
f"`{cls.__name__}(field_name=value, other_field=value, ...)`."
)
return super().__new__(cls)

@abstractmethod
def to_request_params(self) -> Dict:
Expand Down
13 changes: 13 additions & 0 deletions test/test_query_creation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
import re
from ginkgo_ai_client.queries import MeanEmbeddingQuery


def test_that_forgetting_to_name_arguments_raises_the_better_error_message():
expected_error_message = re.escape(
"Invalid initialization: MeanEmbeddingQuery does not accept unnamed arguments. "
"Please name all inputs, for instance "
"`MeanEmbeddingQuery(field_name=value, other_field=value, ...)`."
)
with pytest.raises(TypeError, match=expected_error_message):
MeanEmbeddingQuery("MLLK<mask>P", model="ginkgo-aa0-650M")

0 comments on commit 866399e

Please sign in to comment.