Skip to content

Commit

Permalink
fix(client): raise value when embedding is empty (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxiao committed Mar 29, 2022
1 parent 16f8c40 commit b4624dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion client/clip_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def encode(self, content, **kwargs):
)

r = self._client.post(**self._get_post_payload(content, kwargs))
return self._pack_result(r)

def _pack_result(self, r):
if r.embeddings is None:
raise ValueError(
'empty embedding returned from the server. '
'This often due to a mis-config of the server, '
'restarting the server or changing the serving port number often solves the problem'
)
return r.embeddings if self._return_plain else r

def _iter_doc(self, content) -> Generator['Document', None, None]:
Expand Down Expand Up @@ -222,4 +231,5 @@ async def aencode(self, content, **kwargs):
**self._get_post_payload(content, kwargs)
):
r.extend(da)
return r.embeddings if self._return_plain else r

return self._pack_result(r)
2 changes: 1 addition & 1 deletion scripts/black.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
pip install black==20.8b1
pip install black==22.3.0
arrVar=()
echo we ignore non-*.py files and files generated from protobuf
excluded_files=(
Expand Down

0 comments on commit b4624dd

Please sign in to comment.