saksuke commited on
Commit
38dddab
1 Parent(s): 69ec59f

Upload llm_router.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. llm_router.py +33 -0
llm_router.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from txtai.pipeline import Labels
2
+
3
+ class InstructionClassifier:
4
+ def __init__(self):
5
+ # Initialize the labels model
6
+ self.labels = Labels('facebook/bart-large-mnli')
7
+
8
+ self.tags = [
9
+ "Programming",
10
+ "Factual",
11
+ "Creative Writing",
12
+ "Roleplaying"
13
+ ]
14
+
15
+ self.tools_labels = ["Real Time Information needed: Available in Internet",
16
+ "Historic Information needed: Available in Wikipedia",
17
+ "Sufficient Information"]
18
+
19
+
20
+ def classify_instructions(self, data):
21
+ result = []
22
+ for text in data:
23
+ # Predict tags
24
+ tag_labels_result = self.labels(text, self.tags)
25
+ tag_label = self.tags[tag_labels_result[0][0]] if tag_labels_result[0][0] < len(self.tags) else "Unknown"
26
+
27
+ tool_labels_result = self.labels(text, self.tools_labels)
28
+ tool_label = self.tools_labels[tool_labels_result[0][0]] if tool_labels_result[0][0] < len(self.tools_labels) else "Unknown"
29
+
30
+ result.append((text, tag_label, tool_label))
31
+ return result
32
+ # Usage
33
+ classifier = InstructionClassifier()