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

Test assistant prompt #5194

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/css/main.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/css/main.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/js/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion label_studio/frontend/dist/lsf/js/main.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions label_studio/frontend/dist/lsf/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"message": "fix: OPTIC-341: Incorrect icon width causing layout issues with TabPanels in monorepo",
"commit": "2f5b6e1f3aac6aacf23b66ac64f1d6a8f34d4036",
"branch": "master",
"date": "2023-12-08T16:36:04Z"
"message": "Test assistant prompt",
"commit": "d3b5fd37ecbbf9a0ca6012db5a85b351854ed57d",
"branch": "fb-hackathon-assistant",
"date": "2023-12-18T16:09:13Z"
}
36 changes: 36 additions & 0 deletions label_studio/ml/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""This file and its contents are licensed under the Apache License 2.0. Please see the included NOTICE for copyright information and LICENSE for a copy of the license.
"""
import json
import logging
import random
import string

import drf_yasg.openapi as openapi
from core.feature_flags import flag_set
Expand Down Expand Up @@ -230,6 +233,29 @@ class MLBackendInteractiveAnnotating(APIView):

permission_required = all_permissions.tasks_view

@staticmethod
def _find_occurrences(text, words, label):
occurrences = []
for word in words:
start = text.find(word)
while start != -1:
end = start + len(word)
characters = string.ascii_letters + string.digits # Combining letters and digits
rand_id = ''.join(random.choice(characters) for _ in range(10))

occurrences.append(
{
'value': {'start': start, 'end': end, 'text': text[start:end], 'labels': [label]},
'from_name': 'label',
'to_name': 'text',
'type': 'labels',
'id': rand_id,
'origin': 'manual',
}
)
start = text.find(word, end)
return occurrences

def post(self, request, *args, **kwargs):
ml_backend = generics.get_object_or_404(MLBackend, pk=self.kwargs['pk'])
self.check_object_permissions(self.request, ml_backend)
Expand All @@ -245,7 +271,17 @@ def post(self, request, *args, **kwargs):
context['project_credentials_password'] = task.project.task_data_password

result = ml_backend.interactive_annotating(task, context, user=request.user)
llm_results = result['data']['result'][0]['value']['text'][0]

data = json.loads(llm_results)
extracted_lists = {key: value for key, value in data.items() if isinstance(value, list)}

data = task.data['0']
all_occurences = []
for tag, items in extracted_lists.items():
all_occurences += self._find_occurrences(data, items, tag)

result['data']['result'] = all_occurences
return Response(
result,
status=status.HTTP_200_OK,
Expand Down
Loading