chatgpt-api-0.2.1
توضیحات
ChatGPT HTTP API Client and CLI
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | chatgpt-api-0.2.1 |
| نام | chatgpt-api |
| نسخه کتابخانه | 0.2.1 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Michal Broton |
| ایمیل نویسنده | michal@broton.dev |
| آدرس صفحه اصلی | https://github.com/mbroton/chatgpt-api |
| آدرس اینترنتی | https://pypi.org/project/chatgpt-api/ |
| مجوز | - |
<h1 align="center">💻 ChatGPT API</h1>
<p align="center">Unofficial API client and CLI for ChatGPT.</p>
<p align="center">
<img alt="PyPI" src="https://img.shields.io/pypi/v/chatgpt-api">
<img alt="License" src="https://img.shields.io/github/license/mbroton/chatgpt-api">
<img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-green">
</p>
<br>

<br>
This project is based on `httpx` (uses only HTTP) and uses [Typer (with Rich)](https://typer.tiangolo.com/) for CLI, so responses are looking good (markdown is supported). Also, It has 100% code coverage unlike other ChatGPT packages.

## Status
ChatGPT API often changes. I'm trying to make updates as soon as possible. So, if something is not working properly and you recently didn't upgrade `chatgpt-api`, try to do this first:
```sh
pip install --upgrade chatgpt-api
```
If that doesn't help, please open an issue.
## Installation
```
pip install chatgpt-api
```
## Usage
### As a Command Line Interface
#### Setup
Required to authenticate. In this step you have to provide session key.
```sh
chatgpt setup
```
#### Start chatting
```sh
chatgpt start
```
### As an API
`ChatGPT` class inherits from `httpx.Client`
Recommended usage:
```python
from chatgpt.api import ChatGPT
with ChatGPT(session_token="your-session-token") as chat:
response = chat.send_message("Hello!")
print(response.content)
```
Without context manager you have to explicitly authenticate:
```python
from chatgpt.api import ChatGPT
chat = ChatGPT(session_token="your-session-token")
chat.authenticate()
response = chat.send_message("Hello!")
print(response.content)
chat.close()
```
## How to acquire session key?
After you log in to ChatGPT in your browser, get value of `__Secure-next-auth.session-token` cookie. In this project, this is named as a "session key".
### Chrome instruction
1. Open ChromeDevTools (F12).
2. Click on "Application" tab.
3. Click on "Cookies", on the left bar.
4. Copy the value of `__Secure-next-auth.session-token`:

Now, you can use it in CLI or directly from Python code.
## License
Distributed under the MIT License. See `LICENSE` for more information.
## Disclaimer
This is a personal project, not affiliated in any way with OpenAI. If you have any objections, please contact me.
نیازمندی
| مقدار | نام |
|---|---|
| ==0.23.1 | httpx |
| ==0.7.0 | typer[all] |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.7 | Python |
نحوه نصب
نصب پکیج whl chatgpt-api-0.2.1:
pip install chatgpt-api-0.2.1.whl
نصب پکیج tar.gz chatgpt-api-0.2.1:
pip install chatgpt-api-0.2.1.tar.gz