Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit config to provide feedback on code quality before pushing #17

Merged
merged 16 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"vscode": {
"settings": {
"python.analysis.typeCheckingMode": "basic",
"python.analysis.autoImportCompletions": true
"python.analysis.autoImportCompletions": true,
"python.editor.formatOnSave": true,
"python.editor.defaultFormatter": "charliermarsh.ruff"
},
"extensions": [
"GitHub.vscode-github-actions",
"GitHub.copilot"
"GitHub.copilot",
"charliermarsh.ruff",
"elagil.pre-commit-helper"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions .devcontainer/post-install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
poetry install
poetry shell
poetry run pre-commit install
samhwang marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-byte-order-marker
- id: check-added-large-files
- id: check-shebang-scripts-are-executable
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.1
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
- repo: https://github.com/python-poetry/poetry
rev: 1.7.1
hooks:
- id: poetry-check
- id: poetry-lock
5 changes: 2 additions & 3 deletions llm_assistant/ollama/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ ollama run phi

## Use LiteLLM as a Proxy to re-use OpenAI interface to interact with both OpenAI models and Ollama

Edit the proxy server config at `proxy_config.yaml`, add the desired models the the corresponding parameters. Please visit [here](https://docs.litellm.ai/docs/proxy/quick_start) for the available settings
Edit the proxy server config at `proxy_config.yaml`, add the desired models the the corresponding parameters. Please visit [here](https://docs.litellm.ai/docs/proxy/quick_start) for the available settings

Run the proxy server

```shell
# if you use OpenAI models
export OPENAI_API_KEY=<your_key>
export OPENAI_API_KEY=<your_key>
litellm --config llm_assistant/ollama/proxy_config.yaml
```

Expand All @@ -28,4 +28,3 @@ Modify OpenAI SDK to interact with our proxy server instead. In `openai_chat` we
python openai_chat.py gpt-3.5-turbo
python openai_chat.py phi
```

11 changes: 5 additions & 6 deletions llm_assistant/ollama/openai_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
parser.add_argument("model")
args = parser.parse_args()

response = client.chat.completions.create(model=args.model, messages = [
{
"role": "user",
"content": "write a short poem"
}
], stream=True)
response = client.chat.completions.create(
model=args.model,
messages=[{"role": "user", "content": "write a short poem"}],
stream=True,
)

for chunk in response:
# print(chunk)
Expand Down
609 changes: 369 additions & 240 deletions poetry.lock

Large diffs are not rendered by default.

69 changes: 67 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,81 @@
name = "llm-assistant"
version = "0.1.0"
description = ""
authors = ["Duy Hung Tran <hung.dtrn@gmail.com>"]
authors = ["VAIT"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
python = "^3.12"
litellm = {extras = ["proxy"], version = "^1.23.7"}
openai = "^1.11.1"
python-dotenv = "^1.0.1"
discord-py-interactions = "5.11.0"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.6.1"
ruff = "^0.2.1"

[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 = 88
samhwang marked this conversation as resolved.
Show resolved Hide resolved
indent-width = 4

target-version = "py312"

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
select = ["E4", "E7", "E9", "F"]
ignore = []

# 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]+?))$"

[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"
samhwang marked this conversation as resolved.
Show resolved Hide resolved

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def test_demo():
assert 1==1
assert 1 == 1
Loading