ScratchGPT / main.py
Space-Face's picture
Update main.py
76d520e verified
raw
history blame contribute delete
824 Bytes
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()])