continue icon indicating copy to clipboard operation
continue copied to clipboard

[CON-212] Error when editing files on different drives (e.g. c: vs e: on windows)

Open sestinj opened this issue 2 years ago • 13 comments

Before submitting your bug report

Relevant environment info

- OS: Windows
- Continue: *

Description

Seems to occur when editing a file that is on a drive different from where VS Code is installed, for example when VS Code is on c: and the file is on e:. An error is raised, but the context is still given.

To reproduce

  1. On windows, have VS Code installed on c: drive
  2. Open a file on e: drive
  3. Attempt to /edit the file with Continue

Log output

No response

CON-212

sestinj avatar Sep 27 '23 19:09 sestinj

Any news on this?

I am unable to use the /edit or /comment commands. Every time I try to use them, I always receive a readFile error.

Here are some screenshots and error logs.

image

[2023-10-02 12:52:29,234] [DEBUG] Error loading meilisearch index:
[2023-10-02 12:52:29,638] [DEBUG] Using MeiliSearch at URL: http://localhost:7700
[2023-10-02 12:52:30,320] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"/comment"}}
[2023-10-02 12:52:30,344] [WARNING] Error sending IDE message, websocket probably closed: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.
error uploading: HTTPSConnectionPool(host='app.posthog.com', port=443): Max retries exceeded with url: /batch/ (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:997)')))
[2023-10-02 12:52:50,357] [ERROR] Error while running step:
IDE Protocol _receive_json timed out after 20 seconds. The message sent was: {'filepath': 'g:\\Devils-Covenant\\Assets\\Scripts\\UI\\StartMapUI.cs'}
IDE Protocol _receive_json timed out after 20 seconds: readFile
connection handler failed
Traceback (most recent call last):
  File "D:\conda-data\envs\continuedev\lib\asyncio\tasks.py", line 234, in __step
    result = coro.throw(exc)
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 959, in transfer_data
    message = await self.read_message()
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 1029, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 1104, in read_data_frame
    frame = await self.read_frame(max_size)
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 1161, in read_frame
    frame = await Frame.read(
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\framing.py", line 68, in read
    data = await reader(2)
  File "D:\conda-data\envs\continuedev\lib\asyncio\streams.py", line 707, in readexactly
    await self._wait_for_data('readexactly')
  File "D:\conda-data\envs\continuedev\lib\asyncio\streams.py", line 501, in _wait_for_data
    await self._waiter
  File "D:\conda-data\envs\continuedev\lib\asyncio\futures.py", line 285, in __await__
    yield self  # This tells Task to wait for completion.
  File "D:\conda-data\envs\continuedev\lib\asyncio\tasks.py", line 304, in __wakeup
    future.result()
  File "D:\conda-data\envs\continuedev\lib\asyncio\futures.py", line 196, in result
    raise exc
asyncio.exceptions.CancelledError

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

Traceback (most recent call last):
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\server.py", line 240, in handler
    await self.ws_handler(self)
  File "D:\conda-data\envs\continuedev\lib\site-packages\pylsp\python_lsp.py", line 135, in pylsp_ws
    async for message in websocket:
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 497, in __aiter__
    yield await self.recv()
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 568, in recv
    await self.ensure_open()
  File "D:\conda-data\envs\continuedev\lib\site-packages\websockets\legacy\protocol.py", line 944, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: sent 1011 (unexpected error) keepalive ping timeout; no close frame received

Additional note: My VS Code is on the D drive.

Aincvy avatar Oct 02 '23 05:10 Aincvy

@Aincvy apologies for not having seen this until now! I made an update roughly a few days ago that solved a related problem with other drives on windows. I don't believe this is the exact error that I was able to solve, but let me know if it was. Otherwise, will aim to take another look at this soon

sestinj avatar Oct 10 '23 21:10 sestinj

The problem I'm currently encountering seems to be something else. Here is some additional information:

  • Meilisearch automatically shuts down.
    • When I start the server, it is running.
    • After my VS Code extension connects to the server or when I send the first message, Meilisearch automatically shuts down.
    • I use the command netstat -ano | findstr "7700" to determine if the Meilisearch process is alive.
  • The messages I send receive a response, but the speed is very slow, and I'm not sure why.
    • When I send a message to the server using the VS Code extension, the server's console immediately prints [2023-10-11 12:22:25,964] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"hello"}}. However, it takes about 20 seconds for the "hello" in the VS Code extension to display a colorful border animation.
    • After that, it takes approximately 20-30 seconds for a response to appear. The time between the first character of the response and its completion is short, but the waiting time is long.
  • I manually started Meilisearch (downloaded from the Meilisearch website to my local machine).
    • What is this code doing? is effective, but /comment does not work.

Here are some logs.

[2023-10-10 20:00:57,940] [DEBUG] Removing session: 3dbb3501-0dea-4efd-b633-d00acca271fd

[2023-10-11 11:53:53,491] [DEBUG] ------ Begin Logs ------
[2023-10-11 11:53:55,172] [DEBUG] Starting MeiliSearch...
[2023-10-11 11:53:55,176] [DEBUG] Meilisearch started
[2023-10-11 11:57:04,397] [DEBUG] Accepted websocket connection from Address(host='127.0.0.1', port=11791)
[2023-10-11 11:57:04,406] [DEBUG] Received message while initializing workspaceDirectory
[2023-10-11 11:57:04,406] [DEBUG] Received message while initializing uniqueId
[2023-10-11 11:57:05,383] [DEBUG] New session: None
[2023-10-11 11:57:05,643] [DEBUG] Loaded Continue config file from C:\Users\world\.continue\config.py
[2023-10-11 11:57:26,757] [DEBUG] Starting context manager
[2023-10-11 11:57:47,872] [DEBUG] Sending session id: 5809c469-daae-4adc-99cc-93669e761072
[2023-10-11 11:57:47,881] [DEBUG] Loading Meilisearch index...
[2023-10-11 11:57:47,909] [DEBUG] Received websocket connection at url: ws://localhost:65432/gui/ws?session_id=5809c469-daae-4adc-99cc-93669e761072
[2023-10-11 11:57:47,910] [DEBUG] Session started
[2023-10-11 11:57:47,911] [DEBUG] Registered websocket for session 5809c469-daae-4adc-99cc-93669e761072
[2023-10-11 11:57:47,993] [WARNING] Failed to initialize ripgrepy: local variable 'rg_path' referenced before assignment
[2023-10-11 11:57:47,995] [DEBUG] Loaded 0 documents into meilisearch in 0.0019845962524414062 seconds for context provider search
[2023-10-11 11:57:47,995] [DEBUG] Loaded 0 documents into meilisearch in 0.0024805068969726562 seconds for context provider code
[2023-10-11 11:57:48,005] [DEBUG] Loaded 1 documents into meilisearch in 0.01190495491027832 seconds for context provider url
[2023-10-11 11:57:48,005] [DEBUG] Loaded 1 documents into meilisearch in 0.012400388717651367 seconds for context provider diff
[2023-10-11 11:57:48,006] [DEBUG] Loaded 1 documents into meilisearch in 0.012897253036499023 seconds for context provider terminal
[2023-10-11 11:57:50,754] [DEBUG] IDE websocket disconnected
[2023-10-11 11:57:50,754] [DEBUG] Closing ide websocket
[2023-10-11 11:58:11,829] [DEBUG] Accepted websocket connection from Address(host='127.0.0.1', port=11916)
[2023-10-11 11:58:11,831] [DEBUG] Error loading meilisearch index: 
[2023-10-11 11:58:12,243] [DEBUG] Using MeiliSearch at URL: http://localhost:7700
[2023-10-11 11:58:12,268] [DEBUG] Received message while initializing workspaceDirectory
[2023-10-11 11:58:12,268] [DEBUG] Received message while initializing uniqueId
[2023-10-11 11:58:33,332] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"hello"}}
[2023-10-11 12:05:47,105] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"who are you "}}
[2023-10-11 12:17:09,284] [WARNING] Failed to initialize ripgrepy: local variable 'rg_path' referenced before assignment
[2023-10-11 12:17:09,285] [WARNING] Error sending IDE message, websocket probably closed: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.
[2023-10-11 12:17:09,286] [DEBUG] Loaded 0 documents into meilisearch in 0.002480030059814453 seconds for context provider search
[2023-10-11 12:17:09,286] [DEBUG] Loaded 0 documents into meilisearch in 0.0019838809967041016 seconds for context provider code
[2023-10-11 12:17:09,295] [DEBUG] Loaded 1 documents into meilisearch in 0.01140904426574707 seconds for context provider terminal
[2023-10-11 12:17:09,295] [DEBUG] Loaded 1 documents into meilisearch in 0.011905193328857422 seconds for context provider url
[2023-10-11 12:17:09,296] [DEBUG] Loaded 1 documents into meilisearch in 0.012900114059448242 seconds for context provider diff
[2023-10-11 12:17:29,281] [DEBUG] Error loading meilisearch index:
[2023-10-11 12:17:29,281] [DEBUG] Loaded Meilisearch index
[2023-10-11 12:19:55,178] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"/clear"}}
[2023-10-11 12:22:25,964] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"hello"}}
[2023-10-11 12:25:24,994] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"what this code doing?"}}
[2023-10-11 12:27:05,319] [DEBUG] Received GUI message {"messageType":"main_input","data":{"input":"/comment"}}
[2023-10-11 12:28:29,586] [WARNING] Error sending IDE message, websocket probably closed: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.
[2023-10-11 12:28:49,591] [ERROR] Error while running step:
IDE Protocol _receive_json timed out after 20 seconds. The message sent was: {'filepath': 'g:\\Devils-Covenant\\Assets\\Scripts\\Player\\PlayerHand.cs'}
IDE Protocol _receive_json timed out after 20 seconds: readFile
[2023-10-11 12:29:10,666] [DEBUG] GUI websocket disconnected
[2023-10-11 12:29:10,666] [DEBUG] Closing gui websocket
[2023-10-11 12:29:10,679] [DEBUG] Removing session: 5809c469-daae-4adc-99cc-93669e761072
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "D:\conda-data\envs\continuedev\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 254, in run_asgi
    result = await self.app(self.scope, self.asgi_receive, self.asgi_send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
    return await self.app(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\fastapi\applications.py", line 276, in __call__
    await super().__call__(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\errors.py", line 149, in __call__
    await self.app(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\cors.py", line 75, in __call__
    await self.app(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
    raise exc
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
    await self.app(scope, receive, sender)
  File "D:\conda-data\envs\continuedev\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 21, in __call__
    raise e
  File "D:\conda-data\envs\continuedev\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\routing.py", line 341, in handle
    await self.app(scope, receive, send)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\routing.py", line 82, in app
    await func(session)
  File "D:\conda-data\envs\continuedev\lib\site-packages\fastapi\routing.py", line 289, in app
    await dependant.call(**values)
  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\gui.py", line 453, in websocket_endpoint
    await session_manager.remove_session(session.session_id)
  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\session_manager.py", line 115, in remove_session
    await self.sessions[session_id].autopilot.ide.websocket.close()
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 180, in close
    await self.send(
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 85, in send
    await self._send(message)
  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\exceptions.py", line 65, in sender
    await send(message)
  File "D:\conda-data\envs\continuedev\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 345, in asgi_send
    raise RuntimeError(msg % message_type)
RuntimeError: Unexpected ASGI message 'websocket.close', after sending 'websocket.close'.
INFO:     connection closed
INFO:     ('127.0.0.1', 1936) - "WebSocket /ide/ws?session_id=5809c469-daae-4adc-99cc-93669e761072" [accepted]
[2023-10-11 12:29:10,758] [DEBUG] Accepted websocket connection from Address(host='127.0.0.1', port=1936)
[2023-10-11 12:29:10,759] [DEBUG] IDE websocket disconnected
[2023-10-11 12:29:10,759] [DEBUG] Closing ide websocket
INFO:     connection open
INFO:     connection closed
[2023-10-11 12:29:31,831] [DEBUG] Received message while initializing workspaceDirectory
[2023-10-11 12:29:31,831] [DEBUG] Received message while initializing uniqueId

The startup script for the server is:

@echo off
call C:\Users\world\miniconda3\Scripts\activate.bat 
call conda activate continuedev  

set http_proxy=http://127.0.0.1:7890 & set https_proxy=http://127.0.0.1:7890
echo 'env ready, will execute commands!'
pause
pip install continuedev --upgrade  && python -m continuedev  

pause
Snipaste_2023-10-11_12-43-02

Aincvy avatar Oct 11 '23 04:10 Aincvy

@Aincvy thanks for the extra info. Could you share which model you are using? If it's a local model, sometimes it takes time for the weights to be loaded, potentially causing the long wait times.

sestinj avatar Oct 11 '23 17:10 sestinj

OpenAIFreeTrial without api key.

By the way, I think we should add more logs here. For example:

  • Sending a request to the continue server/OpenAI server.
  • Received the request, maybe we can also print what the received result is.
  • Sending the content to the GUI.
  • Finished sending, and so on.

This way, we can better determine which step the issue occurred in.

Sometimes the following logs are displayed, and it seems like the connection is disconnected. Do you send heartbeat packets?

[2023-10-12 10:52:49,876] [CRITICAL] Exception caught from async task: Traceback (most recent call last):

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 438, in _run_singular_step
    observation = await step(self.continue_sdk)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\main.py", line 376, in __call__
    return await self.run(sdk)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\plugins\steps\chat.py", line 121, in run
    await sdk.update_ui()

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\sdk.py", line 308, in update_ui
    await self.__autopilot.update_subscribers()

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 233, in update_subscribers
    await callback(full_state)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\session_manager.py", line 84, in on_update
    await session_manager.send_ws_data(

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\session_manager.py", line 175, in send_ws_data
    await self.sessions[session_id].ws.send_json(

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 173, in send_json
    await self.send({"type": "websocket.send", "text": text})

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 85, in send
    await self._send(message)

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\exceptions.py", line 65, in sender
    await send(message)

  File "D:\conda-data\envs\continuedev\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 345, in asgi_send
    raise RuntimeError(msg % message_type)

RuntimeError: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\libs\util\create_async_task.py", line 21, in callback
    future.result()

  File "D:\conda-data\envs\continuedev\lib\asyncio\futures.py", line 201, in result
    raise self._exception.with_traceback(self._exception_tb)

  File "D:\conda-data\envs\continuedev\lib\asyncio\tasks.py", line 232, in __step
    result = coro.send(None)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 658, in accept_user_input
    await self.run_from_step(UserInputStep(user_input=user_input))

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 582, in run_from_step
    await self._run_singular_step(next_step, is_future_step)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 492, in _run_singular_step
    await self.update_subscribers()

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\core\autopilot.py", line 233, in update_subscribers
    await callback(full_state)

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\session_manager.py", line 84, in on_update
    await session_manager.send_ws_data(

  File "D:\conda-data\envs\continuedev\lib\site-packages\continuedev\server\session_manager.py", line 175, in send_ws_data
    await self.sessions[session_id].ws.send_json(

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 173, in send_json
    await self.send({"type": "websocket.send", "text": text})

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\websockets.py", line 85, in send
    await self._send(message)

  File "D:\conda-data\envs\continuedev\lib\site-packages\starlette\middleware\exceptions.py", line 65, in sender
    await send(message)

  File "D:\conda-data\envs\continuedev\lib\site-packages\uvicorn\protocols\websockets\websockets_impl.py", line 345, in asgi_send
    raise RuntimeError(msg % message_type)

RuntimeError: Unexpected ASGI message 'websocket.send', after sending 'websocket.close'.

Aincvy avatar Oct 12 '23 02:10 Aincvy

@Aincvy For the websocket errors, I've just pushed a fix to the preview branch (it looked to be a matter of us not checking whether the connection was closed before sending certain messages)

For the speed issue, I'm going to set up replicas of the server deployment that should give faster response times when not near the current one we have (haven't done this yet, but I'll let you know when they're ready) - but I would be curious to make sure: are the response times significantly faster if you use your own API key (in which case it wouldn't go through our proxy server)?

sestinj avatar Oct 12 '23 22:10 sestinj

Change code to async with aiohttp.ClientSession(trust_env=True) as session: of https://github.com/continuedev/continue/blob/b281b56395f58410e05692de2e15e742840d2434/server/continuedev/server/meilisearch_server.py#L17C20-L17C20

document: https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession. Then I can use http_proxy, ... env vars to download meilisearch.exe.

It's slow too, when I use my API key.

The http_proxy env var not works with openai python library, I need use the from continuedev.libs.llm.openai import OpenAI class, and set the proxy property. And sometimes I cannot get the response, it says The request failed. Please check your internet connection and try again. If this issue persists, you can use our API key for free by going to VS Code settings and changing the value of continue.OPENAI_API_KEY to "".

When I using curl command to test api.openai.com, I can get response in 2~4 seconds. test data: https://stackoverflow.com/a/75043933/11226492 The same proxy server address is used for configuring from continuedev.libs.llm.openai import OpenAI.

And, the slash command /config is also slow. Same as other chat content.

Aincvy avatar Oct 13 '23 08:10 Aincvy

@Aincvy Just made the trust_env change to all requests, and it will be ready in v0.1.23 of the pre-release extension. I also changed the OpenAI request so that it should accept the HTTP_PROXY env var as well.

As for the slow responses, is it still faster than Continue if you use gpt-4 for a curl request?:

curl https://api.openai.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Hello!"
      }
    ],
    "stream": true
  }'

sestinj avatar Oct 13 '23 18:10 sestinj

I've recorded two videos, which should be sufficient to illustrate some issues.

https://github.com/continuedev/continue/assets/8110347/e2b348df-3e38-4814-9dad-70a152ef3313

https://www.veed.io/view/41c92852-09b2-425d-a350-cdfc91351208?panel=share

This video is a bit long, you can watch it at 2x or 3x speed. The time I received the response content is around the 1 minute and 33 seconds mark in the video.

This is my first time using the platform for the second video. If you can't watch it, please let me know.

Aincvy avatar Oct 14 '23 14:10 Aincvy

@Aincvy thanks for sharing these. I have one idea that will help determine what I can do to solve the problem.

If you use the GGML class in config.py instead of the OpenAI class, this makes the request manually, instead of using the OpenAI Python library. There's a chance that it will be able to give the quick response time like the curl request.

Example:

...
models=Models(
  default=GGML(server_url="https://api.openai.com", api_key="<API_KEY>")
  )
...

sestinj avatar Oct 14 '23 18:10 sestinj

There's no difference, there's always a long waiting time before sending the request.

Aincvy avatar Oct 15 '23 07:10 Aincvy

@Aincvy sorry, I didn't add the proxy when I shared the GGML example, but did you end up adding this yourself? This seems to be the only difference between the curl command and what the GGML class would be doing.

The best way to simplify this problem would probably be to get the equivalent of the curl command working with Python. If you can get this to work, then I'll be sure that we can fix it in Continue:

import aiohttp
import json

async def send_request():
    url = "https://api.openai.com/v1/chat/completion"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {YOUR_OPENAI_API_KEY}"
    }
    data = {
        "model": "gpt-4",
        "messages": [
            {
                "role": "system",
                "content": "You are a helpful assistant."
            },
            {
                "role": "user",
                "content": "Hello!"
            }
        ],
        "stream": True
    }
    proxy = "http://localhost:7890"

    async with aiohttp.ClientSession() as session:
        async with session.post(url, headers=headers, json=data, proxy=proxy) as response:
            async for line in response.content.iter_any():
                print(line.decode('utf-8'))

# Replace YOUR_OPENAI_API_KEY with your actual API key
YOUR_OPENAI_API_KEY = "YOUR_API_KEY"
await send_request()

sestinj avatar Oct 15 '23 17:10 sestinj

image

https://api.openai.com/v1/chat/completion => https://api.openai.com/v1/chat/completions

await send_request() =>

async def main():
    start_time = time.time()  # 记录开始时间

    await send_request()

    end_time = time.time()  # 记录结束时间
    execution_time = end_time - start_time  # 计算执行时间

    print(f"function execute time: {execution_time} seconds")

asyncio.run(main())

I think the proxy should be effective because I saw the request records for api.openai.com in the connections of Clash for Windows, and I also saw the responses from OpenAI. Additionally, there are no other programs on my Windows development machine that would access OpenAI.

I think the issue lies not in requesting OpenAI, but in the excessive waiting time before making the request to OpenAI.

Aincvy avatar Oct 16 '23 02:10 Aincvy