diff --git a/logs/.gitkeep b/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/pitch_deck_generator/decks/api/serializers.py b/pitch_deck_generator/decks/api/serializers.py index 8bc3fff..c5202b2 100644 --- a/pitch_deck_generator/decks/api/serializers.py +++ b/pitch_deck_generator/decks/api/serializers.py @@ -226,4 +226,5 @@ def create(self, validated_data): s.sort(key=lambda x: int(x.split("_")[1])) for key in s: QuestionAnswerPhoto.objects.create(answer=q, file=validated_data[key]) + return q diff --git a/pitch_deck_generator/decks/signals.py b/pitch_deck_generator/decks/signals.py index 5d13bbb..339ced4 100644 --- a/pitch_deck_generator/decks/signals.py +++ b/pitch_deck_generator/decks/signals.py @@ -1,11 +1,21 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from pitch_deck_generator.decks.models import PitchDeck -from pitch_deck_generator.decks.tasks import run_pitch_deck_calculation +from pitch_deck_generator.decks.models import PitchDeck, QuestionAnswer +from pitch_deck_generator.decks.tasks import ( + generate_numeric_values, + run_pitch_deck_calculation, +) @receiver(post_save, sender=PitchDeck) def tag_create(sender, instance: PitchDeck, created, **kwargs): if created: 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}) diff --git a/pitch_deck_generator/decks/tasks.py b/pitch_deck_generator/decks/tasks.py index 64db626..9420a85 100644 --- a/pitch_deck_generator/decks/tasks.py +++ b/pitch_deck_generator/decks/tasks.py @@ -2,7 +2,12 @@ from celery import shared_task 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 = { "names": ("text", 1), @@ -125,3 +130,32 @@ def generate_batch_hints(pk: int, num: int): deck=pitch_deck, 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"]}, + )