-
Notifications
You must be signed in to change notification settings - Fork 2
Add conversational class #60
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6e2765b
Add conversational class
vitalii-bulyzhyn c06a303
Merge branch 'main' of https://github.com/diffgram/python-sdk into sc…
vitalii-bulyzhyn 5d6a70e
Add file_type on conversation creation
vitalii-bulyzhyn 295b311
Add neceray attribute creation on initialiaing of conversational
vitalii-bulyzhyn a2e5995
Finish conversational import
vitalii-bulyzhyn 9f6721f
Fix functions input/output
vitalii-bulyzhyn 8fe92ff
Add is_read_only to the attribute
vitalii-bulyzhyn 739bccc
Add is_read_only to the attribute
vitalii-bulyzhyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,5 +31,9 @@ sdk/diffgram/utils/__pycache__/ | |
|
||
venv/* | ||
|
||
diffgram.egg-info | ||
|
||
playground.py | ||
|
||
sdk/build/* | ||
sdk/dist/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
from .compound_file import CompoundFile | ||
from uuid import uuid4 | ||
import operator | ||
|
||
class Conversational: | ||
def __init__(self, project, name): | ||
self.parent = CompoundFile( | ||
project=project, | ||
name=name, | ||
directory_id=project.default_directory.id, | ||
file_type="compound/conversational" | ||
) | ||
self.project = project | ||
self.messgaes_meta = [] | ||
|
||
self.add_conversationa_attributes_if_doesnt_exist() | ||
|
||
def add_conversationa_attributes_if_doesnt_exist(self): | ||
default_schema = self.project.schema.default_schema() | ||
attribute_list = self.project.attribute.list(default_schema) | ||
|
||
message_author_attribute = None | ||
message_time_attribute = None | ||
message_date_attribute = None | ||
|
||
for attribute in attribute_list['attribute_group_list']: | ||
if attribute['name'] == 'message_author': | ||
message_author_attribute = attribute | ||
elif attribute['name'] == 'message_time': | ||
message_time_attribute = attribute | ||
elif attribute['name'] == 'message_date': | ||
message_date_attribute = attribute | ||
|
||
if message_author_attribute is None: | ||
message_author_attribute = self.project.attribute.new(default_schema) | ||
self.project.attribute.update( | ||
message_author_attribute, | ||
prompt="Author", | ||
kind="text", | ||
name="message_author", | ||
is_global = True, | ||
global_type = 'file', | ||
is_read_only=True | ||
) | ||
|
||
if message_time_attribute is None: | ||
message_time_attribute = self.project.attribute.new(default_schema) | ||
self.project.attribute.update( | ||
message_time_attribute, | ||
prompt="Time", | ||
kind="time", | ||
name="message_time", | ||
is_global = True, | ||
global_type = 'file', | ||
is_read_only=True | ||
) | ||
|
||
if message_date_attribute is None: | ||
message_date_attribute = self.project.attribute.new(default_schema) | ||
self.project.attribute.update( | ||
message_date_attribute, | ||
prompt="Date", | ||
kind="date", | ||
name="message_date", | ||
is_global = True, | ||
global_type = 'file', | ||
is_read_only=True | ||
) | ||
|
||
self.author_attribute = message_author_attribute | ||
self.time_attribute = message_time_attribute | ||
self.date_attribute = message_date_attribute | ||
|
||
def add_message(self, message_file, author=None, time=None, date=None): | ||
message_meta = { | ||
"author": author, | ||
"time": time, | ||
"date": date | ||
} | ||
|
||
self.messgaes_meta.append(message_meta) | ||
|
||
self.parent.add_child_from_local(path=message_file, ordinal=len(self.messgaes_meta)) | ||
|
||
def _new_global_instance(self): | ||
return { | ||
"creation_ref_id": str(uuid4()), | ||
"type": "global", | ||
"attribute_groups": {} | ||
} | ||
|
||
|
||
def upload(self): | ||
self.parent.upload() | ||
child_files = self.parent.fetch_child_files() | ||
child_files.sort(key=operator.attrgetter('id')) | ||
|
||
for index in range(0, len(child_files)): | ||
global_instance_for_child = self._new_global_instance() | ||
|
||
if self.messgaes_meta[index]["author"] is not None: | ||
global_instance_for_child["attribute_groups"][self.author_attribute["id"]] = self.messgaes_meta[index]["author"] | ||
if self.messgaes_meta[index]["time"] is not None: | ||
global_instance_for_child["attribute_groups"][self.time_attribute["id"]] = self.messgaes_meta[index]["time"] | ||
if self.messgaes_meta[index]["date"] is not None: | ||
global_instance_for_child["attribute_groups"][self.date_attribute["id"]] = self.messgaes_meta[index]["date"] | ||
|
||
payload = { | ||
"instance_list": [global_instance_for_child], | ||
"and_complete": False, | ||
"child_file_save_id": child_files[index].id | ||
} | ||
|
||
response = self.project.session.post(url=self.project.host + f"/api/project/{self.project.project_string_id}/file/{child_files[index].id}/annotation/update", json=payload) | ||
self.project.handle_errors(response) |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
class Attribute: | ||
def __init__(self, project): | ||
self.project = project | ||
|
||
def list(self, schema): | ||
url = f'/api/v1/project/{self.project.project_string_id}/attribute/template/list' | ||
payload = { | ||
"schema_id": schema['id'], | ||
"mode": "from_project" | ||
} | ||
|
||
response = self.project.session.post(url = self.project.host + url, json=payload) | ||
|
||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
return data | ||
|
||
def new(self, schema): | ||
url = f'/api/v1/project/{self.project.project_string_id}/attribute/group/new' | ||
payload = { | ||
"schema_id": schema['id'] | ||
} | ||
|
||
response = self.project.session.post(url = self.project.host + url, json=payload) | ||
|
||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
return data['attribute_template_group'] | ||
|
||
def update(self, | ||
attribute, | ||
prompt, | ||
kind, | ||
name = None, | ||
is_global = False, | ||
label_file_list = None, | ||
is_read_only = False, | ||
global_type = 'file', | ||
): | ||
url = f'/api/v1/project/{self.project.project_string_id}/attribute/group/update' | ||
payload = { | ||
"group_id": attribute['id'], | ||
"mode": "UPDATE", | ||
"prompt": prompt, | ||
"name": name, | ||
"kind": kind, | ||
"is_global": is_global, | ||
"label_file_list": label_file_list, | ||
"global_type": global_type, | ||
"is_read_only": is_read_only | ||
} | ||
|
||
response = self.project.session.post(url = self.project.host + url, json=payload) | ||
|
||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
return data | ||
|
||
def add_options(self, attribute, options): | ||
pass | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
class Schema: | ||
def __init__(self, project): | ||
self.project = project | ||
|
||
def list(self): | ||
url = f'/api/v1/project/{self.project.project_string_id}/labels-schema' | ||
response = self.project.session.get(url = self.project.host + url) | ||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
return data | ||
|
||
def default_schema(self): | ||
url = f'/api/v1/project/{self.project.project_string_id}/labels-schema' | ||
response = self.project.session.get(url = self.project.host + url) | ||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
default_schema = None | ||
|
||
for schema in data: | ||
if schema['is_default'] == True: | ||
default_schema = schema | ||
|
||
return default_schema | ||
|
||
|
||
def new(self, name): | ||
url = f'/api/v1/project/{self.project.project_string_id}/labels-schema/new' | ||
payload = { | ||
"name": name | ||
} | ||
|
||
response = self.project.session.post(url = self.project.host + url, json=payload) | ||
|
||
self.project.handle_errors(response) | ||
data = response.json() | ||
|
||
return data | ||
|
||
def update(self, name): | ||
#Todo | ||
pass | ||
|
||
def archive(self, name): | ||
#Todo | ||
pass | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.