mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
add support for LM Studio (#1663)
### What problem does this PR solve? #1602 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
This commit is contained in:
@ -500,3 +500,24 @@ class NvidiaEmbed(Base):
|
||||
def encode_queries(self, text):
|
||||
embds, cnt = self.encode([text])
|
||||
return np.array(embds[0]), cnt
|
||||
|
||||
|
||||
class LmStudioEmbed(Base):
|
||||
def __init__(self, key, model_name, base_url):
|
||||
if not base_url:
|
||||
raise ValueError("Local llm url cannot be None")
|
||||
if base_url.split("/")[-1] != "v1":
|
||||
self.base_url = os.path.join(base_url, "v1")
|
||||
self.client = OpenAI(api_key="lm-studio", base_url=self.base_url)
|
||||
self.model_name = model_name
|
||||
|
||||
def encode(self, texts: list, batch_size=32):
|
||||
res = self.client.embeddings.create(input=texts, model=self.model_name)
|
||||
return (
|
||||
np.array([d.embedding for d in res.data]),
|
||||
1024,
|
||||
) # local embedding for LmStudio donot count tokens
|
||||
|
||||
def encode_queries(self, text):
|
||||
res = self.client.embeddings.create(text, model=self.model_name)
|
||||
return np.array(res.data[0].embedding), 1024
|
||||
|
||||
Reference in New Issue
Block a user