File size: 824 Bytes
b263642
271c54a
daf2431
271c54a
b263642
271c54a
 
daf2431
271c54a
d243a03
daf2431
 
 
beb66ff
daf2431
54ec371
e24d7b0
daf2431
 
76d520e
 
a5804ff
b263642
271c54a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import SpaceFace as sf
import GPTSimple as ai
import time
class AIEndpoint:
    def receivedMessage(self, message, user: sf.User, responder: sf.Responder):
        if hasattr(user, 'chat'):
            
            answer = user.chat.ask(message, stream=True)
        else:
            user.chat = ai.conversation(base_url="deepinfra", model="meta-llama/Llama-3.2-90B-Vision-Instruct")
            answer = user.chat.ask(message, stream=True)
        r=""
        for token in answer:
            if token.token:
                r+=token.token.replace("\n", "\\n")
                if time.time() - responder.cooldown >= 0.5:
                    print(r)
                    responder.respond(r)
                    r=""

        print(r)
        responder.respond(r)
        responder.close()
sf.start_server([AIEndpoint()])