in src/text_clustering.py [0:0]
def _postprocess_response(self, response):
if self.topic_mode == "multiple_topics":
summary = response.split("\n")[0].split(".")[0].split("(")[0]
summary = ",".join(
[txt for txt in summary.strip().split(",") if len(txt) > 0]
)
return summary
elif self.topic_mode == "single_topic":
first_line = response.split("\n")[0]
topic, score = None, None
try:
topic = first_line.split("Topic:")[1].split("(")[0].split(",")[0].strip()
except IndexError:
print("No topic found")
try:
score = first_line.split("Educational value rating:")[1].strip().split(".")[0].strip()
except IndexError:
print("No educational score found")
full_output = f"{topic}. Educational score: {score}"
return full_output
else:
raise ValueError(
f"Topic labeling mode {self.topic_mode} is not supported, use single_topic or multiple_topics instead."
)