Closed johnd0e closed 7 months ago
It's now fixed and available right now. Just request a pull.
P.S. Claude Stream still needs a little more time to implement.
Unfortunately I cannot confirm the fix. Streaming still does not work neither with Bard, nor with Chatgpt
Can you tell me what your output is? Do you pull the latest updates from the repository? Because the released tag is still old.
I'm on commit d6243237101e11bcd2517b3744c7dfe2bc07010a, I have pulled it with git, like you said.
With endpoints /bard
, /claude
, /chatgpt
, and /claude/v1/chat/completions
behavior is the same - I send request, wait (significal delay) and get (pretty big) response in one piece, without streaming.
E.g. my request:
@curl --request POST ^
--url http://127.0.0.1:8000/chatgpt ^
--header "accept: application/json" ^
--header "content-type: application/json" ^
-T completions.json
{
"session_id": "",
"message": "Sing a song of Fire and Ice",
"stream": true
}
The response:
In case of /v1/chat/completions
endpoint the things are also incorrect.
Here response seems correct, but again, I get all these messages at once, after significant time.
'Streaming' means that I receive response(s) chunk by chunk, immediately when they ready.
Interesting, Are you trying streaming with examples?
python examples_chatgpt1.py True
Of course I did, with same effect.
Actually I don't have access to my system for a couple days, but I think we should start debugging this by looking at the Python version and environment.
What Python version are you using?
Python 3.10.11
Can you please share a screenshot of the output results in the API Docs:
http://127.0.0.1:8000/docs
Try with false
and true
for streaming for ChatGPT or Bard.
I have tried both chatgpt and bard, and here are my observations.
"stream": true
both outputs plain text, with new lines"stream": false
:
\"
and newlines as \n
{"choices":[{"message":{"content":["...
Thus:
"stream": false
seems not useful at all (why may we need such quoted text?)"stream": true
output is good, but still - it appears all in one time. Not streamed.Thank you John There was a silly mistake in the main file that used "return" instead of "yield".
I can't test the result right now, I just made changes on the mobile phone editor and pushed a commit, but there should be no problem.
Just submitting a pull request for this fix; For Bard and ChatGPT, I'm not sure if Claude is working properly with this fix.
There was a silly mistake in the main file that used "return" instead of "yield".
At the moment there are many such places in code, preventing server from launching. And it is not enough to replace there all occurrences of "return" with "yield", because it lead to runtime error during request:
←[31mERROR←[0m: Exception in ASGI application
Traceback (most recent call last):
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\encoders.py", line 230, in jsonable_encoder
data = dict(obj)
TypeError: 'async_generator' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\encoders.py", line 235, in jsonable_encoder
data = vars(obj)
TypeError: vars() argument must have __dict__ attribute
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\AI\WebAI-to-API\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 408, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "D:\AI\WebAI-to-API\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\applications.py", line 289, in __call__
await super().__call__(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\applications.py", line 122, in __call__
await self.middleware_stack(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
raise exc
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\middleware\cors.py", line 83, in __call__
await self.app(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\middleware\exceptions.py", line 79, in __call__
raise exc
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\middleware\exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 20, in __call__
raise e
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py", line 17, in __call__
await self.app(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\routing.py", line 718, in __call__
await route.handle(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\routing.py", line 276, in handle
await self.app(scope, receive, send)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\starlette\routing.py", line 66, in app
response = await func(request)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\routing.py", line 291, in app
content = await serialize_response(
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\routing.py", line 179, in serialize_response
return jsonable_encoder(response_content)
File "D:\AI\WebAI-to-API\venv\lib\site-packages\fastapi\encoders.py", line 238, in jsonable_encoder
raise ValueError(errors) from e
ValueError: [TypeError("'async_generator' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
As I see in code, streaming just is not yet implemented.
E.g. https://github.com/Amm1rr/WebAI-to-API/blob/eafd56505a732f96d93a038fbbb036042b5cdca8/src/main.py#L25
For streaming here should be AsyncChatbot
None of following examples produces streaming:
P.S. Same with direct curl requests.