added numeric hints

This commit is contained in:
Alexander Karpov 2023-08-26 10:44:23 +03:00
parent e5a259f551
commit bc33ac8bad
4 changed files with 48 additions and 3 deletions

0
logs/.gitkeep Normal file
View File

View File

@ -226,4 +226,5 @@ def create(self, validated_data):
s.sort(key=lambda x: int(x.split("_")[1])) s.sort(key=lambda x: int(x.split("_")[1]))
for key in s: for key in s:
QuestionAnswerPhoto.objects.create(answer=q, file=validated_data[key]) QuestionAnswerPhoto.objects.create(answer=q, file=validated_data[key])
return q return q

View File

@ -1,11 +1,21 @@
from django.db.models.signals import post_save from django.db.models.signals import post_save
from django.dispatch import receiver from django.dispatch import receiver
from pitch_deck_generator.decks.models import PitchDeck from pitch_deck_generator.decks.models import PitchDeck, QuestionAnswer
from pitch_deck_generator.decks.tasks import run_pitch_deck_calculation from pitch_deck_generator.decks.tasks import (
generate_numeric_values,
run_pitch_deck_calculation,
)
@receiver(post_save, sender=PitchDeck) @receiver(post_save, sender=PitchDeck)
def tag_create(sender, instance: PitchDeck, created, **kwargs): def tag_create(sender, instance: PitchDeck, created, **kwargs):
if created: if created:
run_pitch_deck_calculation.apply_async(kwargs={"pk": instance.pk}) run_pitch_deck_calculation.apply_async(kwargs={"pk": instance.pk})
@receiver(post_save, sender=QuestionAnswer)
def question_numeric_run(sender, instance: QuestionAnswer, created, **kwargs):
if created:
if instance.question.inner_tag == "category":
generate_numeric_values.apply_async(kwargs={"pk": instance.deck.pk})

View File

@ -2,7 +2,12 @@
from celery import shared_task from celery import shared_task
from ml.openai_handle import create_hints, create_name_hint from ml.openai_handle import create_hints, create_name_hint
from pitch_deck_generator.decks.models import PitchDeck, Question, QuestionDeckHint from pitch_deck_generator.decks.models import (
PitchDeck,
Question,
QuestionAnswer,
QuestionDeckHint,
)
data_types = { data_types = {
"names": ("text", 1), "names": ("text", 1),
@ -125,3 +130,32 @@ def generate_batch_hints(pk: int, num: int):
deck=pitch_deck, deck=pitch_deck,
hint={"type": question_type, "value": el["value"]}, hint={"type": question_type, "value": el["value"]},
) )
@shared_task
def generate_numeric_values(pk: int):
pitch_deck = PitchDeck.objects.get(pk=pk)
if q := QuestionAnswer.objects.filter(
question__inner_tag="category", deck=pitch_deck
):
if q2 := QuestionAnswer.objects.filter(
question__inner_tag="type", deck=pitch_deck
):
category = q.first().answer
type = q2.first().answer
req = requests.post(
"https://rare-needles-lead.loca.lt/numeric",
json={
"description": pitch_deck.description,
"category": category,
"type": type,
},
)
data = req.json()
for el in data:
question_type, question_id = data_types[el["type"]]
QuestionDeckHint.objects.create(
question_id=question_id,
deck=pitch_deck,
hint={"type": question_type, "value": el["value"]},
)