{"id":13593851,"url":"https://github.com/terry3041/pyChatGPT","last_synced_at":"2025-04-09T05:32:24.415Z","repository":{"id":64311328,"uuid":"574849909","full_name":"terry3041/pyChatGPT","owner":"terry3041","description":"An unofficial Python wrapper for OpenAI's ChatGPT API","archived":true,"fork":false,"pushed_at":"2023-12-07T04:08:38.000Z","size":104,"stargazers_count":1350,"open_issues_count":59,"forks_count":256,"subscribers_count":22,"default_branch":"main","last_synced_at":"2025-01-18T19:36:34.654Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/terry3041.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-12-06T07:57:49.000Z","updated_at":"2025-01-17T22:44:36.000Z","dependencies_parsed_at":"2023-12-07T05:24:38.737Z","dependency_job_id":"ba80bcee-15f1-4bda-9fad-fd49ff7c7a69","html_url":"https://github.com/terry3041/pyChatGPT","commit_stats":{"total_commits":138,"total_committers":10,"mean_commits":13.8,"dds":"0.23188405797101452","last_synced_commit":"47f18eecf3ef3cf4ba08493f243cba8d4ded7d88"},"previous_names":[],"tags_count":44,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terry3041%2FpyChatGPT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terry3041%2FpyChatGPT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terry3041%2FpyChatGPT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/terry3041%2FpyChatGPT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/terry3041","download_url":"https://codeload.github.com/terry3041/pyChatGPT/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247986974,"owners_count":21028890,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:25.439Z","updated_at":"2025-04-09T05:32:24.067Z","avatar_url":"https://github.com/terry3041.png","language":"Python","funding_links":[],"categories":["Python","A01_文本生成_文本对话","ChatGPT API"],"sub_categories":["大语言对话模型及数据"],"readme":"# pyChatGPT\n\n[![PyPi](https://img.shields.io/pypi/v/pyChatGPT.svg)](https://pypi.python.org/pypi/pyChatGPT)\n[![License](https://img.shields.io/github/license/terry3041/pyChatGPT.svg?color=green)](https://github.com/terry3041/pyChatGPT/blob/main/LICENSE)\n![PyPi](https://img.shields.io/badge/code_style-black+flake8-blue.svg)\n\n\u003e I stopped maintaining this project as ChatGPT now has an official API. See [OpenAI API](https://beta.openai.com/docs/api-reference/introduction) for more details. Feel free to fork this project if you want to continue development.\n\nAn unofficial Python wrapper for OpenAI's ChatGPT API\n\n## Features\n\n-   [x] Cloudflare's anti-bot protection bypass using `undetected_chromedriver`\n-   [x] OpenAI / Google / Microsoft login support (experimental)\n-   [x] Captcha solvers support (2Captcha, PyPasser)\n-   [x] [Headless machines support](#how-do-i-get-it-to-work-on-headless-linux-server)\n-   [x] Proxy support (only without basic auth)\n\n## Getting Started\n\n\u003e Since version 0.3.0, this library is using only the `undetected_chromedriver` to bypass Cloudflare's anti-bot protection. `requests` module is no longer used due to the complexity of the protection. **Please make sure you have [Google Chrome](https://www.google.com/chrome/) / [Chromium](https://www.chromium.org/) before using this wrapper.**\n\n### Installation\n\n```bash\npip install -U pyChatGPT\n```\n\n### Usage\n\n#### Obtaining session_token\n\n1. Go to https://chat.openai.com/chat and open the developer tools by `F12`.\n2. Find the `__Secure-next-auth.session-token` cookie in `Application` \u003e `Storage` \u003e `Cookies` \u003e `https://chat.openai.com`.\n3. Copy the value in the `Cookie Value` field.\n\n![image](https://user-images.githubusercontent.com/19218518/206170122-61fbe94f-4b0c-4782-a344-e26ac0d4e2a7.png)\n\n#### Interactive mode\n\n```bash\npython3 -m pyChatGPT\n```\n\n#### Import as a module\n\n```python\nfrom pyChatGPT import ChatGPT\n\nsession_token = 'abc123'  # `__Secure-next-auth.session-token` cookie from https://chat.openai.com/chat\napi = ChatGPT(session_token)  # auth with session token\napi = ChatGPT(session_token, conversation_id='some-random-uuid')  # specify conversation id\napi = ChatGPT(session_token, proxy='https://proxy.example.com:8080')  # specify proxy\napi = ChatGPT(session_token, chrome_args=['--window-size=1920,768'])  # specify chrome args\napi = ChatGPT(session_token, moderation=False)  # disable moderation\napi = ChatGPT(session_token, verbose=True)  # verbose mode (print debug messages)\n\n# auth with google login\napi = ChatGPT(auth_type='google', email='example@gmail.com', password='password')\n# auth with microsoft login\napi = ChatGPT(auth_type='microsoft', email='example@gmail.com', password='password')\n# auth with openai login (captcha solving using speech-to-text engine)\napi = ChatGPT(auth_type='openai', email='example@gmail.com', password='password')\n# auth with openai login (manual captcha solving)\napi = ChatGPT(\n    auth_type='openai', captcha_solver=None,\n    email='example@gmail.com', password='password'\n)\n# auth with openai login (2captcha for captcha solving)\napi = ChatGPT(\n    auth_type='openai', captcha_solver='2captcha', solver_apikey='abc',\n    email='example@gmail.com', password='password'\n)\n# reuse cookies generated by successful login before login,\n# if `login_cookies_path` does not exist, it will process logining  with `auth_type`, and save cookies to `login_cookies_path`\n# only works when `auth_type` is `openai` or `google`\napi = ChatGPT(auth_type='openai', email='example@xxx.com', password='password',\n    login_cookies_path='your_cookies_path',\n)\n\nresp = api.send_message('Hello, world!')\nprint(resp['message'])\n\napi.reset_conversation()  # reset the conversation\napi.clear_conversations()  # clear all conversations\napi.refresh_chat_page()  # refresh the chat page\n```\n\n## Frequently Asked Questions\n\n### How do I get it to work on headless linux server?\n\n```bash\n# install chromium \u0026 X virtual framebuffer\nsudo apt install chromium-browser xvfb\n\n# start your script\npython3 your_script.py\n```\n\n### How do I get it to work on Google Colab?\n\nIt is normal for the seession to crash when installing dependencies. Just ignore the error and run your script.\n\n```python\n# install dependencies\n!apt install chromium-browser xvfb\n!pip install -U selenium_profiles pyChatGPT\n\n# install chromedriver\nfrom selenium_profiles.utils.installer import install_chromedriver\ninstall_chromedriver()\n```\n\n```python\n# start your script as normal\n!python3 -m pyChatGPT\n```\n\n## Insipration\n\nThis project is inspired by\n\n-   [ChatGPT](https://github.com/acheong08/ChatGPT)\n-   [chatgpt-api](https://github.com/transitive-bullshit/chatgpt-api)\n\n## Disclaimer\n\nThis project is not affiliated with OpenAI in any way. Use at your own risk. I am not responsible for any damage caused by this project. Please read the [OpenAI Terms of Service](https://beta.openai.com/terms) before using this project.\n\n## License\n\nThis project is licensed under the GPLv3 License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterry3041%2FpyChatGPT","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fterry3041%2FpyChatGPT","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fterry3041%2FpyChatGPT/lists"}