webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

Pythonで使えるHuggingChat API非公式ライブラリのインストール

カテゴリ: Python【初歩から現場実務的なもの】

Pythonで使えるHuggingChat API非公式ライブラリ「HuggingChat Python API」のインストールについて解説しています。

「HugChat(https://github.com/Soulter/hugging-chat-api)」は、Hugging Faceの公式ライブラリではなく個人のプロジェクトとなっています。なお、AIが生成したテキストは偏り、誤りが含まれる情報となっている可能性があります。さらにAPIリクエストは過度に利用することは推奨していない。またモデル作成者と会話した内容は共有されることをご理解ください。

■今回の環境(Python)

今回のPythonは、バージョン3.10.11を用いる。(なお、Google Colaboratory(Google Colab)を使用。)

■Google Colabでノートブックの新規作成

まずは、Google Colab(https://colab.research.google.com/)にアクセスします。アクセス後、お持ちのGoogleアカウントでログインされているか確認しておきましょう。

確認後、Google Colab上部の「ファイル」から「ノートブックを新規作成」をクリックします。

クリックすると「ノートブック」が作成されます。

■HugChatをインストールする

HugChatをインストールを行いますが、今回はpipを経由してインストールを行うので、ノートブックのコードセルにコードを記述します。

! pip install hugchat

上記のコマンドを入力し、実行ボタンをクリックします。

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/

Collecting hugchat

Downloading hugchat-0.0.7-py3-none-any.whl (21 kB)

Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from hugchat) (2.27.1)

Collecting requests-toolbelt (from hugchat)

Downloading requests_toolbelt-1.0.0-py2.py3-none-any.whl (54 kB)

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.5/54.5 kB 5.4 MB/s eta 0:00:00

Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->hugchat) (1.26.15)

Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->hugchat) (2022.12.7)

Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from requests->hugchat) (2.0.12)

Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->hugchat) (3.4)

Installing collected packages: requests-toolbelt, hugchat

Successfully installed hugchat-0.0.7 requests-toolbelt-1.0.0

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、正常にインストールされたことになります。なお、今回はhugchatのバージョン0.0.7をインストールしました。