OpenHands:OpenDevin的升级版,由人工智能驱动的软件开发代理平台
官网:https://github.com/All-Hands-AI/OpenHands
欢迎来到OpenHands(前身为OpenDevin),这是一个由人工智能驱动的软件开发代理平台。
OpenHands代理可以做任何人类开发人员可以做的事情:修改代码、运行命令、浏览网页、调用API,是的,甚至可以从StackOverflow复制代码片段。
实践
Windows10 WSL Ubuntu24.04下尝试(失败)
OpenHands需要用docker安装
比如在Windows10的wsl Ubuntu24.04系统下,直接执行下面两句:
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
启动后在3000端口侦听
You'll find OpenHands running at http://localhost:3000
浏览器打开3000端口
首先进行大模型的设置
设置服务提供方 ,选定模型,输入key 。但是这还不够,因为我们想使用定制的llm大模型提供方,比如本地提供方。那么可以点击“see advanced settings” ,再打开Advanced开关,就可以自己定义大模型了,比如模型名字:gtp-4o,模型url选自己假设的服务192.168.1.5就可以,API key自己设定:
设定好后, 点击新项目,用官方给的prompt开始破冰之旅:
I want to create a Hello World app in Javascript that:
* Displays Hello World in the middle.
* Has a button that when clicked, changes the greeting with a bouncing animation to fun versions of Hello.
* Has a counter for how many times the button has been clicked.
* Has another button that changes the app's background color.
后面是漫长的等待时间。一直就没信息,这不对啊。而且设定为中文,但是界面并没有改,就像设定没有起作用一样。
windows10下试试(失败)
在windows10的powershell下,直接执行:
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 C:\Users\Admin\.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
然后浏览器连到本地3000端口,也是一样,页面显示Connecting,但是就是没啥反应
测试openai api
测试本地搭建的openai api ,测试通过
import openai
client = openai.OpenAI(
api_key="anything",
base_url="http://192.168.1.5:1337/v1"
)
# request sent to model set on litellm proxy, `litellm --model`
response = client.chat.completions.create(model="gpt-4o", messages = [
{
"role": "user",
"content": "this is a test request, write a short poem"
}
])
print(response)
所以到底哪里出错了呢?没找到原因,但是肯定跟科学上网有关。
总结
一句话,OpenHands很好!
第二句话:没法用,问就是科学上网的锅。
调试
agent卡住,控制台报错ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=39992)
File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 475, in __call__
do = self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 376, in iter
result = action(retry_state)
^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 398, in <lambda>
self._add_action_func(lambda rs: rs.outcome.result())
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/app/.venv/lib/python3.12/site-packages/tenacity/__init__.py", line 478, in __call__
result = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/app/openhands/runtime/utils/request.py", line 44, in send_request
response = session.request(method, url, timeout=timeout, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/requests/adapters.py", line 700, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='host.docker.internal', port=39992): Max retries exceeded with url: /alive (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f894c95eba0>: Failed to establish a new connection: [Errno 111] Connection refused'))
感觉是命令里的这句话有问题:
--add-host host.docker.internal:host-gateway
去掉试试
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 \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.28
去掉之后有这句
10:53:54 - openhands:INFO: docker_runtime.py:155 - [runtime 10e429aad4564baea20a8ebcc602fe40] Waiting for client to become ready at http://host.docker.internal:39992...
好像还是一样啊
要不改成这句:
--add-host h172.25.176.1:host-gateway
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 \
--add-host 172.25.176.1:host-gateway \
-p 3000:3000 \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.28
看这个issue:[Bug]: Release using docker images 0.28 doesn't start, fails with exception of incorrect message · Issue #7152 · All-Hands-AI/OpenHands
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 \
-e SANDBOX_RUNTIME_BINDING_ADDRESS="0.0.0.0" \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.28
试试
发现无法修改配置了
而且很...很卡,就是ctrl+c后半天docker都不退出,整个wsl Ubuntu都卡住了。
后来用另一个终端把它kill了。
windows下的docker也是一样网页端卡住,docker端有报错
File "/app/openhands/server/middleware.py", line 203, in __call__
return await call_next(request)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 154, in call_next
raise app_exc
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 141, in coro
await self.app(scope, receive_or_disconnect, send_no_error)
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 177, in __call__
with recv_stream, send_stream, collapse_excgroups():
File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "/app/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 82, in collapse_excgroups
raise exc
File "/app/.venv/lib/python3.12/site-packages/starlette/middleware/base.py", line 179, in __call__
response = await self.dispatch_func(request, call_next)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/openhands/server/middleware.py", line 172, in __call__
response = await self._attach_conversation(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/openhands/server/middleware.py", line 151, in _attach_conversation
await shared.conversation_manager.attach_to_conversation(request.state.sid)
File "/app/openhands/server/conversation_manager/standalone_conversation_manager.py", line 91, in attach_to_conversation
c = Conversation(sid, file_store=self.file_store, config=self.config)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/openhands/server/session/conversation.py", line 34, in __init__
self.runtime = runtime_cls(
^^^^^^^^^^^^
File "/app/openhands/runtime/impl/docker/docker_runtime.py", line 80, in __init__
self.docker_client: docker.DockerClient = self._init_docker_client()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/openhands/runtime/impl/docker/docker_runtime.py", line 183, in _init_docker_client
raise ex
File "/app/openhands/runtime/impl/docker/docker_runtime.py", line 178, in _init_docker_client
return docker.from_env()
^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/docker/client.py", line 94, in from_env
return cls(
^^^^
File "/app/.venv/lib/python3.12/site-packages/docker/client.py", line 45, in __init__
self.api = APIClient(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 207, in __init__
self._version = self._retrieve_server_version()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/docker/api/client.py", line 230, in _retrieve_server_version
raise DockerException(
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))