Paulhayes commited on
Commit
e6aaa10
·
verified ·
1 Parent(s): e1e92af

Create dialogue_manager.py

Browse files
Files changed (1) hide show
  1. dialogue_manager.py +61 -0
dialogue_manager.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import uuid
3
+ from dataclasses import dataclass
4
+ from typing import Dict, Any
5
+
6
+ @dataclass
7
+ class Turn:
8
+ turn_id: str
9
+ session_id: str
10
+ user_id: str
11
+ timestamp: float
12
+ raw_input: Dict[str, Any]
13
+ normalized_input: str = ""
14
+ postprocessed_output: Dict[str, Any] = None
15
+
16
+ def __post_init__(self):
17
+ if self.turn_id is None:
18
+ self.turn_id = str(uuid.uuid4())
19
+ if self.timestamp is None:
20
+ self.timestamp = time.time()
21
+ if self.postprocessed_output is None:
22
+ self.postprocessed_output = {}
23
+
24
+ class DialogueManager:
25
+ def __init__(self, config, persistence, auth, voiceprint, asr):
26
+ self.config = config
27
+ self.persistence = persistence
28
+ self.auth = auth
29
+ self.voiceprint = voiceprint
30
+ self.asr = asr
31
+
32
+ def submit_turn(self, session_id, user_id, raw_input):
33
+ turn = Turn(
34
+ turn_id=str(uuid.uuid4()),
35
+ session_id=session_id,
36
+ user_id=user_id,
37
+ timestamp=time.time(),
38
+ raw_input=raw_input,
39
+ normalized_input=raw_input.get("text", ""),
40
+ postprocessed_output={"text": self.generate_response(raw_input.get("text", ""))}
41
+ )
42
+
43
+ # Save turn
44
+ self.persistence.save_turn(turn)
45
+
46
+ return turn
47
+
48
+ def generate_response(self, text):
49
+ # Simple mock response
50
+ if not text.strip():
51
+ return "I'm here to help. What would you like to know?"
52
+
53
+ # Add some basic responses
54
+ if "hello" in text.lower():
55
+ return "Hello! How can I assist you today?"
56
+ elif "help" in text.lower():
57
+ return "I'm Hive, your AI tutor. I can help with learning, answer questions, and remember our conversations."
58
+ elif "thank" in text.lower():
59
+ return "You're welcome! Is there anything else I can help with?"
60
+ else:
61
+ return f"I understand you said: '{text}'. Let me think about how to best help you with that."