@@ -53,7 +53,9 @@ class Option:
53
53
label : Optional [Union [str , int ]] = None
54
54
schema_id : Optional [str ] = None
55
55
feature_schema_id : Optional [FeatureSchemaId ] = None
56
- options : Union [List ["Classification" ], List ["PromptResponseClassification" ]] = field (default_factory = list )
56
+ options : Union [List ["Classification" ],
57
+ List ["PromptResponseClassification" ]] = field (
58
+ default_factory = list )
57
59
58
60
def __post_init__ (self ):
59
61
if self .label is None :
@@ -82,7 +84,9 @@ def asdict(self) -> Dict[str, Any]:
82
84
"options" : [o .asdict (is_subclass = True ) for o in self .options ]
83
85
}
84
86
85
- def add_option (self , option : Union ["Classification" , "PromptResponseClassification" ]) -> None :
87
+ def add_option (
88
+ self , option : Union ["Classification" ,
89
+ "PromptResponseClassification" ]) -> None :
86
90
if option .name in (o .name for o in self .options ):
87
91
raise InconsistentOntologyException (
88
92
f"Duplicate nested classification '{ option .name } ' "
@@ -140,7 +144,7 @@ class Type(Enum):
140
144
class Scope (Enum ):
141
145
GLOBAL = "global"
142
146
INDEX = "index"
143
-
147
+
144
148
class UIMode (Enum ):
145
149
HOTKEY = "hotkey"
146
150
SEARCHABLE = "searchable"
@@ -155,7 +159,8 @@ class UIMode(Enum):
155
159
schema_id : Optional [str ] = None
156
160
feature_schema_id : Optional [str ] = None
157
161
scope : Scope = None
158
- ui_mode : Optional [UIMode ] = None # How this classification should be answered (e.g. hotkeys / autocomplete, etc)
162
+ ui_mode : Optional [
163
+ UIMode ] = None # How this classification should be answered (e.g. hotkeys / autocomplete, etc)
159
164
160
165
def __post_init__ (self ):
161
166
if self .class_type == Classification .Type .DROPDOWN :
@@ -187,7 +192,8 @@ def from_dict(cls, dictionary: Dict[str, Any]) -> Dict[str, Any]:
187
192
instructions = dictionary ["instructions" ],
188
193
required = dictionary .get ("required" , False ),
189
194
options = [Option .from_dict (o ) for o in dictionary ["options" ]],
190
- ui_mode = cls .UIMode (dictionary ["uiMode" ]) if "uiMode" in dictionary else None ,
195
+ ui_mode = cls .UIMode (dictionary ["uiMode" ])
196
+ if "uiMode" in dictionary else None ,
191
197
schema_id = dictionary .get ("schemaNodeId" , None ),
192
198
feature_schema_id = dictionary .get ("featureSchemaId" , None ),
193
199
scope = cls .Scope (dictionary .get ("scope" , cls .Scope .GLOBAL )))
@@ -206,7 +212,8 @@ def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
206
212
"schemaNodeId" : self .schema_id ,
207
213
"featureSchemaId" : self .feature_schema_id
208
214
}
209
- if (self .class_type == self .Type .RADIO or self .class_type == self .Type .CHECKLIST ) and self .ui_mode :
215
+ if (self .class_type == self .Type .RADIO or
216
+ self .class_type == self .Type .CHECKLIST ) and self .ui_mode :
210
217
# added because this key does nothing for text so no point of including
211
218
classification ["uiMode" ] = self .ui_mode .value
212
219
if is_subclass :
@@ -221,7 +228,8 @@ def add_option(self, option: Option) -> None:
221
228
f"Duplicate option '{ option .value } ' "
222
229
f"for classification '{ self .name } '." )
223
230
self .options .append (option )
224
-
231
+
232
+
225
233
@dataclass
226
234
class ResponseOption (Option ):
227
235
"""
@@ -239,7 +247,7 @@ class ResponseOption(Option):
239
247
feature_schema_id: (str)
240
248
options: (list)
241
249
"""
242
-
250
+
243
251
@classmethod
244
252
def from_dict (
245
253
cls ,
@@ -294,7 +302,7 @@ class PromptResponseClassification:
294
302
schema_id: (str)
295
303
feature_schema_id: (str)
296
304
"""
297
-
305
+
298
306
def __post_init__ (self ):
299
307
if self .name is None :
300
308
msg = (
@@ -314,7 +322,7 @@ def __post_init__(self):
314
322
315
323
class Type (Enum ):
316
324
PROMPT = "prompt"
317
- RESPONSE_TEXT = "response-text"
325
+ RESPONSE_TEXT = "response-text"
318
326
RESPONSE_CHECKLIST = "response-checklist"
319
327
RESPONSE_RADIO = "response-radio"
320
328
@@ -332,15 +340,18 @@ class Type(Enum):
332
340
333
341
@classmethod
334
342
def from_dict (cls , dictionary : Dict [str , Any ]) -> Dict [str , Any ]:
335
- return cls (class_type = cls .Type (dictionary ["type" ]),
336
- name = dictionary ["name" ],
337
- instructions = dictionary ["instructions" ],
338
- required = True , # always required
339
- options = [ResponseOption .from_dict (o ) for o in dictionary ["options" ]],
340
- character_min = dictionary .get ("minCharacters" , None ),
341
- character_max = dictionary .get ("maxCharacters" , None ),
342
- schema_id = dictionary .get ("schemaNodeId" , None ),
343
- feature_schema_id = dictionary .get ("featureSchemaId" , None ))
343
+ return cls (
344
+ class_type = cls .Type (dictionary ["type" ]),
345
+ name = dictionary ["name" ],
346
+ instructions = dictionary ["instructions" ],
347
+ required = True , # always required
348
+ options = [
349
+ ResponseOption .from_dict (o ) for o in dictionary ["options" ]
350
+ ],
351
+ character_min = dictionary .get ("minCharacters" , None ),
352
+ character_max = dictionary .get ("maxCharacters" , None ),
353
+ schema_id = dictionary .get ("schemaNodeId" , None ),
354
+ feature_schema_id = dictionary .get ("featureSchemaId" , None ))
344
355
345
356
def asdict (self , is_subclass : bool = False ) -> Dict [str , Any ]:
346
357
if self .class_type in self ._REQUIRES_OPTIONS \
@@ -351,12 +362,13 @@ def asdict(self, is_subclass: bool = False) -> Dict[str, Any]:
351
362
"type" : self .class_type .value ,
352
363
"instructions" : self .instructions ,
353
364
"name" : self .name ,
354
- "required" : True , # always required
365
+ "required" : True , # always required
355
366
"options" : [o .asdict () for o in self .options ],
356
367
"schemaNodeId" : self .schema_id ,
357
368
"featureSchemaId" : self .feature_schema_id
358
369
}
359
- if (self .class_type == self .Type .PROMPT or self .class_type == self .Type .RESPONSE_TEXT ):
370
+ if (self .class_type == self .Type .PROMPT or
371
+ self .class_type == self .Type .RESPONSE_TEXT ):
360
372
if self .character_min :
361
373
classification ["minCharacters" ] = self .character_min
362
374
if self .character_max :
@@ -488,7 +500,8 @@ class Ontology(DbObject):
488
500
def __init__ (self , * args , ** kwargs ) -> None :
489
501
super ().__init__ (* args , ** kwargs )
490
502
self ._tools : Optional [List [Tool ]] = None
491
- self ._classifications : Optional [Union [List [Classification ],List [PromptResponseClassification ]]] = None
503
+ self ._classifications : Optional [Union [
504
+ List [Classification ], List [PromptResponseClassification ]]] = None
492
505
493
506
def tools (self ) -> List [Tool ]:
494
507
"""Get list of tools (AKA objects) in an Ontology."""
@@ -498,15 +511,20 @@ def tools(self) -> List[Tool]:
498
511
]
499
512
return self ._tools
500
513
501
- def classifications (self ) -> List [Union [Classification , PromptResponseClassification ]]:
514
+ def classifications (
515
+ self ) -> List [Union [Classification , PromptResponseClassification ]]:
502
516
"""Get list of classifications in an Ontology."""
503
517
if self ._classifications is None :
504
518
self ._classifications = []
505
519
for classification in self .normalized ["classifications" ]:
506
- if "type" in classification and classification ["type" ] in PromptResponseClassification .Type ._value2member_map_ .keys ():
507
- self ._classifications .append (PromptResponseClassification .from_dict (classification ))
520
+ if "type" in classification and classification [
521
+ "type" ] in PromptResponseClassification .Type ._value2member_map_ .keys (
522
+ ):
523
+ self ._classifications .append (
524
+ PromptResponseClassification .from_dict (classification ))
508
525
else :
509
- self ._classifications .append (Classification .from_dict (classification ))
526
+ self ._classifications .append (
527
+ Classification .from_dict (classification ))
510
528
return self ._classifications
511
529
512
530
@@ -536,14 +554,22 @@ class OntologyBuilder:
536
554
537
555
"""
538
556
tools : List [Tool ] = field (default_factory = list )
539
- classifications : List [Union [Classification , PromptResponseClassification ]] = field (default_factory = list )
557
+ classifications : List [Union [Classification ,
558
+ PromptResponseClassification ]] = field (
559
+ default_factory = list )
560
+
561
+ def foo (self ):
562
+ pass
540
563
541
564
@classmethod
542
565
def from_dict (cls , dictionary : Dict [str , Any ]) -> Dict [str , Any ]:
543
566
classifications = []
544
567
for c in dictionary ["classifications" ]:
545
- if "type" in c and c ["type" ] in PromptResponseClassification .Type ._value2member_map_ .keys ():
546
- classifications .append (PromptResponseClassification .from_dict (c ))
568
+ if "type" in c and c [
569
+ "type" ] in PromptResponseClassification .Type ._value2member_map_ .keys (
570
+ ):
571
+ classifications .append (
572
+ PromptResponseClassification .from_dict (c ))
547
573
else :
548
574
classifications .append (Classification .from_dict (c ))
549
575
return cls (tools = [Tool .from_dict (t ) for t in dictionary ["tools" ]],
@@ -554,11 +580,13 @@ def asdict(self) -> Dict[str, Any]:
554
580
classifications = []
555
581
prompts = 0
556
582
for c in self .classifications :
557
- if hasattr (c , "class_type" ) and c .class_type in PromptResponseClassification .Type :
583
+ if hasattr (c , "class_type"
584
+ ) and c .class_type in PromptResponseClassification .Type :
558
585
if c .class_type == PromptResponseClassification .Type .PROMPT :
559
586
prompts += 1
560
587
if prompts > 1 :
561
- raise ValueError ("Only one prompt is allowed per ontology" )
588
+ raise ValueError (
589
+ "Only one prompt is allowed per ontology" )
562
590
classifications .append (PromptResponseClassification .asdict (c ))
563
591
else :
564
592
classifications .append (Classification .asdict (c ))
@@ -592,7 +620,10 @@ def add_tool(self, tool: Tool) -> None:
592
620
f"Duplicate tool name '{ tool .name } '. " )
593
621
self .tools .append (tool )
594
622
595
- def add_classification (self , classification : Union [Classification , PromptResponseClassification ]) -> None :
623
+ def add_classification (
624
+ self , classification : Union [Classification ,
625
+ PromptResponseClassification ]
626
+ ) -> None :
596
627
if classification .name in (c .name for c in self .classifications ):
597
628
raise InconsistentOntologyException (
598
629
f"Duplicate classification name '{ classification .name } '. " )
0 commit comments