AGofficial commited on
Commit
f91f788
·
verified ·
1 Parent(s): 9a5b711

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. AGQS.json +3 -0
  3. AGQS.py +40 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ AGQS.json filter=lfs diff=lfs merge=lfs -text
AGQS.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aaffb5587ab1a2860d28bba4b82042810b17b7a11486367e9e68f9b5ba912700
3
+ size 873031923
AGQS.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import difflib
3
+
4
+ class AGQS:
5
+ def __init__(self, filepath):
6
+ self.pairs = []
7
+ with open(filepath, "r") as f:
8
+ for line in f:
9
+ line = line.strip()
10
+ if not line:
11
+ continue
12
+ try:
13
+ data = json.loads(line)
14
+ conversation = data.get("conversation", [])
15
+ for i in range(len(conversation) - 1):
16
+ if conversation[i]["role"] == "user" and conversation[i + 1]["role"] == "assistant":
17
+ question = conversation[i]["content"].strip()
18
+ answer = conversation[i + 1]["content"].strip()
19
+ self.pairs.append((question, answer))
20
+ except json.JSONDecodeError:
21
+ continue
22
+ self.user_questions = [q for q, _ in self.pairs]
23
+
24
+ def ask(self, prompt):
25
+ closest_match = difflib.get_close_matches(prompt, self.user_questions, n=1, cutoff=0.3)
26
+ if closest_match:
27
+ match_index = self.user_questions.index(closest_match[0])
28
+ return self.pairs[match_index][1]
29
+ else:
30
+ return "Sorry, I don't have an answer for that."
31
+
32
+ if __name__ == "__main__":
33
+ chatbot = AGQS("AGQS.json")
34
+ print("Chatbot ready. Type your message. Type 'exit' to quit.\n")
35
+ while True:
36
+ user_input = input("You: ").strip()
37
+ if user_input.lower() in {"exit", "quit"}:
38
+ break
39
+ response = chatbot.ask(user_input)
40
+ print("AI:", response)