Skip to content

Commit

Permalink
add italygpt.it
Browse files Browse the repository at this point in the history
  • Loading branch information
HexyeDEV authored May 1, 2023
1 parent 2ae26bf commit 611a565
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Just API's from some language model sites.
| [bard.google.com](https://bard.google.com) | custom / search |
| [bing.com/chat](https://bing.com/chat) | GPT-4/3.5 |
| [chat.forefront.ai/](https://chat.forefront.ai/) | GPT-4/3.5 |
| [italygpt.it](https://italygpt.it) | GPT-3.5 |

## Best sites <a name="best-sites"></a>

Expand Down
18 changes: 18 additions & 0 deletions gpt4free/italygpt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Example: `italygpt`

```python
# create an instance
from gpt4free import italygpt
italygpt = italygpt.Completion()

# initialize api
italygpt.init()

# get an answer
italygpt.create(prompt="What is the meaning of life?")
print(italygpt.answer) # html formatted

# keep the old conversation
italygpt.create(prompt="Are you a human?", messages=italygpt.messages)
print(italygpt.answer)
```
28 changes: 28 additions & 0 deletions gpt4free/italygpt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import requests, time, ast, json
from bs4 import BeautifulSoup
from hashlib import sha256

class Completion:
# answer is returned with html formatting
next_id = None
messages = []
answer = None

def init(self):
r = requests.get("https://italygpt.it")
soup = BeautifulSoup(r.text, "html.parser")
self.next_id = soup.find("input", {"name": "next_id"})["value"]

def create(self, prompt: str, messages: list = []):
try:
r = requests.get("https://italygpt.it/question", params={"hash": sha256(self.next_id.encode()).hexdigest(), "prompt": prompt, "raw_messages": json.dumps(messages)}).json()
except:
r = requests.get("https://italygpt.it/question", params={"hash": sha256(self.next_id.encode()).hexdigest(), "prompt": prompt, "raw_messages": json.dumps(messages)}).text
if "too many requests" in r.lower():
# rate limit is 17 requests per 1 minute
time.sleep(20)
return self.create(prompt, messages)
self.next_id = r["next_id"]
self.messages = ast.literal_eval(r["raw_messages"])
self.answer = r["response"]
return self

0 comments on commit 611a565

Please sign in to comment.