mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 19:39:00 +08:00
### What problem does this PR solve? #994 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
parent
dc7afe46fb
commit
b9bb11879f
@ -123,6 +123,7 @@ class QWenEmbed(Base):
|
||||
|
||||
def encode(self, texts: list, batch_size=10):
|
||||
import dashscope
|
||||
try:
|
||||
res = []
|
||||
token_count = 0
|
||||
texts = [truncate(t, 2048) for t in texts]
|
||||
@ -138,8 +139,12 @@ class QWenEmbed(Base):
|
||||
res.extend(embds)
|
||||
token_count += resp["usage"]["total_tokens"]
|
||||
return np.array(res), token_count
|
||||
except Exception as e:
|
||||
raise Exception("Account abnormal. Please ensure it's on good standing.")
|
||||
return np.array([]), 0
|
||||
|
||||
def encode_queries(self, text):
|
||||
try:
|
||||
resp = dashscope.TextEmbedding.call(
|
||||
model=self.model_name,
|
||||
input=text[:2048],
|
||||
@ -147,6 +152,9 @@ class QWenEmbed(Base):
|
||||
)
|
||||
return np.array(resp["output"]["embeddings"][0]
|
||||
["embedding"]), resp["usage"]["total_tokens"]
|
||||
except Exception as e:
|
||||
raise Exception("Account abnormal. Please ensure it's on good standing.")
|
||||
return np.array([]), 0
|
||||
|
||||
|
||||
class ZhipuEmbed(Base):
|
||||
|
Loading…
x
Reference in New Issue
Block a user