如何使 OpenHands(在 macOS 上的 Docker 上运行)与 AWS Bedrock 配合使用?

问题描述 投票:0回答:1

我正在使用 Docker 在 macOS 上通过 AWS Bedrock 设置 OpenHands,但遇到与 Docker 客户端和服务器 API 版本相关的连接问题。虽然容器内的某些命令有效,但主应用程序失败并出现以下错误:

Docker运行命令:

docker run -it --pull=always \
        -e SANDBOX_RUNTIME_CONTAINER_IMAGE="docker.all-hands.dev/all-hands-ai/runtime:0.12-nikolaik" \
        -e AWS_ACCESS_KEY_ID="YOUR_ACCESS_KEY_ID" \
        -e AWS_SECRET_ACCESS_KEY="YOUR_SECRET_ACCESS_KEY" \
        -e AWS_REGION="us-east-1" \
        -e LLM_PROVIDER="bedrock" \
        -e MODEL_ID="anthropic.claude-v2" \
        -e BASE_URL="https://bedrock.us-east-1.amazonaws.com" \
        -p 3000:3000 \
        --add-host=host.docker.internal:host-gateway \
        --name openhands-app-bedrock \
        docker.all-hands.dev/all-hands-ai/openhands:latest

在容器内成功运行命令:

docker exec -it openhands-app-bedrock /bin/bash
和里面
ipython
:

from litellm import completion
response = completion(model="anthropic.claude-v2", messages=[{"role": "user", "content": "Hello, how are you?"}])
print(response.choices[0].message.content)
# Output: I'm doing well, thanks for asking!

错误详细信息:

Starting OpenHands...
Running OpenHands as root
INFO:     Started server process [9]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit)
INFO:     192.168.65.1:57134 - "GET / HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /locales/en/translation.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /favicon.ico HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57135 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57135 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57135 - "GET /favicon.ico HTTP/1.1" 200 OK
18:19:26 - openhands:INFO: github.py:14 - Initializing UserVerifier
18:19:26 - openhands:INFO: github.py:27 - GITHUB_USER_LIST_FILE not configured
18:19:26 - openhands:INFO: github.py:48 - GITHUB_USERS_SHEET_ID not configured
18:19:26 - openhands:INFO: github.py:85 - No user verification sources configured - allowing all users
INFO:     ('192.168.65.1', 57136) - "WebSocket /ws" [accepted]
18:19:26 - openhands:ERROR: auth.py:27 - Invalid token
INFO:     192.168.65.1:57135 - "GET /api/options/models HTTP/1.1" 200 OK
INFO:     connection open
INFO:     192.168.65.1:57134 - "GET /api/options/agents HTTP/1.1" 200 OK
INFO:     192.168.65.1:57137 - "GET /api/options/security-analyzers HTTP/1.1" 200 OK
INFO:     connection closed
INFO:     192.168.65.1:57137 - "GET /assets/end-session-CpBsKLW_.js HTTP/1.1" 200 OK
INFO:     192.168.65.1:57137 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /favicon.ico HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57134 - "GET /favicon.ico HTTP/1.1" 200 OK
18:19:28 - openhands:INFO: github.py:14 - Initializing UserVerifier
18:19:28 - openhands:INFO: github.py:27 - GITHUB_USER_LIST_FILE not configured
18:19:28 - openhands:INFO: github.py:48 - GITHUB_USERS_SHEET_ID not configured
18:19:28 - openhands:INFO: github.py:85 - No user verification sources configured - allowing all users
INFO:     ('192.168.65.1', 57138) - "WebSocket /ws" [accepted]
18:19:28 - openhands:INFO: listen.py:336 - New session: aee02a3d-97c4-4c23-9df5-61094a47a0bf
INFO:     connection open
18:19:28 - openhands:WARNING: codeact_agent.py:101 - Function calling not supported for model anthropic.claude-v2. Disabling function calling.
INFO:     192.168.65.1:57134 - "GET /config.json HTTP/1.1" 200 OK
18:19:28 - openhands:INFO: base.py:98 - [runtime aee02a3d-97c4-4c23-9df5-61094a47a0bf] Starting runtime with image: docker.all-hands.dev/all-hands-ai/runtime:0.12-nikolaik
18:19:28 - openhands:INFO: base.py:98 - [runtime aee02a3d-97c4-4c23-9df5-61094a47a0bf] Container started: openhands-runtime-aee02a3d-97c4-4c23-9df5-61094a47a0bf
18:19:28 - openhands:INFO: base.py:98 - [runtime aee02a3d-97c4-4c23-9df5-61094a47a0bf] Waiting for client to become ready at http://host.docker.internal:36410...
18:19:42 - openhands:INFO: base.py:98 - [runtime aee02a3d-97c4-4c23-9df5-61094a47a0bf] Runtime is ready.
18:19:42 - openhands:WARNING: state.py:118 - Failed to restore state from session: sessions/aee02a3d-97c4-4c23-9df5-61094a47a0bf/agent_state.pkl
18:19:42 - openhands:INFO: agent_controller.py:135 - [Agent Controller aee02a3d-97c4-4c23-9df5-61094a47a0bf] Starting step loop...
18:19:42 - openhands:INFO: agent_controller.py:135 - [Agent Controller aee02a3d-97c4-4c23-9df5-61094a47a0bf] Setting agent(CodeActAgent) state from AgentState.LOADING to AgentState.INIT
18:19:42 - openhands:INFO: agent_controller.py:135 - [Agent Controller aee02a3d-97c4-4c23-9df5-61094a47a0bf] Setting agent(CodeActAgent) state from AgentState.INIT to AgentState.RUNNING
18:19:42 - openhands:INFO: github.py:14 - Initializing UserVerifier
18:19:42 - openhands:INFO: github.py:27 - GITHUB_USER_LIST_FILE not configured
18:19:42 - openhands:INFO: github.py:48 - GITHUB_USERS_SHEET_ID not configured
18:19:42 - openhands:INFO: github.py:85 - No user verification sources configured - allowing all users
INFO:     192.168.65.1:57331 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57337 - "GET /config.json HTTP/1.1" 200 OK
INFO:     192.168.65.1:57330 - "GET /api/list-files HTTP/1.1" 200 OK
18:19:42 - openhands:INFO: github.py:14 - Initializing UserVerifier
18:19:42 - openhands:INFO: github.py:27 - GITHUB_USER_LIST_FILE not configured
18:19:42 - openhands:INFO: github.py:48 - GITHUB_USERS_SHEET_ID not configured
18:19:42 - openhands:INFO: github.py:85 - No user verification sources configured - allowing all users
INFO:     192.168.65.1:57337 - "GET /api/list-files HTTP/1.1" 200 OK
18:19:43 - openhands:INFO: github.py:14 - Initializing UserVerifier
18:19:43 - openhands:INFO: github.py:27 - GITHUB_USER_LIST_FILE not configured
18:19:43 - openhands:INFO: github.py:48 - GITHUB_USERS_SHEET_ID not configured
18:19:43 - openhands:INFO: github.py:85 - No user verification sources configured - allowing all users
INFO:     192.168.65.1:57330 - "GET /api/list-files HTTP/1.1" 200 OK


