mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-04 11:24:00 +08:00
fix SILICONFLOW embedding error (#2363)
### What problem does this PR solve? #2335 fix SILICONFLOW embedding 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:
parent
1fc14ff6d4
commit
35b7d17d97
@ -577,11 +577,40 @@ class UpstageEmbed(OpenAIEmbed):
|
||||
super().__init__(key, model_name, base_url)
|
||||
|
||||
|
||||
class SILICONFLOWEmbed(OpenAIEmbed):
|
||||
def __init__(self, key, model_name, base_url="https://api.siliconflow.cn/v1"):
|
||||
class SILICONFLOWEmbed(Base):
|
||||
def __init__(
|
||||
self, key, model_name, base_url="https://api.siliconflow.cn/v1/embeddings"
|
||||
):
|
||||
if not base_url:
|
||||
base_url = "https://api.siliconflow.cn/v1"
|
||||
super().__init__(key, model_name, base_url)
|
||||
base_url = "https://api.siliconflow.cn/v1/embeddings"
|
||||
self.headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json",
|
||||
"authorization": f"Bearer {key}",
|
||||
}
|
||||
self.base_url = base_url
|
||||
self.model_name = model_name
|
||||
|
||||
def encode(self, texts: list, batch_size=32):
|
||||
payload = {
|
||||
"model": self.model_name,
|
||||
"input": texts,
|
||||
"encoding_format": "float",
|
||||
}
|
||||
res = requests.post(self.base_url, json=payload, headers=self.headers).json()
|
||||
return (
|
||||
np.array([d["embedding"] for d in res["data"]]),
|
||||
res["usage"]["total_tokens"],
|
||||
)
|
||||
|
||||
def encode_queries(self, text):
|
||||
payload = {
|
||||
"model": self.model_name,
|
||||
"input": text,
|
||||
"encoding_format": "float",
|
||||
}
|
||||
res = requests.post(self.base_url, json=payload, headers=self.headers).json()
|
||||
return np.array(res["data"][0]["embedding"]), res["usage"]["total_tokens"]
|
||||
|
||||
|
||||
class ReplicateEmbed(Base):
|
||||
|
Loading…
x
Reference in New Issue
Block a user