mirror of
https://github.com/spbleadersofdigtal/backend.git
synced 2024-11-21 11:06:33 +03:00
added numeric hints
This commit is contained in:
parent
e5a259f551
commit
bc33ac8bad
0
logs/.gitkeep
Normal file
0
logs/.gitkeep
Normal file
|
@ -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
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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"]},
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue
Block a user