Das erste Problem besteht darin, dass die Swagger-Benutzeroberfläche in FastAPI eine alte Antwort anzeigt:

Die oben gezeigte Swagger-Benutzeroberfläche wird von der Cloud Run-URL /docs bereitgestellt, nicht von eine lokale FastAPI-Instanz.
CURL-Befehl:
Code: Select all
curl -X 'POST' \
'https://vci-188125714482.asia-south1.run.app/rag' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "yo"
}'
Code: Select all
https://vci-188125714482.asia-south1.run.app/ragCode: Select all
{
"answer": "AI result for: yo"
}
Code: Select all
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
content-length: 30
content-type: application/json
date: Mon,29 Dec 2025 11:33:43 GMT
server: Google Frontend
x-cloud-trace-context: 2b70f32dff26dc2279b45c2643b5f0b5;o=1
Code: Select all
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from fastapi.responses import JSONResponse
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=False,
allow_methods=["*"], # MUST be *
allow_headers=["*"], # MUST be *
)
class Query(BaseModel):
query: str
@app.post("/rag")
async def rag(data: Query):
return {
"answer": f"You asked: {data.query}",
"sources": []
}
Die Repository-Struktur sieht so aus:
Code: Select all
VCI/
├── main.py (old backend code)
├── vc-rag-backend/
│ ├── main.py (new backend code shown above)
│ ├── Dockerfile
│ └── requirements.txt
an /rag eine 405-Antwort zurückgibt, was zu einem CORS-Fehler im Frontend führt:

Cloud Run wird über einen Cloud Build-Trigger bereitgestellt, der mit verbunden ist GitHub. Der Trigger ist für die Verwendung einer Docker-Datei konfiguriert, aber ich bin mir nicht sicher, ob er aus dem Repository-Stammverzeichnis oder aus vc-rag-backend/ erstellt wird.
Wie behebe ich diese beiden Probleme?
Mobile version