Initial commit: TrueConf Chatbot КЛЕВЕР
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import requests
|
||||
import config.config as config
|
||||
|
||||
def get_embedding(text, model_name="multilingual-e5-base"):
|
||||
"""
|
||||
Заменяет model.encode(text). Вместо локальной загрузки
|
||||
отправляет запрос к API-серверу.
|
||||
"""
|
||||
url = f"http://127.0.0.1:8010/embed"
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
# Если в конфиге задан токен, добавляем его
|
||||
if hasattr(config, 'EMBEDDING_API_TOKEN') and config.EMBEDDING_API_TOKEN:
|
||||
headers["X-Embedding-Token"] = config.EMBEDDING_API_TOKEN
|
||||
|
||||
payload = {
|
||||
"model": model_name,
|
||||
"input_type": "query", # или "passage", зависит от того, что кодируешь
|
||||
"texts": [text]
|
||||
}
|
||||
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
if response.status_code == 200:
|
||||
return response.json()["embeddings"][0]
|
||||
else:
|
||||
raise Exception(f"Ошибка API эмбеддингов: {response.text}")
|
||||
Reference in New Issue
Block a user