Skip to content

Commit a73a49b

Browse files
feat: Make OpenAPI spec usable by custom GPTs
1 parent d31910a commit a73a49b

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-llama": patch
3+
---
4+
5+
Make OpenAPI spec usable by custom GPTs

templates/types/streaming/fastapi/app/api/routers/query.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ def get_query_engine() -> BaseQueryEngine:
1616
return index.as_query_engine()
1717

1818

19-
@r.get("/")
19+
@r.get(
20+
"/",
21+
summary="Call the get information from a knowledge base",
22+
description="Get information from the knowledge base using a search query parameter",
23+
)
2024
async def query_request(
2125
query: str,
2226
) -> str:

templates/types/streaming/fastapi/main.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# flake8: noqa: E402
22
from app.config import DATA_DIR, STATIC_DIR
33
from dotenv import load_dotenv
4+
import toml
45

56
load_dotenv()
67

@@ -16,14 +17,24 @@
1617
from fastapi.responses import RedirectResponse
1718
from fastapi.staticfiles import StaticFiles
1819

19-
app = FastAPI()
20-
2120
init_settings()
2221
init_observability()
2322

2423
environment = os.getenv("ENVIRONMENT", "dev") # Default to 'development' if not set
2524
logger = logging.getLogger("uvicorn")
2625

26+
servers = []
27+
# Add the fly.dev URL to the OpenAPI spec
28+
if os.path.exists("fly.toml"):
29+
try:
30+
with open("fly.toml") as f:
31+
fly_config = toml.load(f)
32+
app_name = fly_config["app"]
33+
servers = [{"url": f"https://{app_name}.fly.dev"}]
34+
except Exception as e:
35+
logger.warning(f"Failed to read fly.toml: {e}")
36+
app = FastAPI(servers=servers)
37+
2738

2839
def mount_static_files(directory, path, html=False):
2940
if os.path.exists(directory):

templates/types/streaming/fastapi/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ aiostream = "^0.5.2"
2121
cachetools = "^5.3.3"
2222
llama-index = "^0.12.1"
2323
rich = "^13.9.4"
24+
toml = "^0.10.2"
2425

2526
[tool.poetry.group.dev.dependencies]
2627
mypy = "^1.8.0"

0 commit comments

Comments
 (0)