fix OpenAI Embedding length error (#1972)

### What problem does this PR solve?
 
#1958   fix OpenAI Embedding length error

### Type of change

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

---------

Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
This commit is contained in:
黄腾
2024-08-16 09:49:27 +08:00
committed by GitHub
parent 5b5e3677b6
commit b4ef50bdb5

View File

@ -99,14 +99,14 @@ class OpenAIEmbed(Base):
self.model_name = model_name self.model_name = model_name
def encode(self, texts: list, batch_size=32): def encode(self, texts: list, batch_size=32):
texts = [truncate(t, 8196) for t in texts] texts = [truncate(t, 8191) for t in texts]
res = self.client.embeddings.create(input=texts, res = self.client.embeddings.create(input=texts,
model=self.model_name) model=self.model_name)
return np.array([d.embedding for d in res.data] return np.array([d.embedding for d in res.data]
), res.usage.total_tokens ), res.usage.total_tokens
def encode_queries(self, text): def encode_queries(self, text):
res = self.client.embeddings.create(input=[truncate(text, 8196)], res = self.client.embeddings.create(input=[truncate(text, 8191)],
model=self.model_name) model=self.model_name)
return np.array(res.data[0].embedding), res.usage.total_tokens return np.array(res.data[0].embedding), res.usage.total_tokens