Skip to content

Commit

Permalink
fix metric empty
Browse files Browse the repository at this point in the history
  • Loading branch information
amumu96 committed Apr 29, 2024
1 parent 5fb5663 commit 381b720
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions xinference/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AsyncGenerator,
Callable,
Dict,
Generator,
Iterator,
List,
Optional,
Expand Down Expand Up @@ -379,8 +380,13 @@ async def chat(self, prompt: str, *args, **kwargs):
raise AttributeError(f"Model {self._model.model_spec} is not for chat.")
finally:
# For the non stream result.
if response is not None and isinstance(response, dict):
usage = response["usage"]
record = None
if isinstance(response, Generator) or isinstance(response, AsyncGenerator):
record = response
elif isinstance(response, bytes):
record = json.loads(response)
if record and isinstance(record, dict):
usage = record["usage"]
# Some backends may not have a valid usage, we just skip them.
completion_tokens = usage["completion_tokens"]
prompt_tokens = usage["prompt_tokens"]
Expand Down

0 comments on commit 381b720

Please sign in to comment.