Browse Source

Fix:local variable 'response' referenced before assignment (#9230)

### What problem does this PR solve?

https://github.com/infiniflow/ragflow/issues/9227

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
tags/v0.20.1
Stephen Hu 2 months ago
parent
commit
1deb0a2d42
No account linked to committer's email address
1 changed files with 5 additions and 2 deletions
  1. 5
    2
      rag/llm/cv_model.py

+ 5
- 2
rag/llm/cv_model.py View File

def chat_streamly(self, system, history, gen_conf, images=[]): def chat_streamly(self, system, history, gen_conf, images=[]):
from transformers import GenerationConfig from transformers import GenerationConfig
ans = "" ans = ""
response = None
try: try:
response = self.model.generate_content( response = self.model.generate_content(
self._form_history(system, history, images), self._form_history(system, history, images),
except Exception as e: except Exception as e:
yield ans + "\n**ERROR**: " + str(e) yield ans + "\n**ERROR**: " + str(e)


yield response._chunks[-1].usage_metadata.total_token_count

if response and hasattr(response, "usage_metadata") and hasattr(response.usage_metadata, "total_token_count"):
yield response.usage_metadata.total_token_count
else:
yield 0


class NvidiaCV(Base): class NvidiaCV(Base):
_FACTORY_NAME = "NVIDIA" _FACTORY_NAME = "NVIDIA"

Loading…
Cancel
Save