From 5176e3d66468916e83c77966e93fdce107f074ea Mon Sep 17 00:00:00 2001 From: George Kasparyants Date: Tue, 6 Aug 2024 13:43:13 +0300 Subject: [PATCH] miapia add clonely support --- miapia_own/aihandler_new.py | 36 ++++++++++++++++++++++++++++++++++++ miapia_own/test_new_ai.py | 0 2 files changed, 36 insertions(+) create mode 100644 miapia_own/aihandler_new.py create mode 100644 miapia_own/test_new_ai.py diff --git a/miapia_own/aihandler_new.py b/miapia_own/aihandler_new.py new file mode 100644 index 0000000..1d1ed34 --- /dev/null +++ b/miapia_own/aihandler_new.py @@ -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) diff --git a/miapia_own/test_new_ai.py b/miapia_own/test_new_ai.py new file mode 100644 index 0000000..e69de29