Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonra1993 committed May 18, 2024
2 parents f7c283a + 132828f commit c789f09
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 196 deletions.
Binary file modified .DS_Store
Binary file not shown.
86 changes: 42 additions & 44 deletions create_fastapi_project/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,66 +47,64 @@ def install_template(root: str, template: ITemplate, app_name: str):
if has_pyproject:
dependencies = [
"fastapi[all]",
"fastapi-pagination[sqlalchemy]@^0.12.7",
"asyncer@^0.0.2",
"httpx@^0.24.1",
"fastapi-pagination[sqlalchemy]",
"asyncer",
"httpx",
]
dev_dependencies = [
"pytest@^7.4.0",
"mypy@^1.5.0",
"ruff@^0.0.284",
"black@^23.7.0",
"pytest",
"mypy",
"ruff",
"black",
]
if template == ITemplate.langchain_basic:
langchain_dependencies = [
"langchain@^0.0.265",
"openai@^0.27.8",
"adaptive-cards-py@^0.0.7",
"google-search-results@^2.4.2",
"langchain",
"openai",
"adaptive-cards-py",
"google-search-results",
]
frontend_dependencies = [
"streamlit",
"websockets",
]
dependencies[0] = "fastapi[all]@^0.99.1"
dependencies.extend(langchain_dependencies)
if template == ITemplate.full:
full_dependencies = [
"alembic@^1.10.2",
"asyncpg@^0.27.0",
"sqlmodel@^0.0.8",
"python-jose@^3.3.0",
"cryptography@^38.0.3",
"passlib@^1.7.4",
"SQLAlchemy-Utils@^0.38.3",
"SQLAlchemy@^1.4.40",
"minio@^7.1.13",
"Pillow@^9.4.0",
"watchfiles@^0.18.1",
"asyncer@^0.0.2",
"httpx@^0.23.1",
"pandas@^1.5.3",
"openpyxl@^3.0.10",
"redis@^4.5.1",
"fastapi-async-sqlalchemy@^0.3.12",
"oso@^0.26.4",
"celery@^5.2.7",
"transformers@^4.28.1",
"requests@^2.29.0",
"wheel@^0.40.0",
"setuptools@^67.7.2",
"langchain@^0.0.262",
"openai@^0.27.5",
"celery-sqlalchemy-scheduler@^0.3.0",
"psycopg2-binary@^2.9.5",
"fastapi-limiter@^0.1.5 ",
"fastapi-pagination[sqlalchemy]@^0.11.4 ",
"fastapi-cache2[redis]@^0.2.1 ",
"alembic",
"asyncpg",
"sqlmodel",
"python-jose",
"cryptography",
"passlib",
"SQLAlchemy-Utils",
"SQLAlchemy",
"minio",
"Pillow",
"watchfiles",
"asyncer",
"httpx",
"pandas",
"openpyxl",
"redis",
"fastapi-async-sqlalchemy",
"oso",
"celery",
"transformers",
"requests",
"wheel",
"setuptools",
"langchain",
"openai",
"celery-sqlalchemy-scheduler",
"psycopg2-binary",
"fastapi-limiter",
"fastapi-pagination[sqlalchemy]",
"fastapi-cache2[redis]",
]
full_dev_dependencies = [
"pytest-asyncio@^0.21.1",
"pytest-asyncio",
]
dependencies[0] = "fastapi[all]@^0.95.2"
dependencies.extend(full_dependencies)
dev_dependencies.extend(full_dev_dependencies)

Expand Down
5 changes: 3 additions & 2 deletions create_fastapi_project/templates/basic/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PIP_DEFAULT_TIMEOUT=100
WORKDIR /code
# Install Poetry
RUN apt clean && apt update && apt install curl -y
Expand All @@ -13,7 +14,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

ENV PYTHONPATH=/code
EXPOSE 8000
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ModeEnum(str, Enum):
testing = "testing"


