-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89bae1b
commit 6298c42
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
"""Topic classifier engine.""" | ||
|
||
from dataclasses import dataclass | ||
from typing import List | ||
|
||
from ontogpt.engines.knowledge_engine import KnowledgeEngine | ||
|
||
|
||
@dataclass | ||
class TopicClassifierEngine(KnowledgeEngine): | ||
"""Engine for classifying input text based on its topic.""" | ||
|
||
def binary_classify(self, topic: str, text: str) -> bool: | ||
"""Given a topic description, indicate whether it applies to the input text.""" | ||
|
||
prompt = ( | ||
"I will provide a topic followed by a text." | ||
" If the text matches the topic, return only 'True'." | ||
" If the text does not match the topic, return only 'False'." | ||
" Do not provide any other text." | ||
f" Topic: {topic}" | ||
f" Text: {text}" | ||
) | ||
payload = self.client.complete(prompt) | ||
if payload.lower in ["true"]: | ||
return True | ||
else: | ||
return False |