Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base changes for instruction driven chat page project type #8

Merged
merged 5 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions backend/dataset/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class PromptAnswerEvaluationAdmin(ImportExportActionModelAdmin):
resource_class = PromptAnswerEvaluationResource


# Custom admin class for Instructions model
class InstructionsAdmin(ImportExportActionModelAdmin):
resource_class = InstructionsResource


# Custom admin class for Interactions model
class InteractionsAdmin(ImportExportActionModelAdmin):
resource_class = InteractionsResource


admin.site.register(SentenceText, SentenceTextAdmin)
admin.site.register(TranslationPair, TranslationPairAdmin)
admin.site.register(OCRDocument, OCRDocumentAdmin)
Expand All @@ -60,3 +70,5 @@ class PromptAnswerEvaluationAdmin(ImportExportActionModelAdmin):
admin.site.register(PromptBase, PromptBaseAdmin)
admin.site.register(PromptAnswer, PromptAnswerAdmin)
admin.site.register(PromptAnswerEvaluation, PromptAnswerEvaluationAdmin)
admin.site.register(Instruction, InstructionsAdmin)
admin.site.register(Interaction, InteractionsAdmin)
168 changes: 168 additions & 0 deletions backend/dataset/migrations/0046_auto_20240104_0617.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Generated by Django 3.2.14 on 2024-01-04 06:17

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("tasks", "0048_alter_annotation_unique_together"),
("dataset", "0045_promptanswer_promptanswerevaluation_promptbase"),
]

operations = [
migrations.CreateModel(
name="Instruction",
fields=[
(
"datasetbase_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="dataset.datasetbase",
),
),
(
"meta_info_model",
models.CharField(
blank=True,
help_text="Model information for the instruction",
max_length=255,
null=True,
verbose_name="Meta Info Model",
),
),
(
"meta_info_auto_generated",
models.BooleanField(
blank=True,
help_text="Whether the instruction has been auto-generated",
null=True,
verbose_name="Meta Info Auto Generated",
),
),
(
"meta_info_intent",
models.CharField(
blank=True,
help_text="Intent information for the instruction",
max_length=255,
null=True,
verbose_name="Meta Info Intent",
),
),
(
"meta_info_domain",
models.CharField(
blank=True,
help_text="Domain information for the instruction",
max_length=255,
null=True,
verbose_name="Meta Info Domain",
),
),
(
"meta_info_structure",
models.CharField(
blank=True,
help_text="Structure information for the instruction",
max_length=255,
null=True,
verbose_name="Meta Info Structure",
),
),
(
"meta_info_language",
models.CharField(
blank=True,
choices=[
("English", "English"),
("Assamese", "Assamese"),
("Bengali", "Bengali"),
("Bodo", "Bodo"),
("Dogri", "Dogri"),
("Gujarati", "Gujarati"),
("Hindi", "Hindi"),
("Kannada", "Kannada"),
("Kashmiri", "Kashmiri"),
("Konkani", "Konkani"),
("Maithili", "Maithili"),
("Malayalam", "Malayalam"),
("Manipuri", "Manipuri"),
("Marathi", "Marathi"),
("Nepali", "Nepali"),
("Odia", "Odia"),
("Punjabi", "Punjabi"),
("Sanskrit", "Sanskrit"),
("Santali", "Santali"),
("Sindhi", "Sindhi"),
("Sinhala", "Sinhala"),
("Tamil", "Tamil"),
("Telugu", "Telugu"),
("Urdu", "Urdu"),
],
help_text="Language of the instruction",
max_length=20,
null=True,
verbose_name="Meta Info Language",
),
),
("instruction_data", models.TextField(verbose_name="Instruction_data")),
("examples", models.TextField(verbose_name="Examples")),
("hint", models.TextField(verbose_name="Hint")),
],
bases=("dataset.datasetbase",),
),
migrations.AlterField(
model_name="datasetinstance",
name="dataset_type",
field=models.CharField(
choices=[
("SentenceText", "SentenceText"),
("TranslationPair", "TranslationPair"),
("OCRDocument", "OCRDocument"),
("BlockText", "BlockText"),
("Conversation", "Conversation"),
("SpeechConversation", "SpeechConversation"),
("PromptBase", "PromptBase"),
("PromptAnswer", "PromptAnswer"),
("PromptAnswerEvaluation", "PromptAnswerEvaluation"),
("Interaction", "Interaction"),
("Instruction", "Instruction"),
],
help_text="Dataset Type which is specific for each annotation task",
max_length=100,
verbose_name="dataset_type",
),
),
migrations.RenameModel(
old_name="Interactions",
new_name="Interaction",
),
migrations.AlterField(
model_name="interaction",
name="instruction_id",
field=models.ForeignKey(
help_text="ID of the related instruction",
on_delete=django.db.models.deletion.CASCADE,
to="dataset.instruction",
verbose_name="Instruction ID",
),
),
migrations.AlterField(
model_name="promptbase",
name="instruction_id",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="dataset.instruction",
),
),
migrations.DeleteModel(
name="Instructions",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.14 on 2024-01-10 07:16

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dataset", "0046_auto_20240104_0617"),
]

operations = [
migrations.AlterField(
model_name="instruction",
name="meta_info_language",
field=models.CharField(
blank=True,
choices=[
("1", "English(Any script)"),
("2", "Indic(Indic script)"),
("3", "Indic(Latin script)"),
("4", "Indic/English(Latin script)"),
],
help_text="Language of the instruction",
max_length=20,
null=True,
verbose_name="Meta Info Language",
),
),
]
23 changes: 16 additions & 7 deletions backend/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
("PromptBase", "PromptBase"),
("PromptAnswer", "PromptAnswer"),
("PromptAnswerEvaluation", "PromptAnswerEvaluation"),
("Interaction", "Interaction"),
("Instruction", "Instruction"),
]

