Skip to content

Commit

Permalink
merge (#347)
Browse files Browse the repository at this point in the history
embedding update
  • Loading branch information
yaojin3616 committed Feb 23, 2024
2 parents a08de45 + 9324c16 commit 6125d2d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
1 change: 1 addition & 0 deletions docker/bisheng/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ database_url:
# 缓存配置 redis://[[username]:[password]]@localhost:6379/0
# 普通模式:
redis_url: "redis://redis:6379/1"

# 集群模式或者哨兵模式(只能选其一):
# redis_url:
# mode: "cluster"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,31 @@ def embed(self, texts: List[str], **kwargs) -> List[List[float]]:
if self.verbose:
print('payload', inp)

max_text_to_split = 200
outp = None
try:
outp = self.client(url=self.url_ep, json=inp, timeout=self.request_timeout).json()
except requests.exceptions.Timeout:
raise Exception(f'timeout in host embedding infer, url=[{self.url_ep}]')
except Exception as e:
raise Exception(f'exception in host embedding infer: [{e}]')

if outp['status_code'] != 200:
raise ValueError(f"API returned an error: {outp['status_message']}")

start_index = 0
len_text = len(texts)
while start_index < len_text:
inp_local = {
'texts':texts[start_index:min(start_index + max_text_to_split, len_text)],
'model':self.model,
'type':emb_type
}
try:
outp_single = self.client(url=self.url_ep, json=inp_local, timeout=self.request_timeout).json()
if outp is None:
outp = outp_single
else:
outp['embeddings'] += outp_single['embeddings']
except requests.exceptions.Timeout:
raise Exception(f'timeout in host embedding infer, url=[{self.url_ep}]')
except Exception as e:
raise Exception(f'exception in host embedding infer: [{e}]')

if outp_single['status_code'] != 200:
raise ValueError(f"API returned an error: {outp['status_message']}")
start_index += max_text_to_split
return outp['embeddings']

def embed_documents(self,
Expand Down

0 comments on commit 6125d2d

Please sign in to comment.