mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refactor:Improve the chat stream logic for NvidiaCV (#9242)
### What problem does this PR solve? Improve the chat stream logic for NvidiaCV ### Type of change - [x] Refactoring
This commit is contained in:
@ -623,15 +623,18 @@ class NvidiaCV(Base):
|
|||||||
return "**ERROR**: " + str(e), 0
|
return "**ERROR**: " + str(e), 0
|
||||||
|
|
||||||
def chat_streamly(self, system, history, gen_conf, images=[], **kwargs):
|
def chat_streamly(self, system, history, gen_conf, images=[], **kwargs):
|
||||||
|
total_tokens = 0
|
||||||
try:
|
try:
|
||||||
response = self._request(self._form_history(system, history, images), gen_conf)
|
response = self._request(self._form_history(system, history, images), gen_conf)
|
||||||
cnt = response["choices"][0]["message"]["content"]
|
cnt = response["choices"][0]["message"]["content"]
|
||||||
|
if "usage" in response and "total_tokens" in response["usage"]:
|
||||||
|
total_tokens += response["usage"]["total_tokens"]
|
||||||
for resp in cnt:
|
for resp in cnt:
|
||||||
yield resp
|
yield resp
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
yield "\n**ERROR**: " + str(e)
|
yield "\n**ERROR**: " + str(e)
|
||||||
|
|
||||||
yield response["usage"]["total_tokens"]
|
yield total_tokens
|
||||||
|
|
||||||
|
|
||||||
class AnthropicCV(Base):
|
class AnthropicCV(Base):
|
||||||
|
|||||||
Reference in New Issue
Block a user