TheR1D / shell_gpt

A command-line productivity tool powered by AI large language models like GPT-4, will help you accomplish your tasks faster and more efficiently.
MIT License
9.35k stars 733 forks source link

A --proxy option to accept coporate proxies #79

Closed Isaccseven closed 1 year ago

Isaccseven commented 1 year ago

Problem

No network request will work in an corporate environment without the possibility to use a proxy option

Description

Implement an option to handle proxies.

Possible Solution

When the user provides this flag an environment variable for porxy will be used for configuration.

TheR1D commented 1 year ago

It is possible to set a host in runtime configuration file, more details in README.md

dustookk commented 1 year ago

does not work

➜  ~ sgpt propt
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:386 in _make_request        │
│                                                                                                  │
│    383 │   │                                                                                     │
│    384 │   │   # Trigger any extra validation we need to do.                                     │
│    385 │   │   try:                                                                              │
│ ❱  386 │   │   │   self._validate_conn(conn)                                                     │
│    387 │   │   except (SocketTimeout, BaseSSLError) as e:                                        │
│    388 │   │   │   # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.         │
│    389 │   │   │   self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)               │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │            chunked = False                                                                   │ │
│ │               conn = <urllib3.connection.HTTPSConnection object at 0x1047da950>              │ │
│ │ httplib_request_kw = {                                                                       │ │
│ │                      │   'body': b'{"messages": [{"role": "user", "content": "###\\nRole     │ │
│ │                      name: default\\nYou are Comm'+450,                                      │ │
│ │                      │   'headers': {'User-Agent': 'python-requests/2.28.2',                 │ │
│ │                      'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection':      │ │
│ │                      'keep-alive', 'Content-Type': 'application/json', 'Authorization':      │ │
│ │                      'Bearer sk-apikey',           │ │
│ │                      'Content-Length': '530'}                                                │ │
│ │                      }                                                                       │ │
│ │             method = 'POST'                                                                  │ │
│ │               self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50>      │ │
│ │            timeout = Timeout(connect=60, read=60, total=None)                                │ │
│ │        timeout_obj = Timeout(connect=60, read=60, total=None)                                │ │
│ │                url = '/v1/chat/completions'                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:1042 in _validate_conn      │
│                                                                                                  │
│   1039 │   │                                                                                     │
│   1040 │   │   # Force connect early to allow us to validate the connection.                     │
│   1041 │   │   if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`          │
│ ❱ 1042 │   │   │   conn.connect()                                                                │
│   1043 │   │                                                                                     │
│   1044 │   │   if not conn.is_verified:                                                          │
│   1045 │   │   │   warnings.warn(                                                                │
│                                                                                                  │
│ ╭──────────────────────────────────── locals ────────────────────────────────────╮               │
│ │ __class__ = <class 'urllib3.connectionpool.HTTPSConnectionPool'>               │               │
│ │      conn = <urllib3.connection.HTTPSConnection object at 0x1047da950>         │               │
│ │      self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50> │               │
│ ╰────────────────────────────────────────────────────────────────────────────────╯               │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connection.py:419 in connect                  │
│                                                                                                  │
│   416 │   │   ):                                                                                 │
│   417 │   │   │   context.load_default_certs()                                                   │
│   418 │   │                                                                                      │
│ ❱ 419 │   │   self.sock = ssl_wrap_socket(                                                       │
│   420 │   │   │   sock=conn,                                                                     │
│   421 │   │   │   keyfile=self.key_file,                                                         │
│   422 │   │   │   certfile=self.cert_file,                                                       │
│                                                                                                  │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮           │
│ │                conn = <socks.socksocket [closed] fd=-1, family=2, type=1, proto=6> │           │
│ │             context = <ssl.SSLContext object at 0x1048d72f0>                       │           │
│ │ default_ssl_context = True                                                         │           │
│ │            hostname = 'api.openai.com'                                             │           │
│ │         is_time_off = False                                                        │           │
│ │                self = <urllib3.connection.HTTPSConnection object at 0x1047da950>   │           │
│ │     server_hostname = 'api.openai.com'                                             │           │
│ │          tls_in_tls = False                                                        │           │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯           │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/util/ssl_.py:449 in ssl_wrap_socket           │
│                                                                                                  │
│   446 │   │   )                                                                                  │
│   447 │                                                                                          │
│   448 │   if send_sni:                                                                           │
│ ❱ 449 │   │   ssl_sock = _ssl_wrap_socket_impl(                                                  │
│   450 │   │   │   sock, context, tls_in_tls, server_hostname=server_hostname                     │
│   451 │   │   )                                                                                  │
│   452 │   else:                                                                                  │
│                                                                                                  │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮           │
│ │     ca_cert_data = None                                                            │           │
│ │      ca_cert_dir = None                                                            │           │
│ │         ca_certs = '/opt/homebrew/lib/python3.11/site-packages/certifi/cacert.pem' │           │
│ │        cert_reqs = None                                                            │           │
│ │         certfile = None                                                            │           │
│ │          ciphers = None                                                            │           │
│ │          context = <ssl.SSLContext object at 0x1048d72f0>                          │           │
│ │     key_password = None                                                            │           │
│ │          keyfile = None                                                            │           │
│ │         send_sni = True                                                            │           │
│ │  server_hostname = 'api.openai.com'                                                │           │
│ │             sock = <socks.socksocket [closed] fd=-1, family=2, type=1, proto=6>    │           │
│ │      ssl_context = <ssl.SSLContext object at 0x1048d72f0>                          │           │
│ │      ssl_version = None                                                            │           │
│ │       tls_in_tls = False                                                           │           │
│ │ use_sni_hostname = True                                                            │           │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯           │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/util/ssl_.py:493 in _ssl_wrap_socket_impl     │
│                                                                                                  │
│   490 │   │   return SSLTransport(sock, ssl_context, server_hostname)                            │
│   491 │                                                                                          │
│   492 │   if server_hostname:                                                                    │
│ ❱ 493 │   │   return ssl_context.wrap_socket(sock, server_hostname=server_hostname)              │
│   494 │   else:                                                                                  │
│   495 │   │   return ssl_context.wrap_socket(sock)                                               │
│   496                                                                                            │
│                                                                                                  │
│ ╭──────────────────────────────────── locals ────────────────────────────────────╮               │
│ │ server_hostname = 'api.openai.com'                                             │               │
│ │            sock = <socks.socksocket [closed] fd=-1, family=2, type=1, proto=6> │               │
│ │     ssl_context = <ssl.SSLContext object at 0x1048d72f0>                       │               │
│ │      tls_in_tls = False                                                        │               │
│ ╰────────────────────────────────────────────────────────────────────────────────╯               │
│                                                                                                  │
│ /opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11 │
│ /ssl.py:517 in wrap_socket                                                                       │
│                                                                                                  │
│    514 │   │   │   │   │   server_hostname=None, session=None):                                  │
│    515 │   │   # SSLSocket class handles server_hostname encoding before it calls                │
│    516 │   │   # ctx._wrap_socket()                                                              │
│ ❱  517 │   │   return self.sslsocket_class._create(                                              │
│    518 │   │   │   sock=sock,                                                                    │
│    519 │   │   │   server_side=server_side,                                                      │
│    520 │   │   │   do_handshake_on_connect=do_handshake_on_connect,                              │
│                                                                                                  │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮       │
│ │ do_handshake_on_connect = True                                                         │       │
│ │                    self = <ssl.SSLContext object at 0x1048d72f0>                       │       │
│ │         server_hostname = 'api.openai.com'                                             │       │
│ │             server_side = False                                                        │       │
│ │                 session = None                                                         │       │
│ │                    sock = <socks.socksocket [closed] fd=-1, family=2, type=1, proto=6> │       │
│ │    suppress_ragged_eofs = True                                                         │       │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯       │
│                                                                                                  │
│ /opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11 │
│ /ssl.py:1075 in _create                                                                          │
│                                                                                                  │
│   1072 │   │   │   │   │   if timeout == 0.0:                                                    │
│   1073 │   │   │   │   │   │   # non-blocking                                                    │
│   1074 │   │   │   │   │   │   raise ValueError("do_handshake_on_connect should not be specifie  │
│ ❱ 1075 │   │   │   │   │   self.do_handshake()                                                   │
│   1076 │   │   │   except (OSError, ValueError):                                                 │
│   1077 │   │   │   │   self.close()                                                              │
│   1078 │   │   │   │   raise                                                                     │
│                                                                                                  │
│ ╭──────────────────────────────────────── locals ────────────────────────────────────────╮       │
│ │               __class__ = <class 'ssl.SSLSocket'>                                      │       │
│ │                     cls = <class 'ssl.SSLSocket'>                                      │       │
│ │               connected = True                                                         │       │
│ │                 context = <ssl.SSLContext object at 0x1048d72f0>                       │       │
│ │ do_handshake_on_connect = True                                                         │       │
│ │                  kwargs = {                                                            │       │
│ │                           │   'family': <AddressFamily.AF_INET: 2>,                    │       │
│ │                           │   'type': <SocketKind.SOCK_STREAM: 1>,                     │       │
│ │                           │   'proto': 6,                                              │       │
│ │                           │   'fileno': 5                                              │       │
│ │                           }                                                            │       │
│ │                    self = <ssl.SSLSocket [closed] fd=-1, family=2, type=1, proto=0>    │       │
│ │         server_hostname = 'api.openai.com'                                             │       │
│ │             server_side = False                                                        │       │
│ │                 session = None                                                         │       │
│ │                    sock = <socks.socksocket [closed] fd=-1, family=2, type=1, proto=6> │       │
│ │    suppress_ragged_eofs = True                                                         │       │
│ │                 timeout = 60.0                                                         │       │
│ ╰────────────────────────────────────────────────────────────────────────────────────────╯       │
│                                                                                                  │
│ /opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11 │
│ /ssl.py:1346 in do_handshake                                                                     │
│                                                                                                  │
│   1343 │   │   try:                                                                              │
│   1344 │   │   │   if timeout == 0.0 and block:                                                  │
│   1345 │   │   │   │   self.settimeout(None)                                                     │
│ ❱ 1346 │   │   │   self._sslobj.do_handshake()                                                   │
│   1347 │   │   finally:                                                                          │
│   1348 │   │   │   self.settimeout(timeout)                                                      │
│   1349                                                                                           │
│                                                                                                  │
│ ╭────────────────────────────── locals ───────────────────────────────╮                          │
│ │   block = False                                                     │                          │
│ │    self = <ssl.SSLSocket [closed] fd=-1, family=2, type=1, proto=0> │                          │
│ │ timeout = 60.0                                                      │                          │
│ ╰─────────────────────────────────────────────────────────────────────╯                          │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
TimeoutError: _ssl.c:985: The handshake operation timed out

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/homebrew/lib/python3.11/site-packages/requests/adapters.py:489 in send                      │
│                                                                                                  │
│   486 │   │                                                                                      │
│   487 │   │   try:                                                                               │
│   488 │   │   │   if not chunked:                                                                │
│ ❱ 489 │   │   │   │   resp = conn.urlopen(                                                       │
│   490 │   │   │   │   │   method=request.method,                                                 │
│   491 │   │   │   │   │   url=url,                                                               │
│   492 │   │   │   │   │   body=request.body,                                                     │
│                                                                                                  │
│ ╭─────────────────────────────────── locals ───────────────────────────────────╮                 │
│ │    cert = None                                                               │                 │
│ │ chunked = False                                                              │                 │
│ │    conn = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50> │                 │
│ │ proxies = OrderedDict()                                                      │                 │
│ │ request = <PreparedRequest [POST]>                                           │                 │
│ │    self = <requests.adapters.HTTPAdapter object at 0x104ad3490>              │                 │
│ │  stream = True                                                               │                 │
│ │ timeout = Timeout(connect=60, read=60, total=None)                           │                 │
│ │     url = '/v1/chat/completions'                                             │                 │
│ │  verify = True                                                               │                 │
│ ╰──────────────────────────────────────────────────────────────────────────────╯                 │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:787 in urlopen              │
│                                                                                                  │
│    784 │   │   │   elif isinstance(e, (SocketError, HTTPException)):                             │
│    785 │   │   │   │   e = ProtocolError("Connection aborted.", e)                               │
│    786 │   │   │                                                                                 │
│ ❱  787 │   │   │   retries = retries.increment(                                                  │
│    788 │   │   │   │   method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]           │
│    789 │   │   │   )                                                                             │
│    790 │   │   │   retries.sleep()                                                               │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ _is_ssl_error_message_from_http_proxy = <function                                            │ │
│ │                                         HTTPConnectionPool.urlopen.<locals>._is_ssl_error_m… │ │
│ │                                         at 0x10480dc60>                                      │ │
│ │                      assert_same_host = False                                                │ │
│ │                                  body = b'{"messages": [{"role": "user", "content":          │ │
│ │                                         "###\\nRole name: default\\nYou are Comm'+450        │ │
│ │                              body_pos = None                                                 │ │
│ │                               chunked = False                                                │ │
│ │                            clean_exit = False                                                │ │
│ │                                  conn = None                                                 │ │
│ │                    destination_scheme = None                                                 │ │
│ │                                   err = None                                                 │ │
│ │                               headers = {'User-Agent': 'python-requests/2.28.2',             │ │
│ │                                         'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', │ │
│ │                                         'Connection': 'keep-alive', 'Content-Type':          │ │
│ │                                         'application/json', 'Authorization': 'Bearer         │ │
│ │                                         sk-apikey… │ │
│ │                                         'Content-Length': '530'}                             │ │
│ │                  http_tunnel_required = False                                                │ │
│ │                     is_new_proxy_conn = False                                                │ │
│ │                                method = 'POST'                                               │ │
│ │                            parsed_url = Url(                                                 │ │
│ │                                         │   scheme=None,                                     │ │
│ │                                         │   auth=None,                                       │ │
│ │                                         │   host=None,                                       │ │
│ │                                         │   port=None,                                       │ │
│ │                                         │   path='/v1/chat/completions',                     │ │
│ │                                         │   query=None,                                      │ │
│ │                                         │   fragment=None                                    │ │
│ │                                         )                                                    │ │
│ │                          pool_timeout = None                                                 │ │
│ │                              redirect = False                                                │ │
│ │                          release_conn = False                                                │ │
│ │                     release_this_conn = True                                                 │ │
│ │                           response_kw = {'preload_content': False, 'decode_content': False}  │ │
│ │                               retries = Retry(total=0, connect=None, read=False,             │ │
│ │                                         redirect=None, status=None)                          │ │
│ │                                  self = <urllib3.connectionpool.HTTPSConnectionPool object   │ │
│ │                                         at 0x104adaf50>                                      │ │
│ │                               timeout = Timeout(connect=60, read=60, total=None)             │ │
│ │                           timeout_obj = Timeout(connect=60, read=60, total=None)             │ │
│ │                                   url = '/v1/chat/completions'                               │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/util/retry.py:550 in increment                │
│                                                                                                  │
│   547 │   │   elif error and self._is_read_error(error):                                         │
│   548 │   │   │   # Read retry?                                                                  │
│   549 │   │   │   if read is False or not self._is_method_retryable(method):                     │
│ ❱ 550 │   │   │   │   raise six.reraise(type(error), error, _stacktrace)                         │
│   551 │   │   │   elif read is not None:                                                         │
│   552 │   │   │   │   read -= 1                                                                  │
│   553                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │             _pool = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50>       │ │
│ │       _stacktrace = <traceback object at 0x104adbf80>                                        │ │
│ │             cause = 'unknown'                                                                │ │
│ │           connect = None                                                                     │ │
│ │             error = ReadTimeoutError("HTTPSConnectionPool(host='api.openai.com', port=443):  │ │
│ │                     Read timed out. (read timeout=60)")                                      │ │
│ │            method = 'POST'                                                                   │ │
│ │             other = None                                                                     │ │
│ │              read = False                                                                    │ │
│ │          redirect = None                                                                     │ │
│ │ redirect_location = None                                                                     │ │
│ │          response = None                                                                     │ │
│ │              self = Retry(total=0, connect=None, read=False, redirect=None, status=None)     │ │
│ │            status = None                                                                     │ │
│ │      status_count = None                                                                     │ │
│ │             total = -1                                                                       │ │
│ │               url = '/v1/chat/completions'                                                   │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/packages/six.py:770 in reraise                │
│                                                                                                  │
│    767 │   │   │   │   value = tp()                                                              │
│    768 │   │   │   if value.__traceback__ is not tb:                                             │
│    769 │   │   │   │   raise value.with_traceback(tb)                                            │
│ ❱  770 │   │   │   raise value                                                                   │
│    771 │   │   finally:                                                                          │
│    772 │   │   │   value = None                                                                  │
│    773 │   │   │   tb = None                                                                     │
│                                                                                                  │
│ ╭─────────────────────── locals ────────────────────────╮                                        │
│ │    tb = None                                          │                                        │
│ │    tp = <class 'urllib3.exceptions.ReadTimeoutError'> │                                        │
│ │ value = None                                          │                                        │
│ ╰───────────────────────────────────────────────────────╯                                        │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:703 in urlopen              │
│                                                                                                  │
│    700 │   │   │   │   self._prepare_proxy(conn)                                                 │
│    701 │   │   │                                                                                 │
│    702 │   │   │   # Make the request on the httplib connection object.                          │
│ ❱  703 │   │   │   httplib_response = self._make_request(                                        │
│    704 │   │   │   │   conn,                                                                     │
│    705 │   │   │   │   method,                                                                   │
│    706 │   │   │   │   url,                                                                      │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ _is_ssl_error_message_from_http_proxy = <function                                            │ │
│ │                                         HTTPConnectionPool.urlopen.<locals>._is_ssl_error_m… │ │
│ │                                         at 0x10480dc60>                                      │ │
│ │                      assert_same_host = False                                                │ │
│ │                                  body = b'{"messages": [{"role": "user", "content":          │ │
│ │                                         "###\\nRole name: default\\nYou are Comm'+450        │ │
│ │                              body_pos = None                                                 │ │
│ │                               chunked = False                                                │ │
│ │                            clean_exit = False                                                │ │
│ │                                  conn = None                                                 │ │
│ │                    destination_scheme = None                                                 │ │
│ │                                   err = None                                                 │ │
│ │                               headers = {'User-Agent': 'python-requests/2.28.2',             │ │
│ │                                         'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', │ │
│ │                                         'Connection': 'keep-alive', 'Content-Type':          │ │
│ │                                         'application/json', 'Authorization': 'Bearer         │ │
│ │                                         sk-apikey… │ │
│ │                                         'Content-Length': '530'}                             │ │
│ │                  http_tunnel_required = False                                                │ │
│ │                     is_new_proxy_conn = False                                                │ │
│ │                                method = 'POST'                                               │ │
│ │                            parsed_url = Url(                                                 │ │
│ │                                         │   scheme=None,                                     │ │
│ │                                         │   auth=None,                                       │ │
│ │                                         │   host=None,                                       │ │
│ │                                         │   port=None,                                       │ │
│ │                                         │   path='/v1/chat/completions',                     │ │
│ │                                         │   query=None,                                      │ │
│ │                                         │   fragment=None                                    │ │
│ │                                         )                                                    │ │
│ │                          pool_timeout = None                                                 │ │
│ │                              redirect = False                                                │ │
│ │                          release_conn = False                                                │ │
│ │                     release_this_conn = True                                                 │ │
│ │                           response_kw = {'preload_content': False, 'decode_content': False}  │ │
│ │                               retries = Retry(total=0, connect=None, read=False,             │ │
│ │                                         redirect=None, status=None)                          │ │
│ │                                  self = <urllib3.connectionpool.HTTPSConnectionPool object   │ │
│ │                                         at 0x104adaf50>                                      │ │
│ │                               timeout = Timeout(connect=60, read=60, total=None)             │ │
│ │                           timeout_obj = Timeout(connect=60, read=60, total=None)             │ │
│ │                                   url = '/v1/chat/completions'                               │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:389 in _make_request        │
│                                                                                                  │
│    386 │   │   │   self._validate_conn(conn)                                                     │
│    387 │   │   except (SocketTimeout, BaseSSLError) as e:                                        │
│    388 │   │   │   # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.         │
│ ❱  389 │   │   │   self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)               │
│    390 │   │   │   raise                                                                         │
│    391 │   │                                                                                     │
│    392 │   │   # conn.request() calls http.client.*.request, not the method in                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │            chunked = False                                                                   │ │
│ │               conn = <urllib3.connection.HTTPSConnection object at 0x1047da950>              │ │
│ │ httplib_request_kw = {                                                                       │ │
│ │                      │   'body': b'{"messages": [{"role": "user", "content": "###\\nRole     │ │
│ │                      name: default\\nYou are Comm'+450,                                      │ │
│ │                      │   'headers': {'User-Agent': 'python-requests/2.28.2',                 │ │
│ │                      'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection':      │ │
│ │                      'keep-alive', 'Content-Type': 'application/json', 'Authorization':      │ │
│ │                      'Bearer sk-apikey',           │ │
│ │                      'Content-Length': '530'}                                                │ │
│ │                      }                                                                       │ │
│ │             method = 'POST'                                                                  │ │
│ │               self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50>      │ │
│ │            timeout = Timeout(connect=60, read=60, total=None)                                │ │
│ │        timeout_obj = Timeout(connect=60, read=60, total=None)                                │ │
│ │                url = '/v1/chat/completions'                                                  │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/urllib3/connectionpool.py:340 in _raise_timeout       │
│                                                                                                  │
│    337 │   │   """Is the error actually a timeout? Will raise a ReadTimeout or pass"""           │
│    338 │   │                                                                                     │
│    339 │   │   if isinstance(err, SocketTimeout):                                                │
│ ❱  340 │   │   │   raise ReadTimeoutError(                                                       │
│    341 │   │   │   │   self, url, "Read timed out. (read timeout=%s)" % timeout_value            │
│    342 │   │   │   )                                                                             │
│    343                                                                                           │
│                                                                                                  │
│ ╭────────────────────────────────────── locals ──────────────────────────────────────╮           │
│ │           err = TimeoutError('_ssl.c:985: The handshake operation timed out')      │           │
│ │          self = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50> │           │
│ │ timeout_value = 60                                                                 │           │
│ │           url = '/v1/chat/completions'                                             │           │
│ ╰────────────────────────────────────────────────────────────────────────────────────╯           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ReadTimeoutError: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=60)

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/app.py:159 in main                               │
│                                                                                                  │
│   156 │   │   │   caching=cache,                                                                 │
│   157 │   │   )                                                                                  │
│   158 │   else:                                                                                  │
│ ❱ 159 │   │   full_completion = DefaultHandler(client, role_class).handle(                       │
│   160 │   │   │   prompt,                                                                        │
│   161 │   │   │   model=model.value,                                                             │
│   162 │   │   │   temperature=temperature,                                                       │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │        api_host = 'https://api.openai.com'                              │                      │
│ │         api_key = 'sk-apikey' │                      │
│ │           cache = True                                                  │                      │
│ │            chat = None                                                  │                      │
│ │          client = <sgpt.client.OpenAIClient object at 0x104ad2f50>      │                      │
│ │            code = False                                                 │                      │
│ │     create_role = None                                                  │                      │
│ │          editor = False                                                 │                      │
│ │      list_chats = None                                                  │                      │
│ │      list_roles = None                                                  │                      │
│ │           model = <ModelOptions.GPT3: 'gpt-3.5-turbo'>                  │                      │
│ │          prompt = 'propt'                                               │                      │
│ │            repl = None                                                  │                      │
│ │            role = None                                                  │                      │
│ │      role_class = <sgpt.role.SystemRole object at 0x104ad3a90>          │                      │
│ │           shell = False                                                 │                      │
│ │       show_chat = None                                                  │                      │
│ │       show_role = None                                                  │                      │
│ │    stdin_passed = False                                                 │                      │
│ │     temperature = 0.1                                                   │                      │
│ │ top_probability = 1.0                                                   │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/handlers/handler.py:28 in handle                 │
│                                                                                                  │
│   25 │   def handle(self, prompt: str, **kwargs: Any) -> str:                                    │
│   26 │   │   messages = self.make_messages(self.make_prompt(prompt))                             │
│   27 │   │   full_completion = ""                                                                │
│ ❱ 28 │   │   for word in self.get_completion(messages=messages, **kwargs):                       │
│   29 │   │   │   typer.secho(word, fg=self.color, bold=True, nl=False)                           │
│   30 │   │   │   full_completion += word                                                         │
│   31 │   │   typer.echo()                                                                        │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ full_completion = ''                                                                         │ │
│ │          kwargs = {                                                                          │ │
│ │                   │   'model': 'gpt-3.5-turbo',                                              │ │
│ │                   │   'temperature': 0.1,                                                    │ │
│ │                   │   'top_probability': 1.0,                                                │ │
│ │                   │   'caching': True                                                        │ │
│ │                   }                                                                          │ │
│ │        messages = [                                                                          │ │
│ │                   │   {                                                                      │ │
│ │                   │   │   'role': 'user',                                                    │ │
│ │                   │   │   'content': '###\nRole name: default\nYou are Command Line App      │ │
│ │                   ShellGPT, a programming and syst'+317                                      │ │
│ │                   │   }                                                                      │ │
│ │                   ]                                                                          │ │
│ │          prompt = 'propt'                                                                    │ │
│ │            self = <sgpt.handlers.default_handler.DefaultHandler object at 0x104990c10>       │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/handlers/handler.py:23 in get_completion         │
│                                                                                                  │
│   20 │   │   raise NotImplementedError                                                           │
│   21 │                                                                                           │
│   22 │   def get_completion(self, **kwargs: Any) -> Generator[str, None, None]:                  │
│ ❱ 23 │   │   yield from self.client.get_completion(**kwargs)                                     │
│   24 │                                                                                           │
│   25 │   def handle(self, prompt: str, **kwargs: Any) -> str:                                    │
│   26 │   │   messages = self.make_messages(self.make_prompt(prompt))                             │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ kwargs = {                                                                                   │ │
│ │          │   'messages': [                                                                   │ │
│ │          │   │   {                                                                           │ │
│ │          │   │   │   'role': 'user',                                                         │ │
│ │          │   │   │   'content': '###\nRole name: default\nYou are Command Line App ShellGPT, │ │
│ │          a programming and syst'+317                                                         │ │
│ │          │   │   }                                                                           │ │
│ │          │   ],                                                                              │ │
│ │          │   'model': 'gpt-3.5-turbo',                                                       │ │
│ │          │   'temperature': 0.1,                                                             │ │
│ │          │   'top_probability': 1.0,                                                         │ │
│ │          │   'caching': True                                                                 │ │
│ │          }                                                                                   │ │
│ │   self = <sgpt.handlers.default_handler.DefaultHandler object at 0x104990c10>                │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/client.py:100 in get_completion                  │
│                                                                                                  │
│    97 │   │   :param caching: Boolean value to enable/disable caching.                           │
│    98 │   │   :return: String generated completion.                                              │
│    99 │   │   """                                                                                │
│ ❱ 100 │   │   yield from self._request(                                                          │
│   101 │   │   │   messages,                                                                      │
│   102 │   │   │   model,                                                                         │
│   103 │   │   │   temperature,                                                                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │         caching = True                                                                       │ │
│ │        messages = [                                                                          │ │
│ │                   │   {                                                                      │ │
│ │                   │   │   'role': 'user',                                                    │ │
│ │                   │   │   'content': '###\nRole name: default\nYou are Command Line App      │ │
│ │                   ShellGPT, a programming and syst'+317                                      │ │
│ │                   │   }                                                                      │ │
│ │                   ]                                                                          │ │
│ │           model = 'gpt-3.5-turbo'                                                            │ │
│ │            self = <sgpt.client.OpenAIClient object at 0x104ad2f50>                           │ │
│ │     temperature = 0.1                                                                        │ │
│ │ top_probability = 1.0                                                                        │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/cache.py:39 in wrapper                           │
│                                                                                                  │
│   36 │   │   │   │   yield cache_file.read_text()                                                │
│   37 │   │   │   │   return                                                                      │
│   38 │   │   │   result = ""                                                                     │
│ ❱ 39 │   │   │   for i in func(*args, **kwargs):                                                 │
│   40 │   │   │   │   result += i                                                                 │
│   41 │   │   │   │   yield i                                                                     │
│   42 │   │   │   cache_file.write_text(result)                                                   │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │       args = (                                                                               │ │
│ │              │   <sgpt.client.OpenAIClient object at 0x104ad2f50>,                           │ │
│ │              │   [                                                                           │ │
│ │              │   │   {                                                                       │ │
│ │              │   │   │   'role': 'user',                                                     │ │
│ │              │   │   │   'content': '###\nRole name: default\nYou are Command Line App       │ │
│ │              ShellGPT, a programming and syst'+317                                           │ │
│ │              │   │   }                                                                       │ │
│ │              │   ],                                                                          │ │
│ │              │   'gpt-3.5-turbo',                                                            │ │
│ │              │   0.1,                                                                        │ │
│ │              │   1.0                                                                         │ │
│ │              )                                                                               │ │
│ │ cache_file = PosixPath('/var/folders/x6/4nbmjvwn5yv04gcq2n4cggw40000gn/T/cache/016fc2e13552… │ │
│ │  cache_key = '016fc2e135522df1f2cf31d8f7ea8635'                                              │ │
│ │       func = <function OpenAIClient._request at 0x10480db20>                                 │ │
│ │     kwargs = {}                                                                              │ │
│ │     result = ''                                                                              │ │
│ │       self = <sgpt.cache.Cache object at 0x10404aa10>                                        │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/sgpt/client.py:64 in _request                         │
│                                                                                                  │
│    61 │   │   │   "stream": True,                                                                │
│    62 │   │   }                                                                                  │
│    63 │   │   endpoint = f"{self.api_host}/v1/chat/completions"                                  │
│ ❱  64 │   │   response = requests.post(                                                          │
│    65 │   │   │   endpoint, headers=headers, json=data, timeout=REQUEST_TIMEOUT, stream=True     │
│    66 │   │   )                                                                                  │
│    67 │   │   response.raise_for_status()                                                        │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │            data = {                                                                          │ │
│ │                   │   'messages': [                                                          │ │
│ │                   │   │   {                                                                  │ │
│ │                   │   │   │   'role': 'user',                                                │ │
│ │                   │   │   │   'content': '###\nRole name: default\nYou are Command Line App  │ │
│ │                   ShellGPT, a programming and syst'+317                                      │ │
│ │                   │   │   }                                                                  │ │
│ │                   │   ],                                                                     │ │
│ │                   │   'model': 'gpt-3.5-turbo',                                              │ │
│ │                   │   'temperature': 0.1,                                                    │ │
│ │                   │   'top_p': 1.0,                                                          │ │
│ │                   │   'stream': True                                                         │ │
│ │                   }                                                                          │ │
│ │        endpoint = 'https://api.openai.com/v1/chat/completions'                               │ │
│ │         headers = {                                                                          │ │
│ │                   │   'Content-Type': 'application/json',                                    │ │
│ │                   │   'Authorization': 'Bearer                                               │ │
│ │                   sk-apikey'                       │ │
│ │                   }                                                                          │ │
│ │        messages = [                                                                          │ │
│ │                   │   {                                                                      │ │
│ │                   │   │   'role': 'user',                                                    │ │
│ │                   │   │   'content': '###\nRole name: default\nYou are Command Line App      │ │
│ │                   ShellGPT, a programming and syst'+317                                      │ │
│ │                   │   }                                                                      │ │
│ │                   ]                                                                          │ │
│ │           model = 'gpt-3.5-turbo'                                                            │ │
│ │            self = <sgpt.client.OpenAIClient object at 0x104ad2f50>                           │ │
│ │     temperature = 0.1                                                                        │ │
│ │ top_probability = 1.0                                                                        │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/requests/api.py:115 in post                           │
│                                                                                                  │
│   112 │   :rtype: requests.Response                                                              │
│   113 │   """                                                                                    │
│   114 │                                                                                          │
│ ❱ 115 │   return request("post", url, data=data, json=json, **kwargs)                            │
│   116                                                                                            │
│   117                                                                                            │
│   118 def put(url, data=None, **kwargs):                                                         │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │   data = None                                                                                │ │
│ │   json = {                                                                                   │ │
│ │          │   'messages': [                                                                   │ │
│ │          │   │   {                                                                           │ │
│ │          │   │   │   'role': 'user',                                                         │ │
│ │          │   │   │   'content': '###\nRole name: default\nYou are Command Line App ShellGPT, │ │
│ │          a programming and syst'+317                                                         │ │
│ │          │   │   }                                                                           │ │
│ │          │   ],                                                                              │ │
│ │          │   'model': 'gpt-3.5-turbo',                                                       │ │
│ │          │   'temperature': 0.1,                                                             │ │
│ │          │   'top_p': 1.0,                                                                   │ │
│ │          │   'stream': True                                                                  │ │
│ │          }                                                                                   │ │
│ │ kwargs = {                                                                                   │ │
│ │          │   'headers': {                                                                    │ │
│ │          │   │   'Content-Type': 'application/json',                                         │ │
│ │          │   │   'Authorization': 'Bearer                                                    │ │
│ │          sk-apikey'                                │ │
│ │          │   },                                                                              │ │
│ │          │   'timeout': 60,                                                                  │ │
│ │          │   'stream': True                                                                  │ │
│ │          }                                                                                   │ │
│ │    url = 'https://api.openai.com/v1/chat/completions'                                        │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/requests/api.py:59 in request                         │
│                                                                                                  │
│    56 │   # avoid leaving sockets open which can trigger a ResourceWarning in some               │
│    57 │   # cases, and look like a memory leak in others.                                        │
│    58 │   with sessions.Session() as session:                                                    │
│ ❱  59 │   │   return session.request(method=method, url=url, **kwargs)                           │
│    60                                                                                            │
│    61                                                                                            │
│    62 def get(url, params=None, **kwargs):                                                       │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │  kwargs = {                                                                                  │ │
│ │           │   'data': None,                                                                  │ │
│ │           │   'json': {                                                                      │ │
│ │           │   │   'messages': [                                                              │ │
│ │           │   │   │   {                                                                      │ │
│ │           │   │   │   │   'role': 'user',                                                    │ │
│ │           │   │   │   │   'content': '###\nRole name: default\nYou are Command Line App      │ │
│ │           ShellGPT, a programming and syst'+317                                              │ │
│ │           │   │   │   }                                                                      │ │
│ │           │   │   ],                                                                         │ │
│ │           │   │   'model': 'gpt-3.5-turbo',                                                  │ │
│ │           │   │   'temperature': 0.1,                                                        │ │
│ │           │   │   'top_p': 1.0,                                                              │ │
│ │           │   │   'stream': True                                                             │ │
│ │           │   },                                                                             │ │
│ │           │   'headers': {                                                                   │ │
│ │           │   │   'Content-Type': 'application/json',                                        │ │
│ │           │   │   'Authorization': 'Bearer                                                   │ │
│ │           sk-apikey'                               │ │
│ │           │   },                                                                             │ │
│ │           │   'timeout': 60,                                                                 │ │
│ │           │   'stream': True                                                                 │ │
│ │           }                                                                                  │ │
│ │  method = 'post'                                                                             │ │
│ │ session = <requests.sessions.Session object at 0x104ad3990>                                  │ │
│ │     url = 'https://api.openai.com/v1/chat/completions'                                       │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/requests/sessions.py:587 in request                   │
│                                                                                                  │
│   584 │   │   │   "allow_redirects": allow_redirects,                                            │
│   585 │   │   }                                                                                  │
│   586 │   │   send_kwargs.update(settings)                                                       │
│ ❱ 587 │   │   resp = self.send(prep, **send_kwargs)                                              │
│   588 │   │                                                                                      │
│   589 │   │   return resp                                                                        │
│   590                                                                                            │
│                                                                                                  │
│ ╭─────────────────────────────────────────── locals ───────────────────────────────────────────╮ │
│ │ allow_redirects = True                                                                       │ │
│ │            auth = None                                                                       │ │
│ │            cert = None                                                                       │ │
│ │         cookies = None                                                                       │ │
│ │            data = None                                                                       │ │
│ │           files = None                                                                       │ │
│ │         headers = {                                                                          │ │
│ │                   │   'Content-Type': 'application/json',                                    │ │
│ │                   │   'Authorization': 'Bearer                                               │ │
│ │                   sk-apikey'                       │ │
│ │                   }                                                                          │ │
│ │           hooks = None                                                                       │ │
│ │            json = {                                                                          │ │
│ │                   │   'messages': [                                                          │ │
│ │                   │   │   {                                                                  │ │
│ │                   │   │   │   'role': 'user',                                                │ │
│ │                   │   │   │   'content': '###\nRole name: default\nYou are Command Line App  │ │
│ │                   ShellGPT, a programming and syst'+317                                      │ │
│ │                   │   │   }                                                                  │ │
│ │                   │   ],                                                                     │ │
│ │                   │   'model': 'gpt-3.5-turbo',                                              │ │
│ │                   │   'temperature': 0.1,                                                    │ │
│ │                   │   'top_p': 1.0,                                                          │ │
│ │                   │   'stream': True                                                         │ │
│ │                   }                                                                          │ │
│ │          method = 'post'                                                                     │ │
│ │          params = None                                                                       │ │
│ │            prep = <PreparedRequest [POST]>                                                   │ │
│ │         proxies = {}                                                                         │ │
│ │             req = <Request [POST]>                                                           │ │
│ │            self = <requests.sessions.Session object at 0x104ad3990>                          │ │
│ │     send_kwargs = {                                                                          │ │
│ │                   │   'timeout': 60,                                                         │ │
│ │                   │   'allow_redirects': True,                                               │ │
│ │                   │   'proxies': OrderedDict(),                                              │ │
│ │                   │   'stream': True,                                                        │ │
│ │                   │   'verify': True,                                                        │ │
│ │                   │   'cert': None                                                           │ │
│ │                   }                                                                          │ │
│ │        settings = {'proxies': OrderedDict(), 'stream': True, 'verify': True, 'cert': None}   │ │
│ │          stream = True                                                                       │ │
│ │         timeout = 60                                                                         │ │
│ │             url = 'https://api.openai.com/v1/chat/completions'                               │ │
│ │          verify = None                                                                       │ │
│ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/requests/sessions.py:701 in send                      │
│                                                                                                  │
│   698 │   │   start = preferred_clock()                                                          │
│   699 │   │                                                                                      │
│   700 │   │   # Send the request                                                                 │
│ ❱ 701 │   │   r = adapter.send(request, **kwargs)                                                │
│   702 │   │                                                                                      │
│   703 │   │   # Total elapsed time of the request (approximately)                                │
│   704 │   │   elapsed = preferred_clock() - start                                                │
│                                                                                                  │
│ ╭──────────────────────────────── locals ─────────────────────────────────╮                      │
│ │         adapter = <requests.adapters.HTTPAdapter object at 0x104ad3490> │                      │
│ │ allow_redirects = True                                                  │                      │
│ │           hooks = {'response': []}                                      │                      │
│ │          kwargs = {                                                     │                      │
│ │                   │   'timeout': 60,                                    │                      │
│ │                   │   'proxies': OrderedDict(),                         │                      │
│ │                   │   'stream': True,                                   │                      │
│ │                   │   'verify': True,                                   │                      │
│ │                   │   'cert': None                                      │                      │
│ │                   }                                                     │                      │
│ │         request = <PreparedRequest [POST]>                              │                      │
│ │            self = <requests.sessions.Session object at 0x104ad3990>     │                      │
│ │           start = 1682244456.417363                                     │                      │
│ │          stream = True                                                  │                      │
│ ╰─────────────────────────────────────────────────────────────────────────╯                      │
│                                                                                                  │
│ /opt/homebrew/lib/python3.11/site-packages/requests/adapters.py:578 in send                      │
│                                                                                                  │
│   575 │   │   │   │   # This branch is for urllib3 versions earlier than v1.22                   │
│   576 │   │   │   │   raise SSLError(e, request=request)                                         │
│   577 │   │   │   elif isinstance(e, ReadTimeoutError):                                          │
│ ❱ 578 │   │   │   │   raise ReadTimeout(e, request=request)                                      │
│   579 │   │   │   elif isinstance(e, _InvalidHeader):                                            │
│   580 │   │   │   │   raise InvalidHeader(e, request=request)                                    │
│   581 │   │   │   else:                                                                          │
│                                                                                                  │
│ ╭─────────────────────────────────── locals ───────────────────────────────────╮                 │
│ │    cert = None                                                               │                 │
│ │ chunked = False                                                              │                 │
│ │    conn = <urllib3.connectionpool.HTTPSConnectionPool object at 0x104adaf50> │                 │
│ │ proxies = OrderedDict()                                                      │                 │
│ │ request = <PreparedRequest [POST]>                                           │                 │
│ │    self = <requests.adapters.HTTPAdapter object at 0x104ad3490>              │                 │
│ │  stream = True                                                               │                 │
│ │ timeout = Timeout(connect=60, read=60, total=None)                           │                 │
│ │     url = '/v1/chat/completions'                                             │                 │
│ │  verify = True                                                               │                 │
│ ╰──────────────────────────────────────────────────────────────────────────────╯                 │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ReadTimeout: HTTPSConnectionPool(host='api.openai.com', port=443): Read timed out. (read timeout=60)
➜  ~