Skip to content

Commit

Permalink
Second pass at type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Sep 13, 2023
1 parent 48bf7f7 commit 5b76fcd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
29 changes: 15 additions & 14 deletions src/ontogpt/engines/knowledge_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class KnowledgeEngine(ABC):
knowledge sources plus LLMs
"""

template: TEMPLATE_NAME = None
template: TEMPLATE_NAME = ""
"""LinkML Template to use for this engine.
Must be of the form <module_name>.<ClassName>"""

Expand All @@ -92,40 +92,40 @@ class KnowledgeEngine(ABC):
"""Python class for the template.
This is derived from the template and does not need to be set manually."""

template_module: ModuleType = None
template_module: ModuleType
"""Python module for the template.
This is derived from the template and does not need to be set manually."""

schemaview: SchemaView = None
"""LinkML SchemaView over the template.
This is derived from the template and does not need to be set manually."""

api_key: str = None
api_key: str = ""
"""OpenAI API key."""

model: MODEL_NAME = None
model: MODEL_NAME = ""
"""Language Model. This may be overridden in subclasses."""

# annotator: TextAnnotatorInterface = None
# """Default annotator. TODO: deprecate?"""

annotators: Dict[str, List[TextAnnotatorInterface]] = None
annotators: Dict[str, List[TextAnnotatorInterface]]
"""Annotators for each class.
An annotator will ground/map labels to CURIEs.
These override the annotators annotated in the template
"""

skip_annotators: Optional[List[TextAnnotatorInterface]] = None
skip_annotators: Optional[List[TextAnnotatorInterface]]
"""Annotators to skip.
This overrides any specified in the schema"""

mappers: List[BasicOntologyInterface] = None
mappers: List[BasicOntologyInterface]
"""List of concept mappers, to assist in grounding to desired ID prefix"""

labelers: List[BasicOntologyInterface] = None
labelers: List[BasicOntologyInterface]
"""Labelers that map CURIEs to labels"""

client: OpenAIClient = None
client: OpenAIClient
"""All calls to LLMs are delegated through this client"""

dictionary: Dict[str, str] = field(default_factory=dict)
Expand All @@ -139,13 +139,13 @@ class KnowledgeEngine(ABC):
named_entities: List[NamedEntity] = field(default_factory=list)
"""Cache of all named entities"""

auto_prefix: str = None
auto_prefix: str = ""
"""If set then non-normalized named entities will be mapped to this prefix"""

last_text: str = None
last_text: str = ""
"""Cache of last text."""

last_prompt: str = None
last_prompt: str = ""
"""Cache of last prompt used."""

encoding = None
Expand Down Expand Up @@ -321,9 +321,10 @@ def promptable_slots(self, cls: Optional[ClassDefinition] = None) -> List[SlotDe
return [s for s in sv.class_induced_slots(cls.name) if not self.slot_is_skipped(s)]

def slot_is_skipped(self, slot: SlotDefinition) -> bool:
sv = self.schemaview
if ANNOTATION_KEY_PROMPT_SKIP in slot.annotations:
return True
else:
return False

def normalize_named_entity(self, text: str, range: ElementName) -> str:
"""
Expand Down Expand Up @@ -558,7 +559,7 @@ def groundings(self, text: str, cls: ClassDefinition) -> Iterator[str]:
# raise NotImplementedError

def merge_resultsets(
self, resultset: List[ExtractionResult], unique_fields: List[str] = None
self, resultset: List[ExtractionResult], unique_fields: List[str] = [""]
) -> ExtractionResult:
"""
Merge all resultsets into a single resultset.
Expand Down
28 changes: 14 additions & 14 deletions src/ontogpt/engines/mapping_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ class Confidence(str, Enum):
class CategorizedMapping(BaseModel):
subject: CURIE = None
object: CURIE = None
completion: str = None
completion: str = ""
predicate: Union[MappingPredicate, str] = None
confidence: Union[Confidence, str] = None
similarities: List[str] = None
differences: List[str] = None
similarities: List[str] = [""]
differences: List[str] = [""]


class MappingTask(BaseModel):
subject: CURIE
object: CURIE
subject_label: str = None
object_label: str = None
subject_source: str = None
object_source: str = None
subject_adapter: str = None
object_adapter: str = None
subject_label: str = ""
object_label: str = ""
subject_source: str = ""
object_source: str = ""
subject_adapter: str = ""
object_adapter: str = ""
predicate: Union[str, MappingPredicate] = None
difficulty: Confidence = None
score: float = None
Expand All @@ -97,11 +97,11 @@ class Relationship(BaseModel):
class Concept(BaseModel):
id: CURIE
label: str
definition: str = None
synonyms: List[str] = []
parents: List[str] = []
definition: str = ""
synonyms: List[str] = [""]
parents: List[str] = [""]
relationships: List[Relationship] = []
categories: List[str] = []
categories: List[str] = [""]


@dataclass
Expand All @@ -112,7 +112,7 @@ class MappingEngine(KnowledgeEngine):
object_adapter: BasicOntologyInterface = None

def categorize_mapping(
self, subject: CURIE, object: CURIE, template_path: str = None
self, subject: CURIE, object: CURIE, template_path: str = ""
) -> CategorizedMapping:
if template_path is None:
template_path = DEFAULT_MAPPING_EVAL_PROMPT
Expand Down
2 changes: 1 addition & 1 deletion src/ontogpt/engines/spires_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def _raw_extract(
return payload

def get_completion_prompt(
self, cls: ClassDefinition = None, text: str = None, object: OBJECT = None
self, cls: ClassDefinition = None, text: str = "", object: OBJECT = None
) -> str:
"""Get the prompt for the given template."""
if cls is None:
Expand Down

0 comments on commit 5b76fcd

Please sign in to comment.