Skip to content

Commit 69fd3cc

Browse files
committed
Merge branch 'langchain-leo' into langchain-template
2 parents f095610 + 2e2f217 commit 69fd3cc

File tree

99 files changed

+5466
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+5466
-4
lines changed

create_fastapi_project/templates/__init__.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ def install_template(root: str, template: ITemplate, app_name: str):
3333
)
3434

3535

36-
# Add pyproject.toml file and installl packages
37-
app_folder: str = "app"
36+
poetry_path = ""
3837
if template == ITemplate.full or template == ITemplate.langchain_basic:
3938
# TODO: CHECK PATHS IN MACOS AND WINDOWS | (os.path.join)
40-
app_folder = "backend\\app"
39+
poetry_path = os.path.join(root, "backend", "app")
40+
41+
else:
42+
poetry_path = os.path.join(root, "app")
4143

42-
poetry_path = os.path.join(root, app_folder)
4344
has_pyproject = add_configuration_to_pyproject(poetry_path)
4445

4546
if has_pyproject:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.10-slim-2022-11-25
2+
ENV PYTHONUNBUFFERED=1
3+
WORKDIR /code
4+
# Install Poetry
5+
RUN apt clean && apt update && apt install curl -y
6+
RUN curl -sSL https://install.python-poetry.org | POETRY_HOME=/opt/poetry python && \
7+
cd /usr/local/bin && \
8+
ln -s /opt/poetry/bin/poetry && \
9+
poetry config virtualenvs.create false
10+
11+
# Copy poetry.lock* in case it doesn't exist in the repo
12+
COPY app/pyproject.toml app/poetry.lock* /code/
13+
14+
# Allow installing dev dependencies to run tests
15+
ARG INSTALL_DEV=false
16+
RUN bash -c "if [ $INSTALL_DEV == 'true' ] ; then poetry install --no-root ; else poetry install --no-root --no-dev ; fi"
17+
18+
ENV PYTHONPATH=/code
19+
EXPOSE 8000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
file_template = %%(year)d-%%(month).2d-%%(day).2d-%%(hour).2d-%%(minute).2d_%%(rev)s
10+
11+
# timezone to use when rendering the date
12+
# within the migration file as well as the filename.
13+
# string value is passed to dateutil.tz.gettz()
14+
# leave blank for localtime
15+
# timezone =
16+
17+
# max length of characters to apply to the
18+
# "slug" field
19+
#truncate_slug_length = 40
20+
21+
# set to 'true' to run the environment during
22+
# the 'revision' command, regardless of autogenerate
23+
# revision_environment = false
24+
25+
# set to 'true' to allow .pyc and .pyo files without
26+
# a source .py file to be detected as revisions in the
27+
# versions/ directory
28+
# sourceless = false
29+
30+
# version location specification; this defaults
31+
# to alembic/versions. When using multiple version
32+
# directories, initial revisions must be specified with --version-path
33+
# version_locations = %(here)s/bar %(here)s/bat alembic/versions
34+
35+
# the output encoding used when revision files
36+
# are written from script.py.mako
37+
# output_encoding = utf-8
38+
39+
# Logging configuration
40+
[loggers]
41+
keys = root,sqlalchemy,alembic
42+
43+
[handlers]
44+
keys = console
45+
46+
[formatters]
47+
keys = generic
48+
49+
[logger_root]
50+
level = WARN
51+
handlers = console
52+
qualname =
53+
54+
[logger_sqlalchemy]
55+
level = WARN
56+
handlers =
57+
qualname = sqlalchemy.engine
58+
59+
[logger_alembic]
60+
level = INFO
61+
handlers =
62+
qualname = alembic
63+
64+
[handler_console]
65+
class = StreamHandler
66+
args = (sys.stderr,)
67+
level = NOTSET
68+
formatter = generic
69+
70+
[formatter_generic]
71+
format = %(levelname)-5.5s [%(name)s] %(message)s
72+
datefmt = %H:%M:%S
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from __future__ import with_statement
2+
import asyncio
3+
from logging.config import fileConfig
4+
from sqlmodel import SQLModel, create_engine
5+
from sqlmodel.ext.asyncio.session import AsyncEngine
6+
from alembic import context
7+
from app.core.config import Settings
8+
import sys
9+
import pathlib
10+
11+
sys.path.append(str(pathlib.Path(__file__).resolve().parents[1]))
12+
13+
from app.models import * # necessarily to import something from file where your models are stored
14+
15+
settings = Settings()
16+
# this is the Alembic Config object, which provides
17+
# access to the values within the .ini file in use.
18+
config = context.config
19+
20+
# Interpret the config file for Python logging.
21+
# This line sets up loggers basically.
22+
fileConfig(config.config_file_name)
23+
24+
25+
target_metadata = SQLModel.metadata
26+
27+
# other values from the config, defined by the needs of env.py,
28+
# can be acquired:
29+
# my_important_option = config.get_main_option("my_important_option")
30+
# ... etc.
31+
32+
33+
def run_migrations_offline():
34+
"""Run migrations in 'offline' mode.
35+
This configures the context with just a URL
36+
and not an Engine, though an Engine is acceptable
37+
here as well. By skipping the Engine creation
38+
we don't even need a DBAPI to be available.
39+
Calls to context.execute() here emit the given string to the
40+
script output.
41+
"""
42+
url = settings.ASYNC_DATABASE_URI
43+
context.configure(
44+
url=url,
45+
target_metadata=target_metadata,
46+
literal_binds=True,
47+
compare_type=True,
48+
dialect_opts={"paramstyle": "named"},
49+
)
50+
51+
with context.begin_transaction():
52+
context.run_migrations()
53+
54+
55+
def do_run_migrations(connection):
56+
context.configure(connection=connection, target_metadata=target_metadata)
57+
58+
with context.begin_transaction():
59+
context.run_migrations()
60+
61+
62+
async def run_migrations_online():
63+
"""Run migrations in 'online' mode.
64+
In this scenario we need to create an Engine
65+
and associate a connection with the context.
66+
"""
67+
connectable = AsyncEngine(
68+
create_engine(settings.ASYNC_DATABASE_URI, echo=True, future=True)
69+
)
70+
71+
async with connectable.connect() as connection:
72+
await connection.run_sync(do_run_migrations)
73+
74+
75+
if context.is_offline_mode():
76+
run_migrations_offline()
77+
else:
78+
asyncio.run(run_migrations_online())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlalchemy_utils
11+
import sqlmodel # added
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision = ${repr(up_revision)}
16+
down_revision = ${repr(down_revision)}
17+
branch_labels = ${repr(branch_labels)}
18+
depends_on = ${repr(depends_on)}
19+
20+
21+
def upgrade():
22+
op.execute("CREATE EXTENSION IF NOT EXISTS pg_trgm")
23+
${upgrades if upgrades else "pass"}
24+
25+
26+
def downgrade():
27+
${downgrades if downgrades else "pass"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
"""empty message
2+
3+
Revision ID: 60d49bf413b8
4+
Revises:
5+
Create Date: 2022-09-25 19:46:48.536092
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlalchemy_utils
11+
import sqlmodel # added
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision = "60d49bf413b8"
16+
down_revision = None
17+
branch_labels = None
18+
depends_on = None
19+
20+
21+
def upgrade():
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table(
24+
"Role",
25+
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
26+
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
27+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
28+
sa.Column("updated_at", sa.DateTime(), nullable=True),
29+
sa.Column("created_at", sa.DateTime(), nullable=True),
30+
sa.PrimaryKeyConstraint("id"),
31+
)
32+
op.create_index(op.f("ix_Role_id"), "Role", ["id"], unique=False)
33+
op.create_table(
34+
"User",
35+
sa.Column("birthdate", sa.DateTime(timezone=True), nullable=True),
36+
sa.Column("first_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
37+
sa.Column("last_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
38+
sa.Column("email", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
39+
sa.Column("is_active", sa.Boolean(), nullable=False),
40+
sa.Column("is_superuser", sa.Boolean(), nullable=False),
41+
sa.Column("phone", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
42+
sa.Column("state", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
43+
sa.Column("country", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
44+
sa.Column("address", sqlmodel.sql.sqltypes.AutoString(), nullable=True),
45+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
46+
sa.Column("updated_at", sa.DateTime(), nullable=True),
47+
sa.Column("created_at", sa.DateTime(), nullable=True),
48+
sa.Column(
49+
"hashed_password", sqlmodel.sql.sqltypes.AutoString(), nullable=False
50+
),
51+
sa.Column("role_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
52+
sa.ForeignKeyConstraint(
53+
["role_id"],
54+
["Role.id"],
55+
),
56+
sa.PrimaryKeyConstraint("id"),
57+
)
58+
op.create_index(op.f("ix_User_email"), "User", ["email"], unique=True)
59+
op.create_index(
60+
op.f("ix_User_hashed_password"), "User", ["hashed_password"], unique=False
61+
)
62+
op.create_index(op.f("ix_User_id"), "User", ["id"], unique=False)
63+
op.create_table(
64+
"Group",
65+
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
66+
sa.Column("description", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
67+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
68+
sa.Column("updated_at", sa.DateTime(), nullable=True),
69+
sa.Column("created_at", sa.DateTime(), nullable=True),
70+
sa.Column("created_by_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
71+
sa.ForeignKeyConstraint(
72+
["created_by_id"],
73+
["User.id"],
74+
),
75+
sa.PrimaryKeyConstraint("id"),
76+
)
77+
op.create_index(op.f("ix_Group_id"), "Group", ["id"], unique=False)
78+
op.create_table(
79+
"Team",
80+
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
81+
sa.Column("headquarters", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
82+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
83+
sa.Column("updated_at", sa.DateTime(), nullable=True),
84+
sa.Column("created_at", sa.DateTime(), nullable=True),
85+
sa.Column("created_by_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
86+
sa.ForeignKeyConstraint(
87+
["created_by_id"],
88+
["User.id"],
89+
),
90+
sa.PrimaryKeyConstraint("id"),
91+
)
92+
op.create_index(op.f("ix_Team_id"), "Team", ["id"], unique=False)
93+
op.create_index(op.f("ix_Team_name"), "Team", ["name"], unique=False)
94+
op.create_table(
95+
"Hero",
96+
sa.Column("name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
97+
sa.Column("secret_name", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
98+
sa.Column("age", sa.Integer(), nullable=True),
99+
sa.Column("team_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
100+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
101+
sa.Column("updated_at", sa.DateTime(), nullable=True),
102+
sa.Column("created_at", sa.DateTime(), nullable=True),
103+
sa.Column("created_by_id", sqlmodel.sql.sqltypes.GUID(), nullable=True),
104+
sa.ForeignKeyConstraint(
105+
["created_by_id"],
106+
["User.id"],
107+
),
108+
sa.ForeignKeyConstraint(
109+
["team_id"],
110+
["Team.id"],
111+
),
112+
sa.PrimaryKeyConstraint("id"),
113+
)
114+
op.create_index(op.f("ix_Hero_age"), "Hero", ["age"], unique=False)
115+
op.create_index(op.f("ix_Hero_id"), "Hero", ["id"], unique=False)
116+
op.create_index(op.f("ix_Hero_name"), "Hero", ["name"], unique=False)
117+
op.create_table(
118+
"LinkGroupUser",
119+
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
120+
sa.Column("group_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
121+
sa.Column("user_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
122+
sa.ForeignKeyConstraint(
123+
["group_id"],
124+
["Group.id"],
125+
),
126+
sa.ForeignKeyConstraint(
127+
["user_id"],
128+
["User.id"],
129+
),
130+
sa.PrimaryKeyConstraint("id", "group_id", "user_id"),
131+
)
132+
op.create_index(op.f("ix_LinkGroupUser_id"), "LinkGroupUser", ["id"], unique=False)
133+
# ### end Alembic commands ###
134+
135+
136+
def downgrade():
137+
# ### commands auto generated by Alembic - please adjust! ###
138+
op.drop_index(op.f("ix_LinkGroupUser_id"), table_name="LinkGroupUser")
139+
op.drop_table("LinkGroupUser")
140+
op.drop_index(op.f("ix_Hero_name"), table_name="Hero")
141+
op.drop_index(op.f("ix_Hero_id"), table_name="Hero")
142+
op.drop_index(op.f("ix_Hero_age"), table_name="Hero")
143+
op.drop_table("Hero")
144+
op.drop_index(op.f("ix_Team_name"), table_name="Team")
145+
op.drop_index(op.f("ix_Team_id"), table_name="Team")
146+
op.drop_table("Team")
147+
op.drop_index(op.f("ix_Group_id"), table_name="Group")
148+
op.drop_table("Group")
149+
op.drop_index(op.f("ix_User_id"), table_name="User")
150+
op.drop_index(op.f("ix_User_hashed_password"), table_name="User")
151+
op.drop_index(op.f("ix_User_email"), table_name="User")
152+
op.drop_table("User")
153+
op.drop_index(op.f("ix_Role_id"), table_name="Role")
154+
op.drop_table("Role")
155+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)