Maplemx / Agently

[AI Agent Application Development Framework] - 🚀 Build AI agent native application in very few code 💬 Easy to interact with AI agent in code using structure data and chained-calls syntax 🧩 Enhance AI Agent using plugins instead of rebuild a whole new agent
http://agently.tech
Apache License 2.0
935 stars 105 forks source link

openai.APIConnectionError: Connection error #34

Closed pslong closed 7 months ago

pslong commented 8 months ago

openai 在别的项目里正常调用运行,在执行play_ground时报错openai.APIConnectionError: Connection error

Name: Agently Version: 3.0.2

python .\playground\simple_role_play.py [Request Data] { "stream": true, "messages": [ { "role": "user", "content": "# [INPUT]:\n帮我设计一个符合爱用emoji的猫娘的设定的角色\n\n# [INSTRUCTION]:\n使用中文输出\n\n# [OUTPUT REQUIREMENT]:\n## TYPE:\nJSON can be parsed in Python\n## FORMAT:\n{\n\t\"role\": \n\t{\n\t\t\"name\": ,//jojo\n\t\t\"age\": ,//10\n\t\t\"character\": ,//喜欢睡懒觉和晒太阳\n\t\t\"belief\": ,//没有什么是比吃美食更让人开心了\n\t\t},\n\t\"background_story\": \n\t[\n\t\t,//jojo出生在一个异世界的兽人国小村庄,每天在睡觉的时候会穿 梭到地球,来到主人莫欣的身边,\n\t\t...\n\t],\n}\n\n\n[OUTPUT]:\n" } ], "model": "gpt-3.5-turbo" } Exception in thread Thread-1 (start_in_theard): Traceback (most recent call last): File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 66, in map_httpcore_exceptions yield File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 228, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpcore_sync\connection_pool.py", line 215, 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 "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 858, in _request response = self._client.send(request, auth=self.custom_auth, stream=stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 901, in send
response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 1002, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 227, in handle_request with map_httpcore_exceptions(): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64qbz5n2kfra8p0\Lib\contextlib.py", line 155, in exit__ self.gen.throw(typ, value, traceback) File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 83, 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 "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 66, in map_httpcore_exceptions yield File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 228, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpcore_sync\connection_pool.py", line 215, 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 "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 858, in _request response = self._client.send(request, auth=self.custom_auth, stream=stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 901, in send
response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 1002, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 227, in handle_request with map_httpcore_exceptions(): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64qbz5n2kfra8p0\Lib\contextlib.py", line 155, in exit__ self.gen.throw(typ, value, traceback) File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 83, 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 "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 66, in map_httpcore_exceptions yield File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 228, in handle_request resp = self._pool.handle_request(req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpcore_sync\connection_pool.py", line 215, 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 "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 858, in _request response = self._client.send(request, auth=self.custom_auth, stream=stream) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 901, in send
response = self._send_handling_auth( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 929, in _send_handling_auth response = self._send_handling_redirects( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 966, in _send_handling_redirects response = self._send_single_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_client.py", line 1002, in _send_single_request response = transport.handle_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 227, in handle_request with map_httpcore_exceptions(): File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64qbz5n2kfra8p0\Lib\contextlib.py", line 155, in exit__ self.gen.throw(typ, value, traceback) File "D:\Project\Agently\agently-env\Lib\site-packages\httpx_transports\default.py", line 83, 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 "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64qbz5n2kfra8p0\Lib\threading.py", line 1045, in _bootstrap_inner self.run() File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64qbz5n2kfra8p0\Lib\threading.py", line 982, in run self._target(*self._args, *self._kwargs) File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\Agent\Agent.py", line 223, in start_in_theard reply = asyncio.get_event_loop().run_until_complete(self.start_async(request_type)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\asyncio\base_events.py", line 653, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\Agent\Agent.py", line 149, in start_async event_generator = await self.request.get_event_generator(request_type) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\Request\Request.py", line 104, in get_event_generator response_generator = request_plugin_export"request_model" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\plugins\request\OpenAI.py", line 203, in request_model return self.request_gpt(request_data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\plugins\request\OpenAI.py", line 186, in request_gpt stream = client.chat.completions.create( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_utils_utils.py", line 299, in wrapper return func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai\resources\chat\completions.py", line 598, in create return self._post( ^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 1055, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 834, in request return self._request( ^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 890, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 925, in _retry_request return self._request( ^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 890, in _request return self._retry_request( ^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 925, in _retry_request return self._request( ^^^^^^^^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\openai_base_client.py", line 897, in _request raise APIConnectionError(request=request) from err openai.APIConnectionError: Connection error. Traceback (most recent call last): File "D:\Project\Agently\playground\simple_role_play.py", line 44, in print(play_with_role_play_agent("爱用emoji的猫娘", "你好,今天是个钓鱼的好天气,不是吗?"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Project\Agently\playground\simple_role_play.py", line 30, in play_with_role_play_agent
.start() ^^^^^^^ File "D:\Project\Agently\agently-env\Lib\site-packages\Agently\Agent\Agent.py", line 228, in start reply = reply_queue.get_nowait() ^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\queue.py", line 199, in get_nowait return self.get(block=False) ^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1776.0_x64__qbz5n2kfra8p0\Lib\queue.py", line 168, in get raise Empty _queue.Empty

Maplemx commented 8 months ago

如果要使用OpenAI默认的url,不需要.set_settings("model.OpenAI.url"),如果要切换其他的转发接口,请带上http://或者https://