class Settings(BaseSettings):
class Settings(BaseSettings, extra='ignore'):
PROJECT_NAME: str = "app"
BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl]
MODE: ModeEnum = ModeEnum.development
Expand All @@ -21,7 +21,7 @@ class Settings(BaseSettings):

class Config:
case_sensitive = True
env_file = os.path.expanduser("~/.env")
env_file = os.path.expanduser("../../.env")


settings = Settings()
5 changes: 3 additions & 2 deletions create_fastapi_project/templates/full/backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PIP_DEFAULT_TIMEOUT=100
WORKDIR /code
# Install Poetry
RUN apt clean && apt update && apt install curl -y
Expand All @@ -13,7 +14,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

ENV PYTHONPATH=/code
EXPOSE 8000
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.11-slim
ENV PYTHONUNBUFFERED=1
ENV PIP_DEFAULT_TIMEOUT=100
WORKDIR /code
# Install Poetry
RUN apt clean && apt update && apt install curl -y
Expand All @@ -13,7 +14,7 @@ COPY app/pyproject.toml app/poetry.lock* /code/

# Allow installing dev dependencies to run tests
ARG INSTALL_DEV=false
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --only main ; fi"

ENV PYTHONPATH=/code
EXPOSE 8000
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pydantic import AnyHttpUrl, BaseSettings
from pydantic import AnyHttpUrl, field_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from enum import Enum


Expand All @@ -10,18 +11,26 @@ class ModeEnum(str, Enum):


class Settings(BaseSettings):
PROJECT_NAME: str = "app"
BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl]
MODE: ModeEnum = ModeEnum.development
PROJECT_NAME: str = "app"
API_VERSION: str = "v1"
API_V1_STR: str = f"/api/{API_VERSION}"
OPENAI_API_KEY: str
UNSPLASH_API_KEY: str
SERP_API_KEY: str

class Config:
case_sensitive = True
env_file = os.path.expanduser("~/.env")
BACKEND_CORS_ORIGINS: list[str] | list[AnyHttpUrl]
@field_validator("BACKEND_CORS_ORIGINS")
def assemble_cors_origins(cls, v: str | list[str]) -> list[str] | str:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)

model_config = SettingsConfigDict(
case_sensitive=True, env_file=os.path.expanduser("~/.env")
)


settings = Settings()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pydantic import BaseModel, validator
from pydantic import BaseModel, field_validator
from app.utils.uuid6 import uuid7
from typing import Any

Expand All @@ -19,20 +19,20 @@ class IChatResponse(BaseModel):
type: str
suggested_responses: list[str] = []

@validator("id", "message_id", pre=True, allow_reuse=True)
@field_validator("id", "message_id")
def check_ids(cls, v):
if v == "" or v is None:
return str(uuid7())
return v

@validator("sender")
@field_validator("sender")
def sender_must_be_bot_or_you(cls, v):
if v not in ["bot", "you"]:
raise ValueError("sender must be bot or you")
return v

@validator("type")
@field_validator("type")
def validate_message_type(cls, v):
if v not in ["start", "stream", "end", "error", "info"]:
raise ValueError("type must be start, stream or end")
return v
return v
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,25 @@
from fastapi_pagination import Params, Page
from fastapi_pagination.bases import AbstractPage, AbstractParams
from pydantic import Field
from pydantic.generics import GenericModel
from pydantic import BaseModel

DataType = TypeVar("DataType")
T = TypeVar("T")


class PageBase(Page[T], Generic[T]):
previous_page: int | None = Field(
None, description="Page number of the previous page"
default=None, description="Page number of the previous page"
)
next_page: int | None = Field(
default=None, description="Page number of the next page"
)
next_page: int | None = Field(None, description="Page number of the next page")


class IResponseBase(GenericModel, Generic[T]):
class IResponseBase(BaseModel, Generic[T]):
message: str = ""
meta: dict = {}
data: T | None
meta: dict | Any | None = {}
data: T | None = None


class IGetResponsePaginated(AbstractPage[T], Generic[T]):
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit c789f09

Please sign in to comment.