XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

add oraai

e94e9ffa
hp256 <971748116@qq.com>
提交于

代码差异

2 个文件 +122 -0
Added gpt4free/oraai/README.md +20 -0
@@ -0,0 +1,20 @@
1 # OraAI
2 Written by [hp_mzx](https://github.com/hpsj).
3
4 ## Examples:
5 ### Completion:
6 ```python
7 chunk = oraai.Completion.create("who are you")
8 print(chunk)
9 ```
10
11 ### Chat Completion:
12 Support context
13 ```python
14 obj = oraai.Completion()
15 whilt True:
16 prompt = input("Please enter a question:")
17 chunk = obj.create(prompt)
18 print(chunk)
19 print()
20 ```
Added gpt4free/oraai/__init__.py +102 -0
@@ -0,0 +1,102 @@
1 import time
2 import json
3 import uuid
4 import random
5 import requests
6 from fake_useragent import UserAgent
7
8
9 class ChatCompletion:
10 def __init__(self,proxy=None,chatbotId="5111b690-edd3-403f-b02a-607332d059f9"):
11 self.userId = "auto:"+str(uuid.uuid4())
12 self.chatbotId = chatbotId
13 self.proxies = {'http': 'http://' + proxy, 'https': 'http://' + proxy} if proxy else None
14 self.conversationId = None
15 self.headers = {
16 "Content-Type": "application/json",
17 "Origin": "https://ora.ai",
18 "Referer": "https://ora.ai/",
19 'user-agent': UserAgent().random,
20 }
21
22 def create(self,prompt: str):
23 url = "https://ora.ai/api/conversation"
24 data = {
25 "chatbotId": self.chatbotId,
26 "config": False,
27 "includeHistory": True,
28 "input": prompt,
29 "provider": "OPEN_AI",
30 "userId": self.userId,
31 }
32
33 if self.conversationId:
34 data["conversationId"] = self.conversationId
35 response = requests.post(
36 url,
37 data=json.dumps(data),
38 proxies=self.proxies,
39 headers=self.headers
40 )
41 if response.status_code == 200:
42 response_json = response.json()
43 self.conversationId = response_json["conversationId"]
44 return response_json["response"]
45
46 raise ValueError(response.text)
47
48
49 def generate_image(self,prompt:str):
50 url = "https://ora.ai/api/images/request"
51 data = {
52 "prompt":prompt,
53 "seed":random.randint(0, 4294967295)
54 }
55 response = requests.post(
56 url,
57 data=json.dumps(data),
58 proxies=self.proxies,
59 headers=self.headers
60 )
61 if response.status_code == 200:
62 inferenceId = response.json()["id"]
63 else:
64 raise ValueError(response.text)
65
66 data = {
67 "chatbotId":self.chatbotId,
68 "inferenceId":inferenceId,
69 "userId":self.userId,
70 "userInput":"/generate " + prompt
71 }
72 print(data)
73 if self.conversationId:
74 data["conversationId"] = self.conversationId
75 while True:
76 response = requests.post(
77 "https://ora.ai/api/images/check",
78 data=json.dumps(data),
79 proxies=self.proxies,
80 headers=self.headers
81 )
82 if response.status_code == 200:
83 response_json = response.json()
84 if response_json.get("conversationId"):
85 self.conversationId = response_json["conversationId"]
86 return response_json["inference"]["images"][0]["uri"]
87 else:
88 time.sleep(0.5)
89 else:
90 raise ValueError(response.text)
91
92
93 class Completion:
94 @classmethod
95 def create(self, prompt, proxy):
96 return ChatCompletion(proxy).create(prompt)
97
98
99
100
101
102