summaryrefslogtreecommitdiffstats
path: root/g4f/api
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-11-07 17:38:15 +0100
committerGitHub <noreply@github.com>2023-11-07 17:38:15 +0100
commitf7156766d4216c0ed829c5515c4c153adfb1b0a5 (patch)
tree57e7583aa5f1f6911cd245356a9474e05c0bdcf9 /g4f/api
parentMerge pull request #1218 from ostix360/main (diff)
parentfix: api streaming TypeError: Object of type generator is not JSON serializable (diff)
downloadgpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar.gz
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar.bz2
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar.lz
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar.xz
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.tar.zst
gpt4free-f7156766d4216c0ed829c5515c4c153adfb1b0a5.zip
Diffstat (limited to 'g4f/api')
-rw-r--r--g4f/api/__init__.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/g4f/api/__init__.py b/g4f/api/__init__.py
index 43bca2a5..ad3b0db4 100644
--- a/g4f/api/__init__.py
+++ b/g4f/api/__init__.py
@@ -1,4 +1,5 @@
from fastapi import FastAPI, Response, Request
+from fastapi.responses import StreamingResponse
from typing import List, Union, Any, Dict, AnyStr
from ._tokenizer import tokenize
from .. import BaseProvider
@@ -151,7 +152,7 @@ class Api:
except GeneratorExit:
pass
- return Response(content=json.dumps(streaming(), indent=4), media_type="application/json")
+ return StreamingResponse(streaming(), media_type="text/event-stream")
@self.app.post("/v1/completions")
async def completions():