32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
import sys
|
||
|
||
sys.path.append(".")
|
||
|
||
from backend.agent import vectorstore
|
||
from langchain_core.documents import Document
|
||
import clickhouse_connect
|
||
|
||
query = """
|
||
SELECT id, chat_id, telegram_id, message, timestamp
|
||
FROM telegram_parser_chatmessage
|
||
WHERE timestamp >= now() - INTERVAL 30 DAY
|
||
AND length(message) > 150
|
||
AND arrayCount(x -> position(message, x) > 0, [
|
||
'вакансия', 'ищем', 'требуется', 'разработчик', 'будет плюсом',
|
||
'зарплата', 'оклад', 'з/п', 'руб', 'опыт работы',
|
||
'требования', 'обязанности', 'условия', 'компания', 'офис',
|
||
'удаленно', 'гибкий график', 'полный день', 'частичная занятость',
|
||
'резюме', 'собеседование', 'junior', 'middle', 'senior'
|
||
]) >= 5
|
||
"""
|
||
|
||
client = clickhouse_connect.create_client(host="127.0.0.1", port=18123)
|
||
|
||
documents = []
|
||
for row in client.query(query).result_rows:
|
||
(id, chat_id, telegram_id, message, timestamp) = row
|
||
metadata = {"chat_id": chat_id, "telegram_id": telegram_id, "timestamp": timestamp.isoformat()}
|
||
documents.append(Document(id=id, page_content=message, metadata=metadata))
|
||
|
||
vectorstore.add_documents(documents)
|