GENDER_CHOICES = (("M", "Male"), ("F", "Female"), ("O", "Others"))
Expand Down Expand Up @@ -115,6 +117,13 @@
("Urdu", "Urdu"),
]

LANGUAGE_CHOICES_INSTRUCTIONS = (
("1", "English(Any script)"),
("2", "Indic(Indic script)"),
("3", "Indic(Latin script)"),
("4", "Indic/English(Latin script)"),
)

LLM_CHOICES = (("GPT3.5", "GPT3.5"), ("GPT4", "GPT4"), ("LLAMA2", "LLAMA2"))


Expand Down Expand Up @@ -641,7 +650,7 @@ def __str__(self):
# duration = models.TimeField()


class Instructions(DatasetBase):
class Instruction(DatasetBase):
"""
Subclass model for Instructions
"""
Expand Down Expand Up @@ -682,27 +691,27 @@ class Instructions(DatasetBase):
)
meta_info_language = models.CharField(
max_length=20,
choices=LANGUAGE_CHOICES,
choices=LANGUAGE_CHOICES_INSTRUCTIONS,
verbose_name="Meta Info Language",
null=True,
blank=True,
help_text="Language of the instruction",
)
instruction = models.TextField(verbose_name="Instruction")
instruction_data = models.TextField(verbose_name="Instruction_data")
examples = models.TextField(verbose_name="Examples")
hint = models.TextField(verbose_name="Hint")

def __str__(self):
return f"{self.id} - {self.instruction}"
return f"{self.id} - {self.instruction_data}"


class Interactions(DatasetBase):
class Interaction(DatasetBase):
"""
Subclass model for Interactions
"""

instruction_id = models.ForeignKey(
Instructions,
Instruction,
on_delete=models.CASCADE,
verbose_name="Instruction ID",
help_text="ID of the related instruction",
Expand Down Expand Up @@ -743,7 +752,7 @@ class PromptBase(DatasetBase):
help_text=("Prompt of the conversation"),
)
instruction_id = models.ForeignKey(
Instructions, on_delete=models.CASCADE, null=True, blank=True
Instruction, on_delete=models.CASCADE, null=True, blank=True
)
language = models.CharField(
verbose_name="language", choices=LANG_CHOICES, max_length=15
Expand Down
30 changes: 30 additions & 0 deletions backend/dataset/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ class Meta:
force_init_instance = True


class InstructionsResource(ModelResource, ResourceMixin):
"""
Import/Export Resource for SpeechConversation
"""

class Meta:
import_id_fields = ("id",)
exclude = ("datasetbase_ptr",)
model = Instruction
clean_model_instances = True
skip_diff = True
force_init_instance = True


class InteractionsResource(ModelResource, ResourceMixin):
"""
Import/Export Resource for SpeechConversation
"""

class Meta:
import_id_fields = ("id",)
exclude = ("datasetbase_ptr",)
model = Interaction
clean_model_instances = True
skip_diff = True
force_init_instance = True


# Define a mapping between dataset instance type and resource
RESOURCE_MAP = {
"TranslationPair": TranslationPairResource,
Expand All @@ -155,4 +183,6 @@ class Meta:
"PromptBase": PromptBaseResource,
"PromptAnswer": PromptAnswerResource,
"PromptAnswerEvaluation": PromptAnswerEvaluationResource,
"Instruction": InstructionsResource,
"Interaction": InteractionsResource,
}
14 changes: 14 additions & 0 deletions backend/dataset/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ class Meta:
fields = "__all__"


class InstructionsSerializer(serializers.ModelSerializer):
class Meta:
model = Instruction
fields = "__all__"


class InteractionsSerializer(serializers.ModelSerializer):
class Meta:
model = Interaction
fields = "__all__"


# Define a mapping between dataset instance type and serializer
SERIALIZER_MAP = {
"SentenceText": SentenceTextSerializer,
Expand All @@ -145,6 +157,8 @@ class Meta:
"PromptBase": PromptBaseSerializer,
"PromptAnswer": PromptAnswerSerializer,
"PromptAnswerEvaluation": PromptAnswerEvaluationSerializer,
"Instruction": InstructionsSerializer,
"Interaction": InteractionsSerializer,
}

# class CollectionDatasetSerializer(serializers.ModelSerializer):
Expand Down
2 changes: 2 additions & 0 deletions backend/dataset/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

router.register(r"instances", DatasetInstanceViewSet)
router.register(r"dataitems", DatasetItemsViewSet)
router.register(r"instructions", InstructionsViewSet, basename="instructions")
router.register(r"interactions", InteractionsViewSet, basename="interactions")
# router.register(r"sentences", SentenceTextViewSet)
# router.register(r"collection", CollectionDatasetViewSet)
# router.register(r"speechcol",SpeechCollectionViewset)
Expand Down
10 changes: 10 additions & 0 deletions backend/dataset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,16 @@ def get(self, request, dataset_type):
return Response(dict, status=status.HTTP_200_OK)


class InstructionsViewSet(viewsets.ModelViewSet):
queryset = Instruction.objects.all()
serializer_class = InstructionsSerializer


class InteractionsViewSet(viewsets.ModelViewSet):
queryset = Interaction.objects.all()
serializer_class = InteractionsSerializer


# class SentenceTextViewSet(viewsets.ModelViewSet):
# queryset = SentenceText.objects.all()
# serializer_class = SentenceTextSerializer
Expand Down
Loading
Loading