Spaces:
Running
Running
Ryan Farahani Cursor commited on
Commit ·
3ff5922
1
Parent(s): e4b6d93
Fix async file read bug causing 'coroutine object is not subscriptable'
Browse filesFastAPI UploadFile.read() is async and returns a coroutine. The sync
ingest_file() was receiving the coroutine instead of bytes. Now we
await the read in the async endpoint and wrap the content in BytesIO.
Co-authored-by: Cursor <cursoragent@cursor.com>
api.py
CHANGED
|
@@ -14,6 +14,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 14 |
from pydantic import BaseModel
|
| 15 |
from typing import List
|
| 16 |
import os
|
|
|
|
| 17 |
|
| 18 |
app = FastAPI(title="DocMind AI API", version="3.0")
|
| 19 |
|
|
@@ -133,8 +134,12 @@ async def upload_document(file: UploadFile = File(...)):
|
|
| 133 |
)
|
| 134 |
|
| 135 |
try:
|
| 136 |
-
rag
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
type_labels = {
|
| 140 |
".pdf": "PDF Document",
|
|
|
|
| 14 |
from pydantic import BaseModel
|
| 15 |
from typing import List
|
| 16 |
import os
|
| 17 |
+
import io
|
| 18 |
|
| 19 |
app = FastAPI(title="DocMind AI API", version="3.0")
|
| 20 |
|
|
|
|
| 134 |
)
|
| 135 |
|
| 136 |
try:
|
| 137 |
+
rag = get_rag()
|
| 138 |
+
content = await file.read()
|
| 139 |
+
buf = io.BytesIO(content)
|
| 140 |
+
buf.name = filename
|
| 141 |
+
buf.filename = filename
|
| 142 |
+
chunks = rag.ingest_file(buf)
|
| 143 |
|
| 144 |
type_labels = {
|
| 145 |
".pdf": "PDF Document",
|