muryshev commited on
Commit
1d40914
·
1 Parent(s): bfc27c5
business_transaction_map/components/faiss_vector_database.py CHANGED
@@ -189,10 +189,6 @@ class FaissVectorDatabase:
189
  """
190
  if len(emb_query.shape) != 2:
191
  assert print('Не правильный размер вектора!')
192
-
193
- print("Index dimension:", self.index.d) # Размерность индекса
194
- print("Query dimension:", emb_query.shape[1]) # Размерность вектора запроса
195
-
196
 
197
  distances, indexes = self.index.search(emb_query, k_neighbors)
198
  answers = {}
 
189
  """
190
  if len(emb_query.shape) != 2:
191
  assert print('Не правильный размер вектора!')
 
 
 
 
192
 
193
  distances, indexes = self.index.search(emb_query, k_neighbors)
194
  answers = {}
fastapi_app.py CHANGED
@@ -23,8 +23,6 @@ LLM_API_URL = os.getenv("LLM_API_URL", "")
23
  LLM_API_KEY = os.getenv("LLM_API_KEY", "")
24
  LLM_USE_DEEPINFRA = os.getenv("LLM_USE_DEEPINFRA", "") == "1"
25
 
26
- print(LLM_USE_DEEPINFRA)
27
-
28
  class Query(BaseModel):
29
  query: str = ''
30
  top: int = 10
@@ -46,7 +44,7 @@ class Query(BaseModel):
46
  'Бухгалтерский документ': False}
47
  llm_params: LlmParams = None
48
 
49
- # search = SemanticSearch()
50
  transaction_maps_search = TransactionMapsSearch()
51
 
52
  app = FastAPI(
@@ -78,7 +76,7 @@ def log_query_result(query, top, request_id, result):
78
  @app.post('/search')
79
  async def search_route(query: Query) -> dict:
80
 
81
- default_llm_params = LlmParams(url=LLM_API_URL,api_key=LLM_API_KEY, model="mistralai/Mixtral-8x7B-Instruct-v0.1", predict_params=LlmPredictParams(temperature=0.15, top_p=0.95, min_p=0.05, seed=42, repetition_penalty=1.2, presence_penalty=1.1, max_tokens=6000))
82
 
83
  try:
84
  question = getattr(query, "query", None)
@@ -97,7 +95,7 @@ async def search_route(query: Query) -> dict:
97
 
98
  print(request_llm_params)
99
 
100
- llm_params = default_llm_params#getattr(query, "llm_params", default_llm_params)
101
 
102
  if LLM_USE_DEEPINFRA:
103
  print(llm_params.model)
 
23
  LLM_API_KEY = os.getenv("LLM_API_KEY", "")
24
  LLM_USE_DEEPINFRA = os.getenv("LLM_USE_DEEPINFRA", "") == "1"
25
 
 
 
26
  class Query(BaseModel):
27
  query: str = ''
28
  top: int = 10
 
44
  'Бухгалтерский документ': False}
45
  llm_params: LlmParams = None
46
 
47
+ search = SemanticSearch()
48
  transaction_maps_search = TransactionMapsSearch()
49
 
50
  app = FastAPI(
 
76
  @app.post('/search')
77
  async def search_route(query: Query) -> dict:
78
 
79
+ default_llm_params = LlmParams(url=LLM_API_URL,api_key=LLM_API_KEY, model="meta-llama/Llama-3.3-70B-Instruct", predict_params=LlmPredictParams(temperature=0.15, top_p=0.95, min_p=0.05, seed=42, repetition_penalty=1.2, presence_penalty=1.1, max_tokens=6000))
80
 
81
  try:
82
  question = getattr(query, "query", None)
 
95
 
96
  print(request_llm_params)
97
 
98
+ llm_params = getattr(query, "llm_params", default_llm_params)
99
 
100
  if LLM_USE_DEEPINFRA:
101
  print(llm_params.model)
huggingface/dataset_utils.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from datasets import load_dataset
3
+
4
+ def get_global_data_path():
5
+ """
6
+ Загружает путь к папке `legal_info_search_data` внутри датасета Hugging Face.
7
+
8
+ Ожидает, что переменные окружения HF_TOKEN и HF_DATASET заданы.
9
+ Если переменные не указаны, возвращает значение по умолчанию.
10
+
11
+ Returns:
12
+ str: Путь к папке `legal_info_search_data`.
13
+ Raises:
14
+ ValueError: Если переменные окружения не указаны.
15
+ FileNotFoundError: Если папка `legal_info_search_data` не найдена.
16
+ """
17
+ # Получение переменных окружения
18
+ hf_token = os.environ.get("HF_TOKEN")
19
+ hf_dataset = os.environ.get("HF_DATASET")
20
+ default_path = os.environ.get("GLOBAL_DATA_PATH")
21
+
22
+ # Проверяем, заданы ли переменные окружения
23
+ if not hf_token or not hf_dataset:
24
+ return default_path
25
+
26
+ # Загружаем датасет
27
+ try:
28
+ dataset = load_dataset(hf_dataset, use_auth_token=hf_token)
29
+ # Получаем путь к локальному кешу датасета
30
+ dataset_cache_path = dataset.cache_files[0]['filename']
31
+ global_data_path = os.path.join(os.path.dirname(dataset_cache_path), "legal_info_search_data")
32
+
33
+ # Проверяем существование папки
34
+ if not os.path.exists(global_data_path):
35
+ raise FileNotFoundError(f"Папка {global_data_path} не найдена в датасете {hf_dataset}.")
36
+
37
+ return global_data_path
38
+ except Exception as e:
39
+ raise RuntimeError(f"Ошибка при загрузке датасета: {str(e)}")
semantic_search.py CHANGED
@@ -19,9 +19,18 @@ import torch.nn.functional as F
19
  import pickle
20
  from llm.prompts import LLM_PROMPT_QE, LLM_PROMPT_OLYMPIC, LLM_PROMPT_KEYS
21
  from llm.vllm_api import LlmApi, LlmParams
 
22
 
23
  global_data_path = os.environ.get("GLOBAL_DATA_PATH", "./legal_info_search_data/")
24
 
 
 
 
 
 
 
 
 
25
  global_model_path = os.environ.get("GLOBAL_MODEL_PATH", "./models/20240202_204910_ep8")
26
 
27
  data_path_consult = global_data_path + "external_data"
 
19
  import pickle
20
  from llm.prompts import LLM_PROMPT_QE, LLM_PROMPT_OLYMPIC, LLM_PROMPT_KEYS
21
  from llm.vllm_api import LlmApi, LlmParams
22
+ from huggingface import dataset_utils
23
 
24
  global_data_path = os.environ.get("GLOBAL_DATA_PATH", "./legal_info_search_data/")
25
 
26
+ hf_token = os.environ.get("HF_TOKEN", None)
27
+ hf_dataset = os.environ.get("HF_DATASET", None)
28
+
29
+ if hf_token is not None and hf_dataset is not None:
30
+ global_data_path = dataset_utils.get_global_data_path()
31
+ print(f"Global data path: {global_data_path}")
32
+
33
+
34
  global_model_path = os.environ.get("GLOBAL_MODEL_PATH", "./models/20240202_204910_ep8")
35
 
36
  data_path_consult = global_data_path + "external_data"