Space-Face commited on
Commit
daf2431
1 Parent(s): 239d918

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -2
main.py CHANGED
@@ -1,12 +1,20 @@
1
  import SpaceFace as sf
2
  import GPTSimple as ai
 
3
  class AIEndpoint:
4
  def receivedMessage(self, message, user: sf.User, responder: sf.Responder):
5
  if hasattr(user, 'chat'):
6
 
7
- responder.respond(user.chat.ask(message).text)
8
  else:
9
  user.chat = ai.conversation(base_url="deepinfra", model="meta-llama/Llama-3.2-90B-Vision-Instruct")
10
- responder.respond(user.chat.ask(message).text)
 
 
 
 
 
 
 
11
  responder.close()
12
  sf.start_server([AIEndpoint()])
 
1
  import SpaceFace as sf
2
  import GPTSimple as ai
3
+ import time
4
  class AIEndpoint:
5
  def receivedMessage(self, message, user: sf.User, responder: sf.Responder):
6
  if hasattr(user, 'chat'):
7
 
8
+ answer = user.chat.ask(message, stream=True)
9
  else:
10
  user.chat = ai.conversation(base_url="deepinfra", model="meta-llama/Llama-3.2-90B-Vision-Instruct")
11
+ answer = user.chat.ask(message, stream=True)
12
+ r=""
13
+ for token in answer:
14
+ if token:
15
+ r+=token.token.replace("\n", "\\n")
16
+ if time.time() - self.cooldown >= 0.5:
17
+ responder.respond(r)
18
+ r=""
19
  responder.close()
20
  sf.start_server([AIEndpoint()])