From 381b7201d311062179e0690209f187d069289ffe Mon Sep 17 00:00:00 2001 From: amumu96 <15667065080@163.com> Date: Mon, 29 Apr 2024 12:23:40 +0800 Subject: [PATCH] fix metric empty --- xinference/core/model.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xinference/core/model.py b/xinference/core/model.py index 63616cf3a7..251e90ce92 100644 --- a/xinference/core/model.py +++ b/xinference/core/model.py @@ -25,6 +25,7 @@ AsyncGenerator, Callable, Dict, + Generator, Iterator, List, Optional, @@ -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"]