Skip to content

Commit

Permalink
Send random preset questions to users (#299)
Browse files Browse the repository at this point in the history
* Send random preset questions to users

* fix issue with less number of questions

* migrations
  • Loading branch information
Ashesh3 authored Sep 5, 2023
1 parent 641d500 commit c64f7fb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
20 changes: 20 additions & 0 deletions ayushma/migrations/0042_alter_project_preset_questions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.1 on 2023-09-04 13:02

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("ayushma", "0041_merge_20230904_0908"),
]

operations = [
migrations.AlterField(
model_name="project",
name="preset_questions",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.TextField(), blank=True, null=True, size=None
),
),
]
2 changes: 1 addition & 1 deletion ayushma/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Project(BaseModel):
choices=STTEngine.choices, default=STTEngine.WHISPER
)
model = models.IntegerField(choices=ModelType.choices, default=ModelType.GPT_3_5)
preset_questions = ArrayField(models.TextField(), null=True, blank=True, size=100)
preset_questions = ArrayField(models.TextField(), null=True, blank=True)
is_default = models.BooleanField(default=False)
archived = models.BooleanField(default=False)

Expand Down
35 changes: 31 additions & 4 deletions ayushma/serializers/project.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
from random import sample

from rest_framework import serializers

from ayushma.models import Project


class ProjectSerializer(serializers.ModelSerializer):
display_preset_questions = serializers.SerializerMethodField()

def get_display_preset_questions(self, project_object):
if project_object.preset_questions and len(project_object.preset_questions) > 4:
return sample(project_object.preset_questions, 4)
else:
return project_object.preset_questions

class Meta:
model = Project
fields = (
Expand All @@ -15,22 +25,39 @@ class Meta:
"stt_engine",
"model",
"is_default",
"display_preset_questions",
"archived",
"preset_questions",
)
read_only_fields = ("external_id", "created_at", "modified_at")
read_only_fields = (
"external_id",
"created_at",
"modified_at",
"display_preset_questions",
)


class ProjectUpdateSerializer(serializers.ModelSerializer):
display_preset_questions = serializers.SerializerMethodField()
key_set = serializers.SerializerMethodField()

def get_display_preset_questions(self, project_object):
if project_object.preset_questions and len(project_object.preset_questions) > 4:
return sample(project_object.preset_questions, 4)
else:
return project_object.preset_questions

class Meta:
model = Project
fields = ProjectSerializer.Meta.fields + ("prompt", "open_ai_key", "key_set")
fields = ProjectSerializer.Meta.fields + (
"prompt",
"open_ai_key",
"key_set",
"preset_questions",
)
extra_kwargs = {
"open_ai_key": {"write_only": True},
}
read_only_fields = ("key_set",)
read_only_fields = ("key_set", "display_preset_questions")

def update(self, instance, validated_data):
if validated_data.get("is_default", True):
Expand Down

0 comments on commit c64f7fb

Please sign in to comment.