From fdcaff9982e0e996b6e81d6e014254c6931d9798 Mon Sep 17 00:00:00 2001 From: SFirouzi Date: Thu, 23 Oct 2025 12:19:38 +0330 Subject: [PATCH] add sub cluster --- .gitignore | 1 + post_sub_cluster.py | 35 +++++------------------------------ 2 files changed, 6 insertions(+), 30 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf0824e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.log \ No newline at end of file diff --git a/post_sub_cluster.py b/post_sub_cluster.py index d19b91a..349cf21 100644 --- a/post_sub_cluster.py +++ b/post_sub_cluster.py @@ -20,36 +20,6 @@ class PostSubClusterLLM: - if you found a good fit use its id : {{"cluster" : "id_i"}} - if the title is not related to any of the cluster names, return "outlier" is "yes" : {{"outlier" : "yes"}} - Example-1: - - Input: - - title: "کتاب و درس" - - all_cluster_names: {{ - "1" : "کتابخوانی", - "2" : "فوتبال جام جهانی", - "3" : "ساختمان سازی شهری" }} - - Output: - - {{"cluster" : "1"}} - - Example-2: - - Input: - - title: "لپتاب و کامپیوتر" - - all_cluster_names: {{ - "1" : "کتابخوانی", - "2" : "فوتبال جام جهانی", - "3" : "ساختمان سازی شهری" }} - - Output: - - {{"outlier" : "yes"}} - - Example-3: - - Input: - - title: "ساختمان" - - all_cluster_names: {{ - "1" : "کتابخوانی", - "2" : "فوتبال جام جهانی", - "3" : "ساختمان سازی شهری" }} - - Output: - - {{"cluster" : "3"}} - write a small reason and give the final answer. """ @@ -69,11 +39,16 @@ class PostSubClusterLLM: headers = {"Content-Type": "application/json",} + found_cluster = False for cluster_sub_cluster in cluster_sub_cluster_list: if cluster_sub_cluster["cluster_name"] == cluster_name: sub_cluster_names = cluster_sub_cluster["sub_cluster_names"] + found_cluster = True break + if not found_cluster: + return None + sub_cluster_names_str = "{\n" for count, value in enumerate(sub_cluster_names): sub_cluster_names_str += f"{count} : {value},\n"