如何让openhands始终输出中文?
在本地创建一个文件./user_prompt.j2
添加一行
Always respond in 中文
你可以直接:
echo "Always respond in 中文" > ./user_prompt.j2
使用官方文档的docker命令启动容器时-v挂载一个文件/app/openhands/agenthub/codeact_agent/prompts/user_prompt.j2
到本地./user_prompt.j2
。
例如:
-v ./user_prompt.j2:/app/openhands/agenthub/codeact_agent/prompts/user_prompt.j2 \
完整命令如下:
docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.20-nikolaik \
-e LOG_ALL_EVENTS=true \
-e WORKSPACE_MOUNT_PATH="You work dir" \
-v "You work dir":/opt/workspace_base \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./user_prompt.j2:/app/openhands/agenthub/codeact_agent/prompts/user_prompt.j2
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.20
⚠️我的这个命令添加了–rm参数,退出容器什么内容都不会保存。
⚠️当使用openhands编写代码时,应该在编写完成之后立即下载到本地或者推送到github,因为当你退出对话,内容不会保存。这和–rm参数是两回事。
⚠️我删除了官方文档存在的 -e SANDBOX_USER_ID=$(id -u) \
它是为了防止使用root权限读写你的工作目录造成你无法读取的情况,所以,它使用当前执行docker run命令的用户的权限标识例如“1000”来访问你的工作目录,但是,它有一个bug,它使用权限标识“1000”来运行它的openhands服务,导致/.openhands-state/.jwt_secret
因权限不足而无法访问,导致服务无法启动,具体报错见文末,于是我删除了该行。这会造成你无法读取的情况,此时你需要重新修改文件权限。针对类unix系统这很容易。
⚠️我添加了工作目录这一参数,如果你只是在测试,不需要工作目录,则删除以下:
-e SANDBOX_USER_ID=$(id -u) \
-e WORKSPACE_MOUNT_PATH="You work dir" \
-v "You work dir":/opt/workspace_base \
此时你再通过web界面使用它,它会返回中文回答。
If this helps you, and if you have enough money, can you give me 1$? I am facing a financial crisis.
If you do this, I will pass on the kindness.
This is my bank card number:5592921230414708
Thank you!!
文末:
likewendy@likewendy-PC:~/Desktop/openhands$ docker run -it --rm --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.20-nikolaik \
-e LOG_ALL_EVENTS=true \
-e SANDBOX_USER_ID=$(id -u) \
-e WORKSPACE_MOUNT_PATH="/home/likewendy/Desktop/optillm/yolo" \
-v /home/likewendy/Desktop/optillm/yolo:/opt/workspace_base \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ./user_prompt.j2:/app/openhands/agenthub/codeact_agent/prompts/user_prompt.j2 \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.20
0.20: Pulling from all-hands-ai/openhands
Digest: sha256:0dec9d2db2faf4675b93401df4e271e60f26a0fbebdb4375ddf9ed390a770847
Status: Image is up to date for docker.all-hands.dev/all-hands-ai/openhands:0.20
Starting OpenHands...
Setting up enduser with id 1000
Docker socket group id: 121
Creating group with id 121
Running as enduser
/app/.venv/lib/python3.12/site-packages/pydantic/_internal/_config.py:345: UserWarning: Valid config keys have changed in V2:
* 'fields' has been removed
warnings.warn(message, UserWarning)
ERROR:root: File "/app/.venv/bin/uvicorn", line 8, in <module>
sys.exit(main())
^^^^^^
File "/app/.venv/lib/python3.12/site-packages/click/core.py", line 1161, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/click/core.py", line 1082, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/click/core.py", line 1443, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/click/core.py", line 788, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/uvicorn/main.py", line 412, in main
run(
File "/app/.venv/lib/python3.12/site-packages/uvicorn/main.py", line 579, in run
server.run()
File "/app/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 66, in run
return asyncio.run(self.serve(sockets=sockets))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 194, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 70, in serve
await self._serve(sockets)
File "/app/.venv/lib/python3.12/site-packages/uvicorn/server.py", line 77, in _serve
config.load()
File "/app/.venv/lib/python3.12/site-packages/uvicorn/config.py", line 435, in load
self.loaded_app = import_from_string(self.app)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/uvicorn/importer.py", line 19, in import_from_string
module = importlib.import_module(module_str)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/app/openhands/server/listen.py", line 3, in <module>
from openhands.server.app import app as base_app
File "/app/openhands/server/app.py", line 12, in <module>
from openhands.server.middleware import (
File "/app/openhands/server/middleware.py", line 13, in <module>
from openhands.server.shared import session_manager
File "/app/openhands/server/shared.py", line 13, in <module>
config = load_app_config()
^^^^^^^^^^^^^^^^^
File "/app/openhands/core/config/utils.py", line 447, in load_app_config
finalize_config(config)
File "/app/openhands/core/config/utils.py", line 250, in finalize_config
cfg.jwt_secret = get_or_create_jwt_secret(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/openhands/core/config/utils.py", line 217, in get_or_create_jwt_secret
file_store.write(JWT_SECRET, new_secret)
File "/app/openhands/storage/local.py", line 24, in write
with open(full_path, mode) as f:
^^^^^^^^^^^^^^^^^^^^^
ERROR:root:<class 'PermissionError'>: [Errno 13] Permission denied: '/.openhands-state/.jwt_secret'
原文地址:https://blog.csdn.net/Deng_Xian_Sheng/article/details/145268395
免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!