Skip to content

Commit

Permalink
Add topic classifier engine
Browse files Browse the repository at this point in the history
  • Loading branch information
caufieldjh committed Aug 14, 2024
1 parent 89bae1b commit 6298c42
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/ontogpt/engines/topic_classifier_engine.py
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

0 comments on commit 6298c42

Please sign in to comment.