SWE-agent icon indicating copy to clipboard operation
SWE-agent copied to clipboard

Connection issue whith Open AI

Open PierrunoYT opened this issue 9 months ago • 6 comments

Describe the bug

Connection issue whith Open AI

Steps/commands/code to Reproduce

python run.py --model_name gpt4
--data_path https://github.com/OpenDevin/OpenDevin/issues/1568
--config_file config/default_from_url.yaml

grafik

Error message/results

2024-05-04 19:53:45,017 - openai._base_client - INFO - Retrying request to /chat/completions in 1.915938 seconds
2024-05-04 19:53:47,707 - openai._base_client - INFO - Retrying request to /chat/completions in 0.828122 seconds
2024-05-04 19:53:48,536 - openai._base_client - INFO - Retrying request to /chat/completions in 1.595115 seconds
2024-05-04 19:53:50,689 - openai._base_client - INFO - Retrying request to /chat/completions in 0.961085 seconds
2024-05-04 19:53:51,651 - openai._base_client - INFO - Retrying request to /chat/completions in 1.552007 seconds
Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 952, in _request
    response = self._client.send(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request
    with map_httpcore_exceptions():
  File "/opt/conda/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 952, in _request
    response = self._client.send(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request
    with map_httpcore_exceptions():
  File "/opt/conda/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 69, in map_httpcore_exceptions
    yield
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 233, in handle_request
    resp = self._pool.handle_request(req)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 167, in handle_request
    raise UnsupportedProtocol(
httpcore.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 952, in _request
    response = self._client.send(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 914, in send
    response = self._send_handling_auth(
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 942, in _send_handling_auth
    response = self._send_handling_redirects(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 979, in _send_handling_redirects
    response = self._send_single_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_client.py", line 1015, in _send_single_request
    response = transport.handle_request(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 232, in handle_request
    with map_httpcore_exceptions():
  File "/opt/conda/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/opt/conda/lib/python3.11/site-packages/httpx/_transports/default.py", line 86, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.UnsupportedProtocol: Request URL is missing an 'http://' or 'https://' protocol.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/workspaces/SWE-agent/run.py", line 363, in main
    self.run(index)
  File "/workspaces/SWE-agent/run.py", line 347, in run
    info, trajectory = self.agent.run(
                       ^^^^^^^^^^^^^^^
  File "/workspaces/SWE-agent/sweagent/agent/agents.py", line 814, in run
    thought, action, output = self.forward(
                              ^^^^^^^^^^^^^
  File "/workspaces/SWE-agent/sweagent/agent/agents.py", line 509, in forward
    thought, action, output = self.forward_with_error_check(observation, state)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/SWE-agent/sweagent/agent/agents.py", line 663, in forward_with_error_check
    output = self.forward_model(observation, state)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/SWE-agent/sweagent/agent/agents.py", line 571, in forward_model
    return self.model.query(self.local_history)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/tenacity/__init__.py", line 325, in iter
    raise retry_exc.reraise()
          ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/tenacity/__init__.py", line 158, in reraise
    raise self.last_attempt.result()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/opt/conda/lib/python3.11/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^
  File "/workspaces/SWE-agent/sweagent/agent/models.py", line 264, in query
    response = self.client.chat.completions.create(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_utils/_utils.py", line 277, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/resources/chat/completions.py", line 579, in create
    return self._post(
           ^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 1240, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 921, in request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 976, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 976, in _request
    return self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 1053, in _retry_request
    return self._request(
           ^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/openai/_base_client.py", line 986, in _request
    raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.
WARNING  ❌ Failed on OpenDevin__OpenDevin-i1568: Connection error.                                                                                                                                                                                                            
INFO     Beginning environment shutdown...                                                                                                                                                                                                                                     
INFO     Agent container stopped                                                                                                                                                                                                                                               
INFO     Found image sweagent/swe-agent:latest with tags: ['sweagent/swe-agent:latest'], created: 2024-05-04T19:30:50.413186802Z for linux amd64.                                                                                                                              
DEBUG    Starting container with command: docker run -i --rm --name sweagent-swe-agent-latest-3d9f371ae4 sweagent/swe-agent:latest /bin/bash -l -m                                                                                                                             
INFO     🌱 Environment Initialized ```

### System Information

Windows 11 Pro

### Checklist

- [X] I'm running with the latest docker container/on the latest development version
- [X] I've searched the other issues for a duplicate
- [X] I have copied the full command/code that I ran
- [X] I have copied the **full** log file/error message that was the result (if applicable)
- [X] I have enclosed code/log messages in triple backticks ([docs](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code)) and clicked "Preview" to make sure it's displayed correctly.

PierrunoYT avatar May 04 '24 19:05 PierrunoYT

Ah, looks I misdiagnosed the problem in #307 (github had replaced the datapath with a shorthand so I thought the data path was wrong).

Not sure what's going on here, I don't see it on my side with gpt4.

Can you use the OpenAI API outside of swe-agent?

klieret avatar May 04 '24 20:05 klieret

Ah, looks I misdiagnosed the problem in #307 (github had replaced the datapath with a shorthand so I thought the data path was wrong).

Not sure what's going on here, I don't see it on my side with gpt4.

Can you use the OpenAI API outside of swe-agent?

I tried on Lobe Chat and it worked with my API Key.

PierrunoYT avatar May 04 '24 20:05 PierrunoYT

Did you set an OPENAI_API_BASE_URL or anything like that in your keys.cfg?

klieret avatar May 04 '24 21:05 klieret

What happens if you do this:

import config
import os
from typing import Optional
from openai import OpenAI

cfg = config.Config(os.path.join(os.getcwd(), "keys.cfg"))
api_base_url: Optional[str] = cfg.get("OPENAI_API_BASE_URL", None)
client = OpenAI(api_key=cfg["OPENAI_API_KEY"], base_url=api_base_url)
response = client.chat.completions.create(
        messages=[{"content": "Create a test reply", "role": "user"}],
    model="gpt-4-turbo-2024-04-09",
)
print(response)

klieret avatar May 04 '24 21:05 klieret

Did you set an OPENAI_API_BASE_URL or anything like that in your keys.cfg?

No only the API Key and the GH Token lime removed.

PierrunoYT avatar May 05 '24 06:05 PierrunoYT

What happens if you do this:


import config

import os

from typing import Optional

from openai import OpenAI



cfg = config.Config(os.path.join(os.getcwd(), "keys.cfg"))

api_base_url: Optional[str] = cfg.get("OPENAI_API_BASE_URL", None)

client = OpenAI(api_key=cfg["OPENAI_API_KEY"], base_url=api_base_url)

response = client.chat.completions.create(

        messages=[{"content": "Create a test reply", "role": "user"}],

    model="gpt-4-turbo-2024-04-09",

)

print(response)

Where should I put this?

PierrunoYT avatar May 05 '24 06:05 PierrunoYT

It's a python script to execute and to help you investigate the problem on your end. If this also fails, then the problem is likely on your OpenAI setup/keys configuration.

I'm going to close this issue as this connection issue is probably not related to swe-agent.

klieret avatar May 06 '24 14:05 klieret

It's a python script to execute and to help you investigate the problem on your end. If this also fails, then the problem is likely on your OpenAI setup/keys configuration.

I'm going to close this issue as this connection issue is probably not related to swe-agent.

Mhh okay but how can I run this inside Codespaces?

PierrunoYT avatar May 06 '24 14:05 PierrunoYT

Btw my guess is that you have OPENAI_API_BASE_URL set in your keys.cfg

klieret avatar May 07 '24 22:05 klieret