Skip to content

Commit bc4aa75

Browse files
committed
Add dataloader of llm assisted tagging
1 parent b77be40 commit bc4aa75

File tree

6 files changed

+32
-25
lines changed

6 files changed

+32
-25
lines changed

apps/assisted_tagging/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
from admin_auto_filters.filters import AutocompleteFilterFactory
33
from django.contrib import admin
44

5-
from assisted_tagging.models import AssistedTaggingModelPredictionTag, AssistedTaggingPrediction, DraftEntry
5+
from assisted_tagging.models import AssistedTaggingModelPredictionTag, AssistedTaggingPrediction, DraftEntry, LLMAssistedTaggingPredication
66
from deep.admin import VersionAdmin
77

8+
admin.site.register(LLMAssistedTaggingPredication)
89

910
@admin.register(DraftEntry)
1011
class DraftEntryAdmin(VersionAdmin):

apps/assisted_tagging/dataloaders.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from django.utils.functional import cached_property
55

6-
from assisted_tagging.models import AssistedTaggingPrediction
6+
from assisted_tagging.models import AssistedTaggingPrediction, LLMAssistedTaggingPredication
77

88
from utils.graphene.dataloaders import DataLoaderWithContext, WithContextMixin
99

@@ -18,7 +18,22 @@ def batch_load_fn(self, keys):
1818
return Promise.resolve([_map.get(key, []) for key in keys])
1919

2020

21+
class LLMDraftEntryPredicationsLoader(DataLoaderWithContext):
22+
def batch_load_fn(self, keys):
23+
llm_assisted_tagging_qs = LLMAssistedTaggingPredication.objects\
24+
.filter(draft_entry_id__in=keys)
25+
_map = {
26+
assisted_tagging.draft_entry: assisted_tagging.draft_entry
27+
for assisted_tagging in llm_assisted_tagging_qs
28+
}
29+
return Promise.resolve([_map.get(key) for key in keys])
30+
31+
2132
class DataLoaders(WithContextMixin):
2233
@cached_property
2334
def draft_entry_predications(self):
2435
return DraftEntryPredicationsLoader(context=self.context)
36+
37+
@cached_property
38+
def llm_draft_entry_predications(self):
39+
return LLMDraftEntryPredicationsLoader(context=self.context)

apps/assisted_tagging/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,7 @@ class Meta:
178178
class DraftEntryType(DjangoObjectType):
179179
prediction_status = graphene.Field(DraftEntryPredictionStatusEnum, required=True)
180180
prediction_status_display = EnumDescription(source='get_prediction_status_display', required=True)
181-
tags = graphene.Field(
182-
graphene.List(LLMAssistedTaggingPredictionType),
183-
)
181+
tags = graphene.Field(LLMAssistedTaggingPredictionType)
184182
geo_areas = graphene.List(
185183
graphene.NonNull(ProjectGeoAreaType)
186184
)
@@ -206,8 +204,10 @@ def resolve_geo_areas(root, info, **_):
206204
return info.context.dl.geo.draft_entry_geo_area.load(root.pk)
207205

208206
# TODO use dataloader
207+
@staticmethod
209208
def resolve_tags(root, info, **_):
210-
return LLMAssistedTaggingPredication.objects.filter(draft_entry=root)
209+
# return info.context.dl.assisted_tagging.llm_draft_entry_predications.load(root.pk)
210+
return LLMAssistedTaggingPredication.objects.get(draft_entry=root)
211211

212212

213213
class DraftEntryListType(CustomDjangoListObjectType):

apps/assisted_tagging/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def validate_lead(self, lead):
2323
if lead.project != self.project:
2424
raise serializers.ValidationError('Only lead from current project are allowed.')
2525
af = lead.project.analysis_framework
26-
if af is None or not af.assisted_tagging_enabled:
26+
if af is None:
2727
raise serializers.ValidationError('Assisted tagging is disabled for the Framework used by this project.')
2828
return lead
2929

deep/deepl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ class DeeplServiceEndpoint():
1919
ANALYSIS_GEO = f'{DEEPL_SERVER_DOMAIN}/api/v1/geolocation/'
2020
ASSISTED_TAGGING_ENTRY_PREDICT_ENDPOINT = f'{DEEPL_SERVER_DOMAIN}/api/v1/entry-classification/'
2121
ENTRY_EXTRACTION_CLASSIFICATION = f'{DEEPL_SERVER_DOMAIN}/api/v1/entry-extraction-classification/'
22-
LLM_ASSISTED_TAGGING_ENTRY_PREDICT_ENDPOINT = f'{DEEPL_SERVER_DOMAIN}/api/v1/llm-entry-classification/'
22+
LLM_ASSISTED_TAGGING_ENTRY_PREDICT_ENDPOINT = f'{DEEPL_SERVER_DOMAIN}/api/v1/entry-classification-llm/'

schema.graphql

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,20 +3238,6 @@ enum AssistedTaggingPredictionDataTypeEnum {
32383238
TAG
32393239
}
32403240

3241-
type AssistedTaggingPredictionType {
3242-
id: ID!
3243-
value: String!
3244-
prediction: Decimal
3245-
threshold: Decimal
3246-
isSelected: Boolean!
3247-
modelVersion: ID!
3248-
draftEntry: ID!
3249-
dataType: AssistedTaggingPredictionDataTypeEnum!
3250-
dataTypeDisplay: EnumDescription!
3251-
category: ID
3252-
tag: ID
3253-
}
3254-
32553241
type AssistedTaggingQueryType {
32563242
draftEntry(id: ID!): DraftEntryType
32573243
draftEntries(lead: ID, draftEntryTypes: [DraftEntryTypeEnum!], ignoreIds: [ID!], isDiscarded: Boolean, page: Int = 1, pageSize: Int): DraftEntryListType
@@ -3725,8 +3711,6 @@ type DateCountType {
37253711

37263712
scalar DateTime
37273713

3728-
scalar Decimal
3729-
37303714
type DeleteAdminLevel {
37313715
errors: [GenericScalar!]
37323716
ok: Boolean
@@ -3907,7 +3891,7 @@ type DraftEntryType {
39073891
predictionReceivedAt: DateTime
39083892
predictionStatus: DraftEntryPredictionStatusEnum!
39093893
predictionStatusDisplay: EnumDescription!
3910-
predictionTags: [AssistedTaggingPredictionType!]
3894+
tags: LLMAssistedTaggingPredictionType
39113895
geoAreas: [ProjectGeoAreaType!]
39123896
}
39133897

@@ -4628,6 +4612,13 @@ type JwtTokenType {
46284612
expiresIn: String
46294613
}
46304614

4615+
type LLMAssistedTaggingPredictionType {
4616+
id: ID!
4617+
modelVersion: ID!
4618+
draftEntry: ID!
4619+
modelTags: GenericScalar
4620+
}
4621+
46314622
enum LeadAutoEntryExtractionTypeEnum {
46324623
NONE
46334624
STARTED

0 commit comments

Comments
 (0)