Skip to content

Commit

Permalink
feat: Make OpenAPI spec usable by custom GPTs
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusschiesser committed Dec 11, 2024
1 parent d31910a commit a73a49b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-snails-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-llama": patch
---

Make OpenAPI spec usable by custom GPTs
6 changes: 5 additions & 1 deletion templates/types/streaming/fastapi/app/api/routers/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ def get_query_engine() -> BaseQueryEngine:
return index.as_query_engine()


@r.get("/")
@r.get(
"/",
summary="Call the get information from a knowledge base",
description="Get information from the knowledge base using a search query parameter",
)
async def query_request(
query: str,
) -> str:
Expand Down
15 changes: 13 additions & 2 deletions templates/types/streaming/fastapi/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# flake8: noqa: E402
from app.config import DATA_DIR, STATIC_DIR
from dotenv import load_dotenv
import toml

load_dotenv()

Expand All @@ -16,14 +17,24 @@
from fastapi.responses import RedirectResponse
from fastapi.staticfiles import StaticFiles

app = FastAPI()

init_settings()
init_observability()

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

servers = []
# Add the fly.dev URL to the OpenAPI spec
if os.path.exists("fly.toml"):
try:
with open("fly.toml") as f:
fly_config = toml.load(f)
app_name = fly_config["app"]
servers = [{"url": f"https://{app_name}.fly.dev"}]
except Exception as e:
logger.warning(f"Failed to read fly.toml: {e}")
app = FastAPI(servers=servers)


def mount_static_files(directory, path, html=False):
if os.path.exists(directory):
Expand Down
1 change: 1 addition & 0 deletions templates/types/streaming/fastapi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ aiostream = "^0.5.2"
cachetools = "^5.3.3"
llama-index = "^0.12.1"
rich = "^13.9.4"
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
mypy = "^1.8.0"
Expand Down

0 comments on commit a73a49b

Please sign in to comment.