miapia add clonely support
This commit is contained in:
36
miapia_own/aihandler_new.py
Normal file
36
miapia_own/aihandler_new.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from time import time
|
||||
import openai
|
||||
openai.api_key = "sk-proj-PdTVVVvYzcd6vs2qcRxpT3BlbkFJtq78XfSrzwEK2fqyOVHE"
|
||||
import requests
|
||||
|
||||
|
||||
class AIHandlerStream(object):
|
||||
def __init__(self):
|
||||
self.ai = openai.OpenAI(api_key="sk-proj-GaouEG2QuAcfAr1an2uBT3BlbkFJaIh0XVFXWrYQpJazlbeO")
|
||||
|
||||
def __call__(self, text):
|
||||
out = ""
|
||||
for chunk in self.ai.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are PIA. You talk with short sentences. And help people."},
|
||||
{"role": "user", "content": text}
|
||||
], stream=True
|
||||
):
|
||||
delta = chunk.choices[0].delta.content
|
||||
if delta is None:
|
||||
continue
|
||||
out += delta
|
||||
if len(out) > 0 and out[-1] in ['.', '!', ',', '?']:
|
||||
yield out
|
||||
out = ""
|
||||
if len(out) > 0:
|
||||
yield out
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
aihandler = AIHandlerStream()
|
||||
t1 = time()
|
||||
for text in aihandler("Hello, how are you, what is your name?"):
|
||||
print(time() - t1)
|
||||
print(text)
|
||||
0
miapia_own/test_new_ai.py
Normal file
0
miapia_own/test_new_ai.py
Normal file
Reference in New Issue
Block a user