diff --git a/templates/types/simple/fastapi/app/api/routers/chat.py b/templates/types/simple/fastapi/app/api/routers/chat.py index 81f602edbeae66c5850b30a6183c009ab4b1e014..e728db0dc3d07dfc13b09468235c94a903d3ce7d 100644 --- a/templates/types/simple/fastapi/app/api/routers/chat.py +++ b/templates/types/simple/fastapi/app/api/routers/chat.py @@ -1,10 +1,10 @@ from typing import List -from app.utils.index import get_index from fastapi import APIRouter, Depends, HTTPException, status from llama_index import VectorStoreIndex from llama_index.llms.base import MessageRole, ChatMessage from pydantic import BaseModel +from app.context import get_index chat_router = r = APIRouter() diff --git a/templates/types/simple/fastapi/app/utils/index.py b/templates/types/simple/fastapi/app/context.py similarity index 86% rename from templates/types/simple/fastapi/app/utils/index.py rename to templates/types/simple/fastapi/app/context.py index 530935b7ec84c93bafee5e4d37265f4e4411fd65..48ca79a90c57bcd14f06f32642c903fa814703b1 100644 --- a/templates/types/simple/fastapi/app/utils/index.py +++ b/templates/types/simple/fastapi/app/context.py @@ -1,5 +1,5 @@ -import logging import os +import logging from llama_index import ( SimpleDirectoryReader, @@ -10,16 +10,17 @@ from llama_index import ( ) from llama_index.llms import OpenAI - STORAGE_DIR = "./storage" # directory to cache the generated index DATA_DIR = "./data" # directory containing the documents to index -service_context = ServiceContext.from_defaults( - llm=OpenAI(model="gpt-3.5-turbo") -) - +def create_base_context(): + model = os.getenv("MODEL", "gpt-3.5-turbo") + return ServiceContext.from_defaults( + llm=OpenAI(model=model), + ) def get_index(): + service_context = create_base_context() logger = logging.getLogger("uvicorn") # check if storage already exists if not os.path.exists(STORAGE_DIR): diff --git a/templates/types/simple/fastapi/app/utils/__init__.py b/templates/types/simple/fastapi/app/utils/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/templates/types/simple/fastapi/pyproject.toml b/templates/types/simple/fastapi/pyproject.toml index 59d182bbb47a8d0ee06de3550f2c7fbf954a3901..10d1d609ecc292ab9822ee2b12c8098038a0f1c5 100644 --- a/templates/types/simple/fastapi/pyproject.toml +++ b/templates/types/simple/fastapi/pyproject.toml @@ -9,7 +9,7 @@ readme = "README.md" python = "^3.11,<3.12" fastapi = "^0.104.1" uvicorn = { extras = ["standard"], version = "^0.23.2" } -llama-index = "^0.8.56" +llama-index = "^0.9.19" pypdf = "^3.17.0" python-dotenv = "^1.0.0"