🦆

chatdevを触ってみる(失敗中)

2025/02/16に公開

なぜ作成したのか

  • 開発から遠く離れた立場になったので、今どきの開発ってどんな感じなんだろ、と開発をシム的に俯瞰してみたくなった
  • 読んでみたら触ってみたくなった

件の論文

https://arxiv.org/abs/2307.07924

参考

https://qiita.com/sypn/items/8cf341c353cba73d8d7c
https://qiita.com/taiwa_tky/items/4ab7962f6e7354824cae

環境構築

PCスペック

  • Microsoft Surface Laptop, 7th Edition
  • Windows 11 Home
  • python 3.11.5
  • git version 2.47.1.windows.1

リポジトリのクローン

$ git clone https://github.com/OpenBMB/ChatDev.git

依存ライブラリのインストール

$ pip install -r requirements.txt

環境変数にOpenAI API キーを設定

$ $env:OPENAI_API_KEY="your_OpenAI_API_key"

発注指示

プロンプトでアプリの生成を発注

  • description_of_your_idea:
    • 作成してほしいアプリのアイデアを英語で指示
  • project_name:
    • 作成したいアプリの名称を英語で指定
$ python run.py --task "[description_of_your_idea]" --name "[project_name]"

発注失敗!(TypeError: Client.init() got an unexpected keyword argument 'proxies')

参考

https://community.openai.com/t/error-with-openai-1-56-0-client-init-got-an-unexpected-keyword-argument-proxies/1040332

原因

  • httpx の 0.28 廃止予定のキーワード 「proxies」を使用しているため

対策

  • httpxのバージョンを 0.27.2 にダウングレードする
$ pip install httpx==0.27.2 

発注失敗!(tenacity.RetryError: RetryError[<Future at 0x251f95cb310 state=finished raised RateLimitError>])

openai.RateLimitError: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}}

参考

https://github.com/OpenBMB/ChatDev/issues/26
https://qiita.com/motito/items/491f7021ad6a5aa8762a

原因

  • ChatDevが内部で利用しているライブラリCamelの問題

対処

  • ソースコードのCamel側のコードを修正する

camel/model_backend.py

  • Import文の追加
  from tenacity import retry, wait_exponential
  • OpenAIModelクラスのクラスメソッドに、デコレータの追加
class OpenAIModel(ModelBackend):
    r"""OpenAI API in a unified ModelBackend interface."""

    @retry(wait=wait_exponential(multiplier=1, min=4, max=10))        
    def run(self, *args, **kwargs) -> Dict[str, Any]:

camel/agents/role_playing.py

  • Import文の追加
  from tenacity import retry, wait_exponential
  • 「def step」の上に、デコレータの追加
    @retry(wait=wait_exponential(multiplier=60, max=100))
    def step(
            self,
            user_msg: ChatMessage,
            assistant_only: bool,
    ) -> Tuple[ChatAgentResponse, ChatAgentResponse]:


処理は通ったように見えるが失敗は続く()

model指定なしの場合(3.5)

HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 429 Too Many Requests"
  • exponential backoff が効いてない?

model "GPT_4"指定の場合

HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 404 Not Found"

ちょっと原因わからないので棚上げ

サンプルのログをリプレイして遊ぶ

生成がうまくいかないので、サンプルで動作をのぞいてみることにする。
WereHouseフォルダ配下には、サンプルアプリフォルダがたくさん格納されている。
このフォルダには生成時のログも含まれているので、このログをリプレイしてみる。

Viewerを起動する

$ python .\visualizer\app.py
Please visit http://127.0.0.1:8000/ for the front-end display page.
In the event of a port conflict, please modify the port argument (e.g., python3 app.py --port 8012).
 * Serving Flask app 'app'
 * Debug mode: off

ブラウザで「http://127.0.0.1:8000/」にアクセスする

「Replay Visualizer」をクリックしてViewerを起動する

「File Upload」からログファイルをアップロードし、「Replay」をクリックする


エージェント間のチャットや生成物の生成状況が再生される

所感

  • OpenAIのAPIとして3.5Turbo、4oも提供されてるはずだから、多分APIの呼び出し自体がうまくいっていない感。
  • 別途他のAPIツールでKey、呼び出しの機能検証して別日にリトライする。
GitHubで編集を提案

Discussion