From f9a559d0dbe81c6482a7d22de5443313aca89fdc Mon Sep 17 00:00:00 2001 From: Han Lee Date: Sat, 9 Sep 2023 04:31:27 +0000 Subject: [PATCH] feat: devcontainer? --- .devcontainer/devcontainer.json | 19 ++++++++++++ .devcontainer/post_create_command.sh | 6 ++++ app/app.py | 18 ++++++------ poetry.lock | 19 +++++++++++- pyproject.toml | 43 ++++++++++++++++++---------- 5 files changed, 79 insertions(+), 26 deletions(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/post_create_command.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..b8d8a5f --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "image": "mcr.microsoft.com/vscode/devcontainers/universal", + "features": { + "ghcr.io/devcontainers-contrib/features/pre-commit:2": { + "version": "latest" + } + }, + "postCreateCommand": ".devcontainer/post_create_command.sh", + "postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}", + "customizations": { + "vscode": { + "extensions": [ + "GitHub.copilot", + "ms-python.python", + "esbenp.prettier-vscode" + ] + } + } +} \ No newline at end of file diff --git a/.devcontainer/post_create_command.sh b/.devcontainer/post_create_command.sh new file mode 100644 index 0000000..df9b6e0 --- /dev/null +++ b/.devcontainer/post_create_command.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# do as little as possible in this script to keep the container creation fast. +# for more specific devcontainer use cases use the different devcontainer subfolders. + +echo "done" diff --git a/app/app.py b/app/app.py index 1d304c5..609c6d9 100644 --- a/app/app.py +++ b/app/app.py @@ -1,19 +1,17 @@ from tempfile import NamedTemporaryFile +import chainlit as cl +from chainlit.types import AskFileResponse +from chromadb.config import Settings +from langchain.chains import RetrievalQAWithSourcesChain +from langchain.chains.base import Chain +from langchain.chat_models import ChatOpenAI from langchain.document_loaders import PDFPlumberLoader -from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.embeddings.openai import OpenAIEmbeddings +from langchain.text_splitter import RecursiveCharacterTextSplitter from langchain.vectorstores import Chroma from langchain.vectorstores.base import VectorStore -from langchain.chains import RetrievalQAWithSourcesChain -from langchain.chains.base import Chain -from langchain.chat_models import ChatOpenAI - -import chainlit as cl -from chainlit.types import AskFileResponse -from chromadb.config import Settings - -from prompts import PROMPT, EXAMPLE_PROMPT +from prompts import EXAMPLE_PROMPT, PROMPT WELCOME_MESSAGE = """\ Welcome to Introduction to LLM App Development Sample PDF QA Application! diff --git a/poetry.lock b/poetry.lock index dba2e03..314cbe6 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1158,6 +1158,23 @@ files = [ docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-ruff"] +[[package]] +name = "isort" +version = "5.12.0" +description = "A Python utility / library to sort Python imports." +optional = false +python-versions = ">=3.8.0" +files = [ + {file = "isort-5.12.0-py3-none-any.whl", hash = "sha256:f84c2818376e66cf843d497486ea8fed8700b340f308f076c6fb1229dff318b6"}, + {file = "isort-5.12.0.tar.gz", hash = "sha256:8bef7dde241278824a6d83f44a544709b065191b95b6e50894bdc722fcba0504"}, +] + +[package.extras] +colors = ["colorama (>=0.4.3)"] +pipfile-deprecated-finder = ["pip-shims (>=0.5.2)", "pipreqs", "requirementslib"] +plugins = ["setuptools"] +requirements-deprecated-finder = ["pip-api", "pipreqs"] + [[package]] name = "jinja2" version = "3.1.2" @@ -3186,4 +3203,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "dafbb966780108965c29644bac5d52d0db88f5c4551f150d0ec3149d3db94aa3" +content-hash = "33e0f99f6fc0302218b99dfb61df4b6fa092618fc5559a97878431d8c4c85b99" diff --git a/pyproject.toml b/pyproject.toml index dc1e9f5..7737718 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.black] -line-length = 88 -target-version = ['py37', 'py38'] +line-length = 120 +target-version = ['py310'] include = '\.pyi?$' extend-exclude = ''' /( @@ -14,6 +14,16 @@ extend-exclude = ''' # this off. preview = true +[tool.isort] +profile = "black" +filter_files = true +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true +ensure_newline_before_comments = true +line_length = 120 + [tool.poetry] name = "llm-pdf-qa-sample-app" version = "0.1.0" @@ -34,13 +44,21 @@ chromadb = "^0.4.9" [tool.poetry.group.dev.dependencies] ruff = "^0.0.287" black = "^23.7.0" +isort = "^5.12.0" [tool.ruff] -# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default. -# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or -# McCabe complexity (`C901`) by default. -select = ["E", "F"] -ignore = [] +target-version = "py310" +line-length = 120 +select = [ + "E", "W", # see: https://pypi.org/project/pycodestyle + "F", # see: https://pypi.org/project/pyflakes +] +ignore = [ + "E501", + "E731", + "E741", # Ambiguous variable name: ... + "E999", # SyntaxError: invalid syntax. Got unexpected token Newline +] # Allow autofix for all enabled rules (when `--fix`) is provided. fixable = ["ALL"] @@ -70,17 +88,12 @@ exclude = [ "node_modules", "venv", ] +ignore-init-module-imports = true per-file-ignores = {} - -# Same as Black. -line-length = 88 - -# Allow unused variables when underscore-prefixed. dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" -target-version = "py310" -[tool.ruff.isort] -case-sensitive = true +[tool.ruff.mccabe] +max-complexity = 10 [build-system] requires = ["poetry-core"]