change to stream respsonse (#5285)

* change to stream respsonse

* Changed default log level to INFO
This commit is contained in:
Swifty
2023-09-21 14:57:41 +02:00
committed by GitHub
parent a9ad805ba9
commit 12f3a321b7
2 changed files with 7 additions and 11 deletions

View File

@@ -2,6 +2,8 @@ import asyncio
import os
import pathlib
from uuid import uuid4
from fastapi.responses import StreamingResponse
from io import BytesIO
from fastapi import APIRouter, FastAPI, UploadFile
from fastapi.middleware.cors import CORSMiddleware
@@ -196,17 +198,11 @@ class Agent:
artifact = await self.db.get_artifact(artifact_id)
file_path = os.path.join(artifact.relative_path, artifact.file_name)
retrieved_artifact = self.workspace.read(task_id=task_id, path=file_path)
path = artifact.file_name
with open(path, "wb") as f:
f.write(retrieved_artifact)
except NotFoundError as e:
raise
except FileNotFoundError as e:
raise
except Exception as e:
raise
return FileResponse(
# Note: mimetype is guessed in the FileResponse constructor
path=path,
filename=artifact.file_name,
)
return StreamingResponse(BytesIO(retrieved_artifact), media_type='application/octet-stream', headers={'Content-Disposition': f'attachment; filename={artifact.file_name}'})

View File

@@ -179,17 +179,17 @@ logging_config: dict = dict(
"h": {
"class": "logging.StreamHandler",
"formatter": "console",
"level": logging.DEBUG,
"level": logging.INFO,
},
},
root={
"handlers": ["h"],
"level": logging.DEBUG,
"level": logging.INFO,
},
loggers={
"autogpt": {
"handlers": ["h"],
"level": logging.DEBUG,
"level": logging.INFO,
"propagate": False,
},
},