22import shutil
33from enum import Enum
44from dotenv import dotenv_values
5- from create_fastapi_project .helpers .install import add_configuration_to_pyproject , install_dependencies
5+ from create_fastapi_project .helpers .install import (
6+ add_configuration_to_pyproject ,
7+ install_dependencies ,
8+ )
9+ 610
711class ITemplate (str , Enum ):
812 basic = "basic"
913 langchain_basic = "langchain_basic"
10- full = "full"
14+ full = "full"
15+ 1116
1217def install_template (root : str , template : ITemplate , app_name : str ):
1318 print (f"Initializing project with template: { template } " )
@@ -32,45 +37,107 @@ def install_template(root: str, template: ITemplate, app_name: str):
3237 dirs_exist_ok = True ,
3338 )
3439
35- 3640 poetry_path = ""
3741 if template == ITemplate .full or template == ITemplate .langchain_basic :
3842 # TODO: CHECK PATHS IN MACOS AND WINDOWS | (os.path.join)
3943 poetry_path = os .path .join (root , "backend" , "app" )
44+ poetry_frontend_path = os .path .join (root , "frontend" , "app" )
4045
4146 else :
4247 poetry_path = os .path .join (root , "app" )
43-
48+ 4449 has_pyproject = add_configuration_to_pyproject (poetry_path )
4550
4651 if has_pyproject :
47- dependencies = ["fastapi[all]" , "fastapi-pagination[sqlalchemy]@^0.12.7" , "asyncer@^0.0.2" , "httpx@^0.24.1" ]
52+ dependencies = [
53+ "fastapi[all]" ,
54+ "fastapi-pagination[sqlalchemy]@^0.12.7" ,
55+ "asyncer@^0.0.2" ,
56+ "httpx@^0.24.1" ,
57+ ]
58+ dev_dependencies = [
59+ "pytest@^7.4.0" ,
60+ "mypy@^1.5.0" ,
61+ "ruff@^0.0.284" ,
62+ "black@^23.7.0" ,
63+ ]
4864 if template == ITemplate .langchain_basic :
4965 langchain_dependencies = [
5066 "langchain@^0.0.265" ,
5167 "openai@^0.27.8" ,
5268 "adaptive-cards-py@^0.0.7" ,
53- "google-search-results@^2.4.2"
69+ "google-search-results@^2.4.2" ,
70+ ]
71+ frontend_dependencies = [
72+ "streamlit" ,
73+ "websockets" ,
5474 ]
5575 dependencies [0 ] = "fastapi[all]@^0.99.1"
5676 dependencies .extend (langchain_dependencies )
57- dev_dependencies = ["pytest@^5.2" , "mypy@^1.5.0" , "ruff@^0.0.284" , "black@^23.7.0" ]
77+ if template == ITemplate .full :
78+ full_dependencies = [
79+ "alembic@^1.10.2" ,
80+ "asyncpg@^0.27.0" ,
81+ "sqlmodel@^0.0.8" ,
82+ "python-jose@^3.3.0" ,
83+ "cryptography@^38.0.3" ,
84+ "passlib@^1.7.4" ,
85+ "SQLAlchemy-Utils@^0.38.3" ,
86+ "SQLAlchemy@^1.4.40" ,
87+ "minio@^7.1.13" ,
88+ "Pillow@^9.4.0" ,
89+ "watchfiles@^0.18.1" ,
90+ "asyncer@^0.0.2" ,
91+ "httpx@^0.23.1" ,
92+ "pandas@^1.5.3" ,
93+ "openpyxl@^3.0.10" ,
94+ "redis@^4.5.1" ,
95+ "fastapi-async-sqlalchemy@^0.3.12" ,
96+ "oso@^0.26.4" ,
97+ "celery@^5.2.7" ,
98+ "transformers@^4.28.1" ,
99+ "requests@^2.29.0" ,
100+ "wheel@^0.40.0" ,
101+ "setuptools@^67.7.2" ,
102+ "langchain@^0.0.262" ,
103+ "openai@^0.27.5" ,
104+ "celery-sqlalchemy-scheduler@^0.3.0" ,
105+ "psycopg2-binary@^2.9.5" ,
106+ "fastapi-limiter@^0.1.5 " ,
107+ "fastapi-pagination[sqlalchemy]@^0.11.4 " ,
108+ "fastapi-cache2[redis]@^0.2.1 " ,
109+ ]
110+ full_dev_dependencies = [
111+ "pytest-asyncio@^0.21.1" ,
112+ ]
113+ dependencies [0 ] = "fastapi[all]@^0.95.2"
114+ dependencies .extend (full_dependencies )
115+ dev_dependencies .extend (full_dev_dependencies )
116+ 58117 print ("- Installing main packages. This might take a couple of minutes." )
59118 install_dependencies (poetry_path , dependencies )
60119 print ("- Installing development packages. This might take a couple of minutes." )
61120 install_dependencies (poetry_path , dev_dependencies , dev = True )
121+ 122+ if template == ITemplate .langchain_basic :
123+ add_configuration_to_pyproject (poetry_frontend_path )
124+ print (
125+ "- Installing frontend packages. This might take a couple of minutes."
126+ )
127+ install_dependencies (poetry_frontend_path , frontend_dependencies )
128+ 62129 # Set your dynamic environment variables
63-
130+ 64131 # Load variables from .env.example
65132 example_env = dotenv_values (".env.example" )
66133 example_env ["PROJECT_NAME" ] = app_name
67134
68135 # Write modified environment variables to .env and .env.example file
69- with open (".env" , "w" ) as env_file , open (".env.example" , "w" ) as example_env_file :
136+ with open (".env" , "w" ) as env_file , open (
137+ ".env.example" , "w"
138+ ) as example_env_file :
70139 for key , value in example_env .items ():
71140 env_file .write (f"{ key } ={ value } \n " )
72141 example_env_file .write (f"{ key } ={ value } \n " )
73142
74143 return has_pyproject
75- 76-
0 commit comments