-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathprojects.py
More file actions
75 lines (58 loc) · 2.23 KB
/
projects.py
File metadata and controls
75 lines (58 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
class TaskTemplate:
"""Task Template Object."""
def __init__(self, json, client):
self._json = json
self._client = client
self.id = json["id"]
self.version = json["version"]
self.created_at = json["created_at"]
self.updated_at = json["updated_at"]
self.template_variables = json["template_variables"]
self.response_schema = json.get("response_schema", None)
self.auto_onboard_enabled = json.get("auto_onboard_enabled", False)
def __hash__(self):
return hash(self.id)
def __str__(self):
return f"TaskTemplate(id={self.id})"
def __repr__(self):
return f"TaskTemplate({self._json})"
def get_template_variables(self):
"""Returns template variables dictionary"""
return self.template_variables
def is_auto_onboardable(self):
"""Returns boolean value whether project is auto onboardable"""
return self.auto_onboard_enabled
def get_response_schema(self):
"""Returns response schema if enabled for your account"""
return self.response_schema
def as_dict(self):
"""Returns task template object as JSON dictionary"""
return self._json
class Project:
"""Project class, containing Project information."""
def __init__(self, json, client):
self._json = json
self.name = json["name"]
self.type = json["type"]
self._client = client
self.params = None
self.version = None
self.instruction = None
if len(json["param_history"]):
self.params = json["param_history"][-1]
self.version = self.params["version"]
if "instruction" in self.params:
self.instruction = self.params["instruction"]
def __hash__(self):
return hash(self.name)
def __str__(self):
return f"Project(name={self.name})"
def __repr__(self):
return f"Project({self._json})"
def get_template(self) -> TaskTemplate:
"""Returns TaskTemplate.
Only works for Chat and TextCollection type."""
return self._client.get_project_template(self.name)
def as_dict(self):
"""Returns all attributes as a dictionary"""
return self._json