mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
format code (#14)
This commit is contained in:
1
python/llm/__init__.py
Normal file
1
python/llm/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .embedding_model import HuEmbedding
|
||||
31
python/llm/embedding_model.py
Normal file
31
python/llm/embedding_model.py
Normal file
@ -0,0 +1,31 @@
|
||||
from abc import ABC
|
||||
from FlagEmbedding import FlagModel
|
||||
import torch
|
||||
|
||||
class Base(ABC):
|
||||
def encode(self, texts: list, batch_size=32):
|
||||
raise NotImplementedError("Please implement encode method!")
|
||||
|
||||
|
||||
class HuEmbedding(Base):
|
||||
def __init__(self):
|
||||
"""
|
||||
If you have trouble downloading HuggingFace models, -_^ this might help!!
|
||||
|
||||
For Linux:
|
||||
export HF_ENDPOINT=https://hf-mirror.com
|
||||
|
||||
For Windows:
|
||||
Good luck
|
||||
^_-
|
||||
|
||||
"""
|
||||
self.model = FlagModel("BAAI/bge-large-zh-v1.5",
|
||||
query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:",
|
||||
use_fp16=torch.cuda.is_available())
|
||||
|
||||
def encode(self, texts: list, batch_size=32):
|
||||
res = []
|
||||
for i in range(0, len(texts), batch_size):
|
||||
res.extend(self.encode(texts[i:i+batch_size]))
|
||||
return res
|
||||
@ -209,10 +209,8 @@ def rm_doc_from_kb(df):
|
||||
|
||||
def main(comm, mod):
|
||||
global model
|
||||
from FlagEmbedding import FlagModel
|
||||
model = FlagModel('/opt/home/kevinhu/data/bge-large-zh-v1.5/',
|
||||
query_instruction_for_retrieval="为这个句子生成表示以用于检索相关文章:",
|
||||
use_fp16=torch.cuda.is_available())
|
||||
from llm import HuEmbedding
|
||||
model = HuEmbedding()
|
||||
tm_fnm = f"res/{comm}-{mod}.tm"
|
||||
tm = findMaxDt(tm_fnm)
|
||||
rows = collect(comm, mod, tm)
|
||||
|
||||
@ -16,7 +16,9 @@ class Config:
|
||||
|
||||
def get(self, key, default=None):
|
||||
global CF
|
||||
return CF[self.env].get(key, default)
|
||||
return os.environ.get(key.upper(), \
|
||||
CF[self.env].get(key, default)
|
||||
)
|
||||
|
||||
def init(env):
|
||||
return Config(env)
|
||||
|
||||
@ -49,11 +49,7 @@ class Postgres(object):
|
||||
cur = self.conn.cursor()
|
||||
cur.execute(sql)
|
||||
updated_rows = cur.rowcount
|
||||
<<<<<<< HEAD
|
||||
self.conn.commit()
|
||||
=======
|
||||
conn.commit()
|
||||
>>>>>>> upstream/main
|
||||
cur.close()
|
||||
return updated_rows
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user