add pre commit (#14)

* add pre-commit config

Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>

* add prettier

Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>

* update prettier

Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>

* fix codespell

Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>

---------

Signed-off-by: Sun, Xuehao <xuehao.sun@intel.com>
This commit is contained in:
Sun, Xuehao
2024-03-27 19:14:19 +08:00
committed by GitHub
parent cd1d2169d3
commit 6c00ee5a0d
5 changed files with 250 additions and 5 deletions

0
.github/code_spell_ignore.txt vendored Normal file
View File

13
.github/license_template.txt vendored Normal file
View File

@@ -0,0 +1,13 @@
Copyright (c) 2024 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

122
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,122 @@
ci:
autofix_prs: true
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: end-of-file-fixer
files: (.*\.(py|md|rst|yaml|yml|json|ts|js|html|svelte|sh))$
- id: check-json
exclude: |
(?x)^(
ChatQnA/ui/tsconfig.json
)$
- id: check-yaml
- id: debug-statements
- id: requirements-txt-fixer
- id: trailing-whitespace
files: (.*\.(py|rst|cmake|yaml|yml|json|ts|js|html|svelte|sh))$
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: insert-license
files: |
(?x)^(
(ChatQnA|CodeGen|DocSum|VisualQnA)/.*(py|yaml|yml|sh)|
)$
args:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--skip-license-insertion-comment=Copyright,
]
- id: insert-license
files: |
(?x)^(
(ChatQnA|CodeGen|DocSum|VisualQnA)/.*(ts|js)|
)$
args:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--skip-license-insertion-comment=Copyright,
--comment-style=//,
]
- id: insert-license
files: |
(?x)^(
(ChatQnA|CodeGen|DocSum|VisualQnA)/.*(html|svelte)|
)$
args:
[
--license-filepath=.github/license_template.txt,
--use-current-year,
--detect-license-in-X-top-lines=40,
--skip-license-insertion-comment=Copyright,
--comment-style=<!--| |-->,
]
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
name: Unused noqa
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
- id: docformatter
args: [
--in-place,
--wrap-summaries=0, # 0 means disable wrap
--wrap-descriptions=0, # 0 means disable wrap
--black,
--style=google,
]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.1.0" # Use the sha / tag you want to point at
hooks:
- id: prettier
args: [--print-width=120]
types_or: [yaml, markdown, html, css, scss, javascript, json]
additional_dependencies:
- prettier@3.2.5
- repo: https://github.com/psf/black.git
rev: 24.3.0
hooks:
- id: black
files: (.*\.py)$
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: [--line-length=120, --skip-errors]
additional_dependencies:
- black==24.3.0
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: [-w]
additional_dependencies:
- tomli
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix, --no-cache]

View File

@@ -6,11 +6,13 @@ Pre-requisite: Signup in langsmith [https://www.langchain.com/langsmith] and get
3. Statr redis container with docker-compose-redis.yml
4. Add your hugging face access token in docker-compose-langchain.yml and start langchain-rag-server container
5. enter into langchain-rag-server container and start jupyter notebook server (can specify needed IP address and jupyter will run on port 8888)
```
docker exec -it langchain-rag-server bash
cd /test
jupyter notebook --allow-root --ip=X.X.X.X
```
```
docker exec -it langchain-rag-server bash
cd /test
jupyter notebook --allow-root --ip=X.X.X.X
```
6. Launch jupyter notebook in your browser and open the tgi_gaudi.ipynb notebook
7. Add langsmith api key in first cell of the notebook [os.environ["LANGCHAIN_API_KEY"] = "add-your-langsmith-key" # Your API key]
8. Clear all the cells and run all the cells

108
pyproject.toml Normal file
View File

@@ -0,0 +1,108 @@
[tool.isort]
profile = "black"
line_length = 120
extend_skip_glob = ["**/__init__.py"]
[tool.black]
line-length = 120
[tool.codespell]
skip = '*.po,*.js,*.map,*.js.map,*.css.map,*.json'
count = ''
quiet-level = 3
ignore-words = ".github/code_spell_ignore.txt"
[tool.ruff]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
# Same as Black.
line-length = 120
indent-width = 4
# Assume Python 3.10
target-version = "py310"
[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = [
"E402", # Module level import not at top of file
"E501", # Line too long (121 > 120 characters)
"E721", # Do not compare types, use isinstance()
"E722", # Do not use bare except
"E731", # Do not assign a lambda expression, use a def
"E741", # Do not use variables named l, O, or I
"F401", # {name} imported but unused
"F403", # from {name} import * used; unable to detect undefined names
"F405", # {name} may be undefined, or defined from star imports
"F841", # Local variable is assigned to but never used{name}
]
# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []
# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
ignore-init-module-imports = true
[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"
# Like Black, indent with spaces, rather than tabs.
indent-style = "space"
# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false
# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false
# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"