Pārlūkot izejas kodu

Truncate text for zhipu embedding. (#4490)

### What problem does this PR solve?


### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
tags/v0.16.0
Kevin Hu pirms 9 mēnešiem
vecāks
revīzija
be5f830878
Revīzijas autora e-pasta adrese nav piesaistīta nevienam kontam
1 mainītis faili ar 8 papildinājumiem un 0 dzēšanām
  1. 8
    0
      rag/llm/embedding_model.py

+ 8
- 0
rag/llm/embedding_model.py Parādīt failu

@@ -217,6 +217,14 @@ class ZhipuEmbed(Base):
def encode(self, texts: list):
arr = []
tks_num = 0
MAX_LEN = -1
if self.model_name.lower() == "embedding-2":
MAX_LEN = 512
if self.model_name.lower() == "embedding-3":
MAX_LEN = 3072
if MAX_LEN > 0:
texts = [truncate(t, MAX_LEN) for t in texts]

for txt in texts:
res = self.client.embeddings.create(input=txt,
model=self.model_name)

Notiek ielāde…
Atcelt
Saglabāt