diff options
author | hp256 <971748116@qq.com> | 2023-05-19 04:53:44 +0200 |
---|---|---|
committer | hp256 <971748116@qq.com> | 2023-05-19 04:53:44 +0200 |
commit | e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4 (patch) | |
tree | 2b36060a9243e0b2c796e0932baabc6633cf5ab8 | |
parent | Merge pull request #561 from ading2210/main (diff) | |
download | gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar.gz gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar.bz2 gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar.lz gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar.xz gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.tar.zst gpt4free-e94e9ffa4ee5aa70ab5a958cdce52ea619eb2de4.zip |
-rw-r--r-- | gpt4free/oraai/README.md | 20 | ||||
-rw-r--r-- | gpt4free/oraai/__init__.py | 102 |
2 files changed, 122 insertions, 0 deletions
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) + + + + + + |