From e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4 Mon Sep 17 00:00:00 2001 From: hp256 <971748116@qq.com> Date: Fri, 19 May 2023 10:53:44 +0800 Subject: add oraai --- gpt4free/oraai/README.md | 20 +++++++++ gpt4free/oraai/__init__.py | 102 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 gpt4free/oraai/README.md create mode 100644 gpt4free/oraai/__init__.py diff --git a/gpt4free/oraai/README.md b/gpt4free/oraai/README.md new file mode 100644 index 00000000..6f538711 --- /dev/null +++ b/gpt4free/oraai/README.md @@ -0,0 +1,20 @@ +# OraAI +Written by [hp_mzx](https://github.com/hpsj). + +## Examples: +### Completion: +```python +chunk = oraai.Completion.create("who are you") +print(chunk) +``` + +### Chat Completion: +Support context +```python +obj = oraai.Completion() +whilt True: + prompt = input("Please enter a question:") + chunk = obj.create(prompt) + print(chunk) +print() +``` \ No newline at end of file diff --git a/gpt4free/oraai/__init__.py b/gpt4free/oraai/__init__.py new file mode 100644 index 00000000..99a70098 --- /dev/null +++ b/gpt4free/oraai/__init__.py @@ -0,0 +1,102 @@ +import time +import json +import uuid +import random +import requests +from fake_useragent import UserAgent + + +class ChatCompletion: + def __init__(self,proxy=None,chatbotId="5111b690-edd3-403f-b02a-607332d059f9"): + self.userId = "auto:"+str(uuid.uuid4()) + self.chatbotId = chatbotId + self.proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None + self.conversationId = None + self.headers = { + "Content-Type": "application/json", + "Origin": "https://ora.ai", + "Referer": "https://ora.ai/", + 'user-agent': UserAgent().random, + } + + def create(self,prompt: str): + url = "https://ora.ai/api/conversation" + data = { + "chatbotId": self.chatbotId, + "config": False, + "includeHistory": True, + "input": prompt, + "provider": "OPEN_AI", + "userId": self.userId, + } + + if self.conversationId: + data["conversationId"] = self.conversationId + response = requests.post( + url, + data=json.dumps(data), + proxies=self.proxies, + headers=self.headers + ) + if response.status_code == 200: + response_json = response.json() + self.conversationId = response_json["conversationId"] + return response_json["response"] + + raise ValueError(response.text) + + + def generate_image(self,prompt:str): + url = "https://ora.ai/api/images/request" + data = { + "prompt":prompt, + "seed":random.randint(0, 4294967295) + } + response = requests.post( + url, + data=json.dumps(data), + proxies=self.proxies, + headers=self.headers + ) + if response.status_code == 200: + inferenceId = response.json()["id"] + else: + raise ValueError(response.text) + + data = { + "chatbotId":self.chatbotId, + "inferenceId":inferenceId, + "userId":self.userId, + "userInput":"/generate " + prompt + } + print(data) + if self.conversationId: + data["conversationId"] = self.conversationId + while True: + response = requests.post( + "https://ora.ai/api/images/check", + data=json.dumps(data), + proxies=self.proxies, + headers=self.headers + ) + if response.status_code == 200: + response_json = response.json() + if response_json.get("conversationId"): + self.conversationId = response_json["conversationId"] + return response_json["inference"]["images"][0]["uri"] + else: + time.sleep(0.5) + else: + raise ValueError(response.text) + + +class Completion: + @classmethod + def create(self, prompt, proxy): + return ChatCompletion(proxy).create(prompt) + + + + + + -- cgit v1.2.3