OpenHandsを動かしてみる
Devinは試すには高いので一旦OSS版のOpenHandsを動かしてみたい
Windowsで動かしてみる。(WSL2)
スペックは次の通り
CPU:Ryzen 5950X
GPU:RTX 3080 Ti(VRAM 12GB)
メモリ:128GB
クイックスタートをやってみる。
docker pull docker.all-hands.dev/all-hands-ai/runtime:0.28-nikolaik
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.28-nikolaik \
-e LOG_ALL_EVENTS=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.openhands-state:/.openhands-state \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.28
改行されてるのをそのままターミナルに貼り付けたらダメだったので改行無くしたりした。
とりあえず起動した。
AI Provider選択画面
AnthropicのClaude 3.5 Sonnet
がオススメっぽい。
今回は費用かけたくないのでローカルで動いてるOllamaを使うことにした。
モデルは一旦適当にollama/deepseek-coder-v2-base
API Keyは何でもOK。とりあえずhogehoge
とした
Ollama側でdeepseek-coder-v2-base
をダウンロードする
ollama pull deepseek-coder-v2
deepseek-coder-v2-base
は無かったので、deepseek-coder-v2に変更
OpenHands側もdeepseek-coder-v2
に変更しておく。
Base URLには、http://host.docker.internal:11434
を設定
参考:https://bwgift.hatenadiary.jp/entry/2025/02/24/233957
動かしてみる。
トップページに「Hacker Newsのトップ記事を表示するbashスクリプトを作成する」とボタンが出てたので、そこから始めてみる。
クリックすると、以下の内容が入力された。
Please write a bash script which displays the top story on Hacker News. It should show the title, the link, and the number of points.
The script should only use tools that are widely available on unix systems, like curl and grep.
これだとやり取りが英語になりそうなので、日本語化してから実行してみる。
Hacker News のトップストーリーを表示する bash スクリプトを作成してください。
タイトル、リンク、ポイント数を表示する必要があります。
スクリプトでは、curl や grep など、Unix システムで広く利用可能なツールのみを使用する必要があります。
ワークスペース?が作られた。
で、エラーになった。
ワークスペースが作られてからちょっと時差がある。
Modelをdeepseek-coder-v2
からollama/deepseek-coder-v2
に変更。
エラー内容が変わった。
RuntimeError: There was an unexpected error while running the agent. Please report this error to the developers by opening an issue at https://github.com/All-Hands-AI/OpenHands. Your session ID is 206d631b810b4028b65d95c2fdcc8f70. Error type: APIConnectionError
OpenHands側のエラーメッセージ(一部抜粋)
Error while running the agent (session ID: 206d631b810b4028b65d95c2fdcc8f70): litellm.APIConnectionError: OllamaException - {"error":"POST predict: Post "http://127.0.0.1:52948/completion": read tcp 127.0.0.1:52952-\u003e127.0.0.1:52948: wsarecv: An existing connection was forcibly closed by the remote host."}.
Ollama側でも怪しいメッセージがあった。
The current context does not support K-shift
モデルファイルを作って、適用すれば回避できるかも?
cat > Modelfile <<EOF
FROM deepseek-coder-v2
PARAMETER num_ctx 24576
PARAMETER num_predict 8192
EOF
ollama create deepseek-coder-v2-fixed -f Modelfile
ちょっとめんどくさくなってきたので、違うモデルにする。
hhao/qwen2.5-coder-tools:32b
を使う。
よく分かってないけど、Clineで使ってる人が多いっぽい。
ollama pull hhao/qwen2.5-coder-tools:32b
OpenHands側もモデルの指定を変更しておく
ollama/deepseek-coder-v2
→ollama/hhao/qwen2.5-coder-tools:32b
どうやら出来たっぽい?
ここからどうすれば?
まだ終わってなかった。
jq使ってるけど、これ標準的なやつじゃないから違うコマンド使うように変えるって。
で、変更したファイルを作ろうと思ったら、既にファイルがあって新しいファイルが作れなかったと。
次のメッセージ。
Let's modify the existing script instead of creating a new one. We'll use the str_replace_editor tool to update the content of the existing hacker_news_top_stories.sh file.
新しく作るんじゃなくて、既存のファイルを変更しますと。
気付いたら右のワークスペースにファイル作られてた。
次
The script looks correct now. Let's make it executable and then run it to ensure it works as expected:
出来たっぽいから実行してみる。
出来てないっぽいw
次
It seems the script executed successfully, but it did not display any stories. This could be due to the grep and paste commands not correctly extracting and combining the data from the JSON responses.
Let's refine the script to ensure that the extraction and combination of title, link, and score are done correctly using sed and awk.
上手く動いていない。grepとpasteコマンドがJSONを上手く処理出来てないのが原因だと考えられるので、sedとawkを使って解消してみる。
で、再実行。
まだダメっぽい。
次
It appears that the awk command is not correctly extracting the title, link, and score from the JSON data. Let's refine the script further to ensure accurate extraction.
We'll use a more robust method to parse the JSON data using sed and awk. Here’s an updated version of the script:
まだダメだったので、改良します。
再実行
ここでタイムアップ。一旦このまま放置。
しばらく放置して出来たっぽい。
以下、完成したコード
#!/bin/bash
# Fetch the top stories from Hacker News
top_story_ids=$(curl -s https://hacker-news.firebaseio.com/v0/topstories.json | sed 's/\[//; s/\]//' | tr ',' '\n' | head -n 10)
# Initialize an empty file to store story details
> stories.txt
# Read each story ID and fetch details
for id in $top_story_ids; do
curl -s "https://hacker-news.firebaseio.com/v0/item/$id.json" >> stories.txt
done
# Extract title, link, and score from the fetched stories
echo "Title\tLink\tScore"
sed -n 's/.*"title":"\([^"]*\)".*/\1/p' stories.txt | paste -d'\t' - <(sed -n 's/.*"url":"\([^"]*\)".*/\1/p' stories.txt) <(sed -n 's/.*"score":\([0-9]*\).*/\1/p' stories.txt)
metadata.jsonが次の通り。
{"conversation_id":"c7eb39c95485447088589b23186f9c31","github_user_id":null,"selected_repository":null,"selected_branch":null,"title":"Conversation c7eb3","last_updated_at":"2025-03-17T04:46:48.904416Z","created_at":"2025-03-17T00:41:41.978469Z"}
created_at
とlast_updated_at
の差が4時間ぐらいなので、トータル4時間ぐらいで出来たことになる。
これが早いのか遅いのかは何とも言えないが…
まあ自分で書いた方が早いのは確かか…
Devinを使ってる人が「新卒エンジニアだと思って接すると良い」と言ってたけど、OpenHandsでも同じことが言えそうだなという印象。
この辺はAnthropicのClaude 3.5 Sonnet
にすると変わったりするかも?
このスクラップは一旦ここまで。
あとからOllama側のログみたので、一応補足で追加。
[GIN] 2025/03/17 - 09:44:18 | 200 | 2m13s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:47:02 | 200 | 2m43s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:50:19 | 200 | 3m16s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:50:49 | 200 | 29.7869226s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:54:48 | 200 | 3m54s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:55:14 | 200 | 25.7206331s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:59:18 | 200 | 4m0s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 09:59:44 | 200 | 25.7604711s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:04:00 | 200 | 4m12s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:04:26 | 200 | 26.1003136s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:05:43 | 200 | 1m12s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:08:51 | 200 | 3m7s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:12:14 | 200 | 3m22s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:12:51 | 200 | 37.3040513s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:15:39 | 200 | 2m47s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:18:31 | 200 | 2m52s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:19:01 | 200 | 30.2615663s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:21:53 | 200 | 2m51s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:22:24 | 200 | 30.8504223s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:25:14 | 200 | 2m50s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:25:45 | 200 | 31.3408941s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:28:36 | 200 | 2m50s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:29:07 | 200 | 31.071574s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:32:03 | 200 | 2m56s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:32:35 | 200 | 31.770142s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:33:16 | 200 | 40.6850229s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:33:58 | 200 | 42.2696123s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:34:41 | 200 | 42.4455034s | 127.0.0.1 | POST "/api/generate"
[GIN] 2025/03/17 - 10:35:22 | 200 | 41.377021s | 127.0.0.1 | POST "/api/generate"
コードを生成するのに1回2~4分ぐらいかかってそう。
さらに追記
モデルをgemma3:27b
に変更してみて実行したら。10分経っても返答が得られず。タイムアウト。
次にqwq:32b
に変更。こちらも10分経って返答が得られず。タイムアウト。
もっと良いGPUにすれば使えるようになる?
最後にPerplexityのSonar
を使ってみる。
Pro契約で5ドルまでは使えるので、それを使ってみる。
約10秒で結果が返ってきた。早いなぁ
しかも1発でこれを出してくる。偉いなぁ
#!/bin/bash
# Fetch top stories from Hacker News using Algolia API
curl -s "https://hn.algolia.com/api/v1/search?query=&tags=front_page" | grep -oE '"title":"[^"]+"|url":"[^"]+"|points":\d+'
# This will print out lines containing titles, URLs, and points, but it won't be nicely formatted.
全然違うアプローチ!
https://hn.algolia.com ってそんなのあるんだ…
ただ、ファイルは生成されていないので、それが若干気になるところ。
ちなみに費用は0.01ドル。
Algolia、jq、pupを使わないでってお願いしたら次のコードが出た。
#!/bin/bash
# Fetch top stories from Hacker News
curl -s https://news.ycombinator.com/ | grep -oE '<a href="[^"]+"[^>]*>[^<]+' | sed 's/<a href="\(.*\)"[^>]*>\(.*\)<\/a>/\2: \1/g'
さすがにHTML直接見るとは思わなかったw
めっちゃアクセスするなら考えることは色々あるけど、1回動かすだけならまあこれでも良いか?