Open sweep-nightly[bot] opened 11 months ago
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
pre-commit install
1/4 βpre-commit installed at .git/hooks/pre-commit pre-commit installed at .git/hooks/pre-push
trunk init
2/4 ββ‘Ώ Downloading Trunk 1.17.1... β‘Ώ Downloading Trunk 1.17.1... β’Ώ Downloading Trunk 1.17.1... β£» Downloading Trunk 1.17.1... β£½ Downloading Trunk 1.17.1... β£Ύ Downloading Trunk 1.17.1... β£· Downloading Trunk 1.17.1... β Downloading Trunk 1.17.1... done β‘Ώ Verifying Trunk sha256... β Verifying Trunk sha256... done β‘Ώ Unpacking Trunk... β Unpacking Trunk... done β 18 linters were enabled (.trunk/trunk.yaml) actionlint 1.6.26 (4 github-workflow files) bandit 1.7.5 (66 python files) black 23.9.1 (56 python files) checkov 3.0.19 (1 docker, 1 json, 10 yaml files) git-diff-check (99 files) hadolint 2.12.0 (1 docker file) (created .hadolint.yaml) isort 5.12.0 (66 python files) (created .isort.cfg) markdownlint 0.37.0 (3 markdown files) (created .markdownlint.yaml) mypy 1.6.1 (66 python files) osv-scanner 1.4.3 (1 lockfile file) oxipng 9.0.0 (1 png file) prettier 3.0.3 (1 html, 1 json, 3 markdown, 10 yaml files) ruff 0.1.3 (66 python files) taplo 0.8.1 (1 toml file) terrascan 1.18.3 (1 docker file) trivy 0.46.1 (1 docker, 10 yaml files) trufflehog 3.62.1 (99 files) yamllint 1.32.0 (10 yaml files) (created .yamllint.yaml) Next Steps 1. Read documentation Our documentation can be found at https://docs.trunk.io 2. Get help and give feedback Join the Trunk community at https://slack.trunk.io
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
3/4 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
4/4 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:27:15 16:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 18:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 27:15 high Name "root_injector" is not defined mypy/name-defined 27:15 high Undefined name `root_injector` ruff/F821 27:33 high Name "ChunksService" is not defined mypy/name-defined 27:33 high Undefined name `ChunksService` ruff/F821 33:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 33:30 high Undefined name `VectorStoreIndex` ruff/F821 33:30 high Name "VectorStoreIndex" is not defined mypy/name-defined 40:15 high Name "root_injector" is not defined mypy/name-defined 40:15 high Undefined name `root_injector` ruff/F821 40:33 high Name "ChunksService" is not defined mypy/name-defined 40:33 high Undefined name `ChunksService` ruff/F821 47:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 48:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 48:33 high Name "NodeWithScore" is not defined mypy/name-defined 48:33 high Undefined name `NodeWithScore` ruff/F821 55:15 high Name "root_injector" is not defined mypy/name-defined 55:15 high Undefined name `root_injector` ruff/F821 55:33 high Name "ChunksService" is not defined mypy/name-defined 55:33 high Undefined name `ChunksService` ruff/F821 63:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 72:15 high Name "root_injector" is not defined mypy/name-defined 72:15 high Undefined name `root_injector` ruff/F821 72:33 high Undefined name `ChunksService` ruff/F821 72:33 high Name "ChunksService" is not defined mypy/name-defined 81:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 82:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 82:34 high Undefined name `Chunk` ruff/F821 82:34 high Name "Chunk" is not defined mypy/name-defined Checked 1 file 2 existing issues β 28 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:8:1 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export attribute mypy/attr-defined "NodeWithScore" 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export attribute mypy/attr-defined "VectorStoreIndex" 24:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 26:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 47:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 67:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 68:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 89:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 107:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 108:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. Checked 1 file 2 existing issues β 8 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:8:1 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export mypy/attr-defined attribute "NodeWithScore" 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export mypy/attr-defined attribute "VectorStoreIndex" 24:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 26:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 47:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 67:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 68:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 73:27 high Call to untyped function "setup_chunks_service" in typed context mypy/no-untyped-call 76:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 79:1 high Function is missing a type annotation mypy/no-untyped-def 113:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 114:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. Checked 1 file 2 existing issues β 10 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)β Auto-fixed tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... ISSUES tests/server/chunks/test_chunk_routes.py:44:0 21:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 23:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 44:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 64:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 65:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 73:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 78:6 high Undefined name `Tuple` ruff/F821 78:6 high Did you forget to import it from "typing"? (Suggestion: "from typing import Tuple") mypy/note 78:6 high Name "Tuple" is not defined mypy/name-defined 78:12 high Undefined name `List` ruff/F821 78:12 high Name "List" is not defined mypy/name-defined 78:12 high Did you forget to import it from "typing"? (Suggestion: "from typing import List") mypy/note 78:33 high Undefined name `List` ruff/F821 112:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 113:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 125:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 128:1 high Name "test_sort_nodes" already defined on line 68 mypy/no-redef 128:5 high Redefinition of unused `test_sort_nodes` from line 68 ruff/F811 133:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 136:1 high Function is missing a type annotation mypy/no-untyped-def 136:1 high Name "setup_chunks_service" already defined on line 76 mypy/no-redef 136:5 high Redefinition of unused `setup_chunks_service` from line 76 ruff/F811 137:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 137:23 high Undefined name `chunks` ruff/F821 138:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 138:54 high Undefined name `chunks` ruff/F821 Checked 1 file 2 existing issues β 24 new issues
[X] Check tests/server/chunks/test_chunk_routes.py
β
Run `tests/server/chunks/test_chunk_routes.py` through the sandbox.
[X] Check tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)β Auto-fixed tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... ISSUES tests/server/chunks/test_chunk_routes.py:44:0 21:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 23:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 44:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 64:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 65:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 73:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 78:6 high Undefined name `Tuple` ruff/F821 78:6 high Did you forget to import it from "typing"? (Suggestion: "from typing import Tuple") mypy/note 78:6 high Name "Tuple" is not defined mypy/name-defined 78:12 high Undefined name `List` ruff/F821 78:12 high Name "List" is not defined mypy/name-defined 78:12 high Did you forget to import it from "typing"? (Suggestion: "from typing import List") mypy/note 78:33 high Undefined name `List` ruff/F821 112:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 113:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 125:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 128:1 high Name "test_sort_nodes" already defined on line 68 mypy/no-redef 128:5 high Redefinition of unused `test_sort_nodes` from line 68 ruff/F811 133:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 136:1 high Function is missing a type annotation mypy/no-untyped-def 136:1 high Name "setup_chunks_service" already defined on line 76 mypy/no-redef 136:5 high Redefinition of unused `setup_chunks_service` from line 76 ruff/F811 137:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 137:23 high Undefined name `chunks` ruff/F821 138:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 138:54 high Undefined name `chunks` ruff/F821 Checked 1 file 2 existing issues β 24 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:8:1 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export mypy/attr-defined attribute "NodeWithScore" 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export mypy/attr-defined attribute "VectorStoreIndex" 24:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 26:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 47:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 67:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 68:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 73:27 high Call to untyped function "setup_chunks_service" in typed context mypy/no-untyped-call 76:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 79:1 high Function is missing a type annotation mypy/no-untyped-def 113:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. 114:0 low Use of assert detected. The enclosed code will be removed when compiling to bandit/B101 optimised byte code. Checked 1 file 2 existing issues β 10 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
1/2 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... β Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
2/2 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:8:1 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export attribute mypy/attr-defined "NodeWithScore" 8:1 high Module "private_gpt.server.chunks.chunks_service" does not explicitly export attribute mypy/attr-defined "VectorStoreIndex" 24:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 26:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 47:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 67:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 68:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 89:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 107:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 108:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. Checked 1 file 2 existing issues β 8 new issues
tests/server/chunks/test_chunk_routes.py
β
Sandbox logs for
pre-commit install
1/4 βpre-commit installed at .git/hooks/pre-commit pre-commit installed at .git/hooks/pre-push
trunk init
2/4 ββ‘Ώ Downloading Trunk 1.17.1... β‘Ώ Downloading Trunk 1.17.1... β’Ώ Downloading Trunk 1.17.1... β£» Downloading Trunk 1.17.1... β£½ Downloading Trunk 1.17.1... β£Ύ Downloading Trunk 1.17.1... β£· Downloading Trunk 1.17.1... β Downloading Trunk 1.17.1... done β‘Ώ Verifying Trunk sha256... β Verifying Trunk sha256... done β‘Ώ Unpacking Trunk... β Unpacking Trunk... done β 18 linters were enabled (.trunk/trunk.yaml) actionlint 1.6.26 (4 github-workflow files) bandit 1.7.5 (66 python files) black 23.9.1 (56 python files) checkov 3.0.19 (1 docker, 1 json, 10 yaml files) git-diff-check (99 files) hadolint 2.12.0 (1 docker file) (created .hadolint.yaml) isort 5.12.0 (66 python files) (created .isort.cfg) markdownlint 0.37.0 (3 markdown files) (created .markdownlint.yaml) mypy 1.6.1 (66 python files) osv-scanner 1.4.3 (1 lockfile file) oxipng 9.0.0 (1 png file) prettier 3.0.3 (1 html, 1 json, 3 markdown, 10 yaml files) ruff 0.1.3 (66 python files) taplo 0.8.1 (1 toml file) terrascan 1.18.3 (1 docker file) trivy 0.46.1 (1 docker, 10 yaml files) trufflehog 3.62.1 (99 files) yamllint 1.32.0 (10 yaml files) (created .yamllint.yaml) Next Steps 1. Read documentation Our documentation can be found at https://docs.trunk.io 2. Get help and give feedback Join the Trunk community at https://slack.trunk.io
trunk fmt tests/server/chunks/test_chunk_routes.py || exit 0
3/4 ββ Formatted tests/server/chunks/test_chunk_routes.py Re-checking autofixed files... Checked 1 file β No issues
trunk check --fix --print-failures tests/server/chunks/test_chunk_routes.py
4/4 β (`1`)ISSUES tests/server/chunks/test_chunk_routes.py:27:15 16:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 18:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 27:15 high Name "root_injector" is not defined mypy/name-defined 27:15 high Undefined name `root_injector` ruff/F821 27:33 high Name "ChunksService" is not defined mypy/name-defined 27:33 high Undefined name `ChunksService` ruff/F821 33:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 33:30 high Undefined name `VectorStoreIndex` ruff/F821 33:30 high Name "VectorStoreIndex" is not defined mypy/name-defined 40:15 high Name "root_injector" is not defined mypy/name-defined 40:15 high Undefined name `root_injector` ruff/F821 40:33 high Name "ChunksService" is not defined mypy/name-defined 40:33 high Undefined name `ChunksService` ruff/F821 47:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 48:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 48:33 high Name "NodeWithScore" is not defined mypy/name-defined 48:33 high Undefined name `NodeWithScore` ruff/F821 55:15 high Name "root_injector" is not defined mypy/name-defined 55:15 high Undefined name `root_injector` ruff/F821 55:33 high Name "ChunksService" is not defined mypy/name-defined 55:33 high Undefined name `ChunksService` ruff/F821 63:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 72:15 high Name "root_injector" is not defined mypy/name-defined 72:15 high Undefined name `root_injector` ruff/F821 72:33 high Undefined name `ChunksService` ruff/F821 72:33 high Name "ChunksService" is not defined mypy/name-defined 81:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 82:0 low Use of assert detected. The enclosed code will be removed when compiling to optimised bandit/B101 byte code. 82:34 high Undefined name `Chunk` ruff/F821 82:34 high Name "Chunk" is not defined mypy/name-defined Checked 1 file 2 existing issues β 28 new issues
Description
This PR refactors the
retrieve_relevant
function inchunks_service.py
to improve modularity and reduce complexity. The function was quite large and performed multiple distinct tasks, which have now been extracted into separate subfunctions. Additionally, unit tests have been added for the new subfunctions to ensure their correctness.Summary of Changes
create_vector_store_index
.retrieve_nodes
.sort_nodes
.Chunk
objects from the nodes into a new function namedcreate_chunks_from_nodes
.test_chunk_routes.py
to ensure their correctness.Please review and merge this PR. Thank you!
Fixes #1.
π Latest improvements to Sweep:
rope
library to refactor Python! Check out Large Language Models are Bad at Refactoring Code. To have Sweep refactor your code, trysweep: Refactor <your_file>.py to be more modular
!π‘ To get Sweep to edit this pull request, you can: