返回提交历史
Modified
README.md
+1
-0
Added
gpt4free/italygpt/README.md
+18
-0
Added
gpt4free/italygpt/__init__.py
+28
-0
XFEstudio/gpt4free
add italygpt.it
611a5650
代码差异
3 个文件
+47
-0
@@ -87,6 +87,7 @@ Just API's from some language model sites.
87
87
| [bard.google.com](https://bard.google.com) | custom / search |
88
88
| [bing.com/chat](https://bing.com/chat) | GPT-4/3.5 |
89
89
| [chat.forefront.ai/](https://chat.forefront.ai/) | GPT-4/3.5 |
90
| [italygpt.it](https://italygpt.it) | GPT-3.5 |
90
91
91
92
## Best sites <a name="best-sites"></a>
92
93
@@ -0,0 +1,18 @@
1
### Example: `italygpt`
2
3
```python
4
# create an instance
5
from gpt4free import italygpt
6
italygpt = italygpt.Completion()
7
8
# initialize api
9
italygpt.init()
10
11
# get an answer
12
italygpt.create(prompt="What is the meaning of life?")
13
print(italygpt.answer) # html formatted
14
15
# keep the old conversation
16
italygpt.create(prompt="Are you a human?", messages=italygpt.messages)
17
print(italygpt.answer)
18
```
@@ -0,0 +1,28 @@
1
import requests, time, ast, json
2
from bs4 import BeautifulSoup
3
from hashlib import sha256
4
5
class Completion:
6
# answer is returned with html formatting
7
next_id = None
8
messages = []
9
answer = None
10
11
def init(self):
12
r = requests.get("https://italygpt.it")
13
soup = BeautifulSoup(r.text, "html.parser")
14
self.next_id = soup.find("input", {"name": "next_id"})["value"]
15
16
def create(self, prompt: str, messages: list = []):
17
try:
18
r = requests.get("https://italygpt.it/question", params={"hash": sha256(self.next_id.encode()).hexdigest(), "prompt": prompt, "raw_messages": json.dumps(messages)}).json()
19
except:
20
r = requests.get("https://italygpt.it/question", params={"hash": sha256(self.next_id.encode()).hexdigest(), "prompt": prompt, "raw_messages": json.dumps(messages)}).text
21
if "too many requests" in r.lower():
22
# rate limit is 17 requests per 1 minute
23
time.sleep(20)
24
return self.create(prompt, messages)
25
self.next_id = r["next_id"]
26
self.messages = ast.literal_eval(r["raw_messages"])
27
self.answer = r["response"]
28
return self