PyChatGPT - ⚡️ 自動トークン再生成、会話追跡、プロキシサポートなどを備えた非公式のChatGPT API用のPythonクライアント。

(⚡️ Python client for the unofficial ChatGPT API with auto token regeneration, conversation tracking, proxy support and more.)

Created at: 2022-12-05 17:41:51
Language: Python
License: MIT

🔥PyChatGPT

ニシキヘビ ピパイ ピパイ

⭐️このリポジトリが好きですか?スター&それを維持するために寄付を検討してください

コーヒーを買って

💡OpenAIがAPIを変更した場合、できるだけ早く修正しますので、通知を受け取りたい場合はリポジトリを見てください

顔立ち

  • [x]会話をファイルに保存する
  • [x]プログラムを終了した後でも会話を再開する
  • [x] プロキシのサポート
  • [x] ブラウザを介さずに自動的にログイン
  • [x]アクセストークンを自動的に取得する
  • [x]ログインキャプチャを回避します(後でログインしようとすると、キャプチャを解決するように求められます)
  • [x]アクセストークンをファイルに保存するので、再度ログインする必要はありません
  • [x]有効期限が切れるとアクセストークンを自動的に更新します
  • [x]コロラマを使用して出力を色付けします。
  • [x]スマート会話追跡

ウェブデモ

グラジオを使用してハギングフェイススペース🤗に統合されました。ウェブデモを試す

ハグフェイススペース

雑談

スクリーンショット1

トークンの作成

スクリーンショット 2

You: Hi there, My name is Rawa
Chat GPT: Hello Rawa, nice to meet you. Is there something you would like to talk about or ask me? I'm here to help with any questions you may have.
You: great, now say my name like Heisenberg
Chat GPT: Sure, Rawa like Heisenberg. Is there anything else you would like to talk about? I'm here to help with any questions you may have.
You: Sorry I meant like the episode of Breaking Bad where Walter White says Heisenberg
Chat GPT: Ah, I see. In that case, you could try saying it like this: "My name is Rawa, like Heisenberg." This is a reference to the character Walter White from the TV show Breaking Bad, who often used the pseudonym "Heisenberg" when conducting illegal activities. The character was known for his cool and calculated demeanor, so saying your name like Heisenberg in this context would mean saying it with confidence and authority.

取り付ける

pip install chatgptpy --upgrade

使い

[ニュー]オブジェクトをコンストラクターに渡してセッションをカスタマイズする

options()
ChatGPT()

[ニュー]会話をファイルに保存できるようになりました

from pychatgpt import Chat, Options

options = Options()

# [New] Enable, Disable logs
options.logs = True

# Track conversation
options.track = True 

# Use a proxy
options.proxies = 'http://localhost:8080'

# Optionally, you can pass a file path to save the conversation
# They're created if they don't exist

# options.chat_log = "chat_log.txt"
# options.id_log = "id_log.txt"

# Create a Chat object
chat = Chat(email="email", password="password", options=options)
answer = chat.ask("How are you?")
print(answer)

[ニュー]会話を再開する

from pychatgpt import Chat

# Create a Chat object
chat = Chat(email="email", password="password", 
            conversation_id="Parent Conversation ID", 
            previous_convo_id="Previous Conversation ID")

answer, parent_conversation_id, conversation_id = chat.ask("How are you?")

print(answer)

# Or change the conversation id later
answer, _, _ = chat.ask("How are you?", 
                        previous_convo_id="Parent Conversation ID",
                        conversation_id="Previous Conversation ID")
print(answer)

CLI セッションの開始

from pychatgpt import Chat

chat = Chat(email="email", password="password")
chat.cli_chat()

1 回限りの質問をする

from pychatgpt import Chat

# Initializing the chat class will automatically log you in, check access_tokens
chat = Chat(email="email", password="password") 
answer, parent_conversation_id, conversation_id = chat.ask("Hello!")

手動で設定してトークンを取得することもできます

import time
from pychatgpt import OpenAI

# Manually set the token
OpenAI.Auth(email_address="email", password="password").save_access_token(access_token="", expiry=time.time() + 3600)

# Get the token, expiry
access_token, expiry = OpenAI.get_access_token()

# Check if the token is valid
is_expired = OpenAI.token_expired() # Returns True or False
変更ログ

次を使用して更新
pip install chatgptpy --upgrade

1.0.6

  • ログをオフにする新しいオプション。
  • エラー処理の改善。
  • 会話追跡の強化
  • 今すぐ尋ねる のタプルを返します
    answer, previous_convo, convo_id
  • より良いドキュメント

1.0.5

  • プルリクエスト/マイナー修正

1.0.4

  • トークン認証のパート 8 の修正

1.0.3

  • チャットセッションのオプションを設定するための新しいクラスメソッド
    options()
  • スレッドをファイルに保存する
  • プログラムを閉じた後も会話を再開します

1.0.2

  • ChatGPT API は から に頻繁に切り替わります。このライブラリは現在、API から次の応答を取得する代わりに使用しています。
    action=next
    action=variant
    action=variant
    action=next
  • サーバーが過負荷になると、APIがエラーを返すことがあります。
    502 Bad Gateway
  • auth.json ファイルが見つからない/破損している場合のエラー処理を追加

1.0.0

  • PyPi 経由の初期リリース

その他情報

トークン作成プロセスが失敗した場合:

  1. プロキシを使用してみてください(常にこれを使用することをお勧めします)
  2. ログインが速すぎないようにしてください。レートが制限されている場合は、少なくとも10分待ちます。
  3. それでも問題が解決しない場合は、VPNを使用してみてください。VPNでは、スクリプトは正常に動作するはずです。

次は何ですか?

次のようないくつかの機能を追加する予定です。

  • [x] インポートして他のプロジェクトで使用できる Python モジュール
  • [x]会話を保存する方法
  • [ ] エラー処理の向上
  • [ ] マルチユーザー・チャット

プロセス全体

私は新しいチャットGPT APIと対話する方法を探していましたが、ここGitHubのほとんどのソースは Chromiumインスタンスをバックグラウンドで実行する必要があります。または、Web インスペクターを使用してアクセス トークンを手動で取得します。

これ以上はない。APIをリバースエンジニアリングし、TLSクライアントを使用して実際のユーザーを模倣し、Auth0によるボット検出手法をオフにせずにスクリプトがログインできるようにしました。

基本的に、スクリプトはTLSクライアントを使用してユーザーに代わってログインし、アクセストークンを取得します。それはかなり速いです。

まず、「httpリクエストを作成するだけでは十分ではなく、Auth0はスマートで、各プロセスはJWTトークンであるトークンによって保護されています。このトークンは、CSRF攻撃を防ぐために使用され、ボットがログインするのを防ぐためにも使用されます。 ファイルを見ると、9つ以上の関数があり、それぞれが異なるタスクを担当しており、それらはすべて 協力してトークンを作成します。 ログインプロセスをナビゲートできるため、これには大きな役割を果たしました

state
auth.py
allow-redirects

私は MeshMonitors.io で働いています、私たちは素晴らしいツールを作ります(それをチェックしてください!私はこれにあまり時間をかけないことに決めましたが、ここにいます。

なぜ私はこれをしたのですか?

誰もこれを行うことができなかったので、私は私ができるかどうかを見たかったのです。

クレジット