Fix re-recommending vacancies
This commit is contained in:
parent
2d8d9ec0f7
commit
d107d69d77
@ -25,7 +25,7 @@ class Command(BaseCommand):
|
|||||||
help = "Collect vacancies from telegram messages"
|
help = "Collect vacancies from telegram messages"
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
documents = []
|
ids, documents = [], []
|
||||||
|
|
||||||
for index, row in enumerate(clickhouse_client.query(query).result_rows):
|
for index, row in enumerate(clickhouse_client.query(query).result_rows):
|
||||||
(id, chat_username, telegram_id, message, timestamp) = row
|
(id, chat_username, telegram_id, message, timestamp) = row
|
||||||
@ -36,9 +36,10 @@ class Command(BaseCommand):
|
|||||||
defaults={'content': message}
|
defaults={'content': message}
|
||||||
)
|
)
|
||||||
|
|
||||||
metadata = {"link": link, "vacancy_id": vacancy.id}
|
metadata = {"link": link}
|
||||||
|
ids.append(vacancy.id)
|
||||||
documents.append(Document(page_content=message, metadata=metadata))
|
documents.append(Document(page_content=message, metadata=metadata))
|
||||||
|
|
||||||
print(index, link)
|
print(index, link)
|
||||||
|
|
||||||
vector_store.add_documents(documents)
|
vector_store.add_documents(documents, ids=ids)
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from vacancies.main.vector_store import vector_store
|
|||||||
from vacancies.main.models import CustomerCV, RecommendedVacancy
|
from vacancies.main.models import CustomerCV, RecommendedVacancy
|
||||||
from vacancies.main.bot import application
|
from vacancies.main.bot import application
|
||||||
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
|
from qdrant_client.models import Filter, HasIdCondition
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -16,14 +17,21 @@ class Command(BaseCommand):
|
|||||||
customer=customer_cv.customer
|
customer=customer_cv.customer
|
||||||
).values_list('vacancy_id', flat=True)
|
).values_list('vacancy_id', flat=True)
|
||||||
|
|
||||||
|
query_filter = Filter(
|
||||||
|
must_not = [
|
||||||
|
HasIdCondition(has_id=recommended_vacancy_ids),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
document = vector_store.similarity_search(
|
document = vector_store.similarity_search(
|
||||||
customer_cv.content,
|
customer_cv.content,
|
||||||
k=1,
|
k=1,
|
||||||
filter={"vacancy_id": {"$nin": list(recommended_vacancy_ids)}}
|
filter=query_filter,
|
||||||
)[0]
|
)[0]
|
||||||
|
print(document.__dict__)
|
||||||
recommendation, _ = RecommendedVacancy.objects.get_or_create(
|
recommendation, _ = RecommendedVacancy.objects.get_or_create(
|
||||||
customer=customer_cv.customer,
|
customer=customer_cv.customer,
|
||||||
vacancy_id=document.metadata["vacancy_id"],
|
vacancy_id=document.metadata["_id"],
|
||||||
)
|
)
|
||||||
|
|
||||||
asyncio.run(application.bot.send_message(
|
asyncio.run(application.bot.send_message(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user