==============
[Agent Controller aee02a3d-97c4-4c23-9df5-61094a47a0bf] LEVEL 0 LOCAL STEP 0 GLOBAL STEP 0


Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

18:19:44 - openhands:ERROR: retry_mixin.py:47 - litellm.APIConnectionError: 'output'
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/litellm/main.py", line 2564, in completion
    response = bedrock_converse_chat_completion.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_handler.py", line 421, in completion
    return litellm.AmazonConverseConfig()._transform_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_transformation.py", line 390, in _transform_response
    message: Optional[MessageBlock] = completion_response["output"]["message"]
                                      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'output'
. Attempt #1 | You can customize retry values in the configuration.

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

18:19:59 - openhands:ERROR: retry_mixin.py:47 - litellm.APIConnectionError: 'output'
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/litellm/main.py", line 2564, in completion
    response = bedrock_converse_chat_completion.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_handler.py", line 421, in completion
    return litellm.AmazonConverseConfig()._transform_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_transformation.py", line 390, in _transform_response
    message: Optional[MessageBlock] = completion_response["output"]["message"]
                                      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'output'
. Attempt #2 | You can customize retry values in the configuration.

Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

18:20:14 - openhands:ERROR: retry_mixin.py:47 - litellm.APIConnectionError: 'output'
Traceback (most recent call last):
  File "/app/.venv/lib/python3.12/site-packages/litellm/main.py", line 2564, in completion
    response = bedrock_converse_chat_completion.completion(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_handler.py", line 421, in completion
    return litellm.AmazonConverseConfig()._transform_response(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.12/site-packages/litellm/llms/bedrock/chat/converse_transformation.py", line 390, in _transform_response
    message: Optional[MessageBlock] = completion_response["output"]["message"]
                                      ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'output'
. Attempt #3 | You can customize retry values in the configuration.
python docker amazon-bedrock litellm openhands
1个回答
0
投票

要解决与 AWS Bedrock 的连接问题,请尝试运行以下命令,添加调试日志记录和卷挂载以进行 AWS 配置访问。

docker run -it --pull=always \
    -e LITELLM_LOG='DEBUG' \
    -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.12-nikolaik \
    -e AWS_ACCESS_KEY_ID='<YOUR_ACCESS_KEY>' \
    -e AWS_SECRET_ACCESS_KEY='<YOUR_SECRET_KEY>' \
    -e AWS_REGION_NAME='us-east-1' \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v ~/.aws:/root/.aws:ro \
    -p 3000:3000 \
    --add-host host.docker.internal:host-gateway \
    --name openhands-app \
    docker.all-hands.dev/all-hands-ai/openhands:0.12

有关更多信息,请参阅 LiteLLM 的 Bedrock 提供程序文档:https://docs.litellm.ai/docs/providers/bedrock

© www.soinside.com 2019 - 2024. All rights reserved.