Hansimov commited on
Commit
82cb440
1 Parent(s): a14ad21

:gem: [Feature] IdleOutputer: Start to customize message output

Browse files
conversations/conversation_connector.py CHANGED
@@ -8,7 +8,7 @@ from networks import (
8
  ChathubRequestPayloadConstructor,
9
  ConversationRequestHeadersConstructor,
10
  )
11
- from networks import MessageParser
12
  from utils.logger import logger
13
 
14
  http_proxy = "http://localhost:11111" # Replace with yours
@@ -80,7 +80,7 @@ class ConversationConnector:
80
  async def stream_chat(self, prompt=""):
81
  await self.connect()
82
  await self.send_chathub_request(prompt)
83
- message_parser = MessageParser()
84
  while not self.wss.closed:
85
  response_lines_str = await self.wss.receive_str()
86
  if isinstance(response_lines_str, str):
@@ -110,6 +110,6 @@ class ConversationConnector:
110
  # Stream: Heartbeat Signal
111
  elif data.get("type") == 6:
112
  continue
113
- # Stream: Not Monitored
114
  else:
115
  continue
 
8
  ChathubRequestPayloadConstructor,
9
  ConversationRequestHeadersConstructor,
10
  )
11
+ from networks import MessageParser, IdleOutputer
12
  from utils.logger import logger
13
 
14
  http_proxy = "http://localhost:11111" # Replace with yours
 
80
  async def stream_chat(self, prompt=""):
81
  await self.connect()
82
  await self.send_chathub_request(prompt)
83
+ message_parser = MessageParser(outputer=IdleOutputer())
84
  while not self.wss.closed:
85
  response_lines_str = await self.wss.receive_str()
86
  if isinstance(response_lines_str, str):
 
110
  # Stream: Heartbeat Signal
111
  elif data.get("type") == 6:
112
  continue
113
+ # Stream: Not Implemented
114
  else:
115
  continue
networks/__init__.py CHANGED
@@ -3,4 +3,5 @@ from .cookies_constructor import CookiesConstructor
3
  from .conversation_request_headers_constructor import (
4
  ConversationRequestHeadersConstructor,
5
  )
 
6
  from .message_parser import MessageParser
 
3
  from .conversation_request_headers_constructor import (
4
  ConversationRequestHeadersConstructor,
5
  )
6
+ from .message_outputer import IdleOutputer
7
  from .message_parser import MessageParser
networks/message_outputer.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ class IdleOutputer:
2
+ def output(self, message_content=None, message_type=None):
3
+ pass
networks/message_parser.py CHANGED
@@ -1,9 +1,11 @@
1
  from utils.logger import logger
 
2
 
3
 
4
  class MessageParser:
5
- def __init__(self) -> None:
6
  self.delta_content_pointer = 0
 
7
 
8
  def parse(self, data):
9
  arguments = data["arguments"][0]
@@ -18,6 +20,7 @@ class MessageParser:
18
  content = message["adaptiveCards"][0]["body"][0]["text"]
19
  delta_content = content[self.delta_content_pointer :]
20
  logger.line(delta_content, end="")
 
21
  self.delta_content_pointer = len(content)
22
  # Message: Suggested Questions
23
  if message.get("suggestedResponses"):
@@ -25,10 +28,17 @@ class MessageParser:
25
  for suggestion in message.get("suggestedResponses"):
26
  suggestion_text = suggestion.get("text")
27
  logger.file(f"- {suggestion_text}")
 
 
 
 
28
  # Message: Search Query
29
  elif message_type in ["InternalSearchQuery"]:
30
  message_hidden_text = message["hiddenText"]
31
  logger.note(f"\n[Searching: [{message_hidden_text}]]")
 
 
 
32
  # Message: Internal Search Results
33
  elif message_type in ["InternalSearchResult"]:
34
  logger.note("[Analyzing search results ...]")
@@ -36,9 +46,17 @@ class MessageParser:
36
  elif message_type in ["InternalLoaderMessage"]:
37
  # logger.note("[Generating answers ...]\n")
38
  pass
 
 
 
 
 
 
39
  # Message: Render Cards for Webpages
40
  elif message_type in ["RenderCardRequest"]:
41
  continue
 
 
42
  # Message: Not Implemented
43
  else:
44
  raise NotImplementedError(
 
1
  from utils.logger import logger
2
+ from networks import IdleOutputer
3
 
4
 
5
  class MessageParser:
6
+ def __init__(self, outputer=IdleOutputer()):
7
  self.delta_content_pointer = 0
8
+ self.outputer = outputer
9
 
10
  def parse(self, data):
11
  arguments = data["arguments"][0]
 
20
  content = message["adaptiveCards"][0]["body"][0]["text"]
21
  delta_content = content[self.delta_content_pointer :]
22
  logger.line(delta_content, end="")
23
+ self.outputer.output(delta_content, message_type="Completions")
24
  self.delta_content_pointer = len(content)
25
  # Message: Suggested Questions
26
  if message.get("suggestedResponses"):
 
28
  for suggestion in message.get("suggestedResponses"):
29
  suggestion_text = suggestion.get("text")
30
  logger.file(f"- {suggestion_text}")
31
+ self.outputer.output(
32
+ message.get("suggestedResponses"),
33
+ message_type="Suggestions",
34
+ )
35
  # Message: Search Query
36
  elif message_type in ["InternalSearchQuery"]:
37
  message_hidden_text = message["hiddenText"]
38
  logger.note(f"\n[Searching: [{message_hidden_text}]]")
39
+ self.outputer.output(
40
+ message_hidden_text, message_type="InternalSearchQuery"
41
+ )
42
  # Message: Internal Search Results
43
  elif message_type in ["InternalSearchResult"]:
44
  logger.note("[Analyzing search results ...]")
 
46
  elif message_type in ["InternalLoaderMessage"]:
47
  # logger.note("[Generating answers ...]\n")
48
  pass
49
+ # Message: Internal thoughts, such as "I will generate my response to the user message"
50
+ elif message_type in ["Internal"]:
51
+ pass
52
+ # Message: Internal Action Marker, no value
53
+ elif message_type in ["InternalActionMarker"]:
54
+ continue
55
  # Message: Render Cards for Webpages
56
  elif message_type in ["RenderCardRequest"]:
57
  continue
58
+ elif message_type in ["ChatName"]:
59
+ continue
60
  # Message: Not Implemented
61
  else:
62
  raise NotImplementedError(