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

V2 #3

Merged
merged 36 commits into from
May 8, 2024
Merged

V2 #3

merged 36 commits into from
May 8, 2024

Conversation

closedLoop
Copy link
Contributor

No description provided.

closedLoop and others added 30 commits February 14, 2024 12:22
docs: USAGE docs in README-USECASE.md
♻️ (_data_extraction.py): refactor code to improve readability and maintainability
📝 (safer_python_exec.py): add import statement for black module
♻️ (safer_python_exec.py): refactor code to use black module for code formatting
♻️ (data_from_text.py): refactor code to improve readability and maintainability
♻️ (entities_from_text.py): refactor code to improve readability and maintainability
♻️ (helpers.py): refactor code to improve readability and maintainability
♻️ (datagraph_from_pydantic.py): refactor code to use safer_exec instead of kindofsafe_exec
♻️ (datagraph_from_pydantic.py): refactor code to use format_code function for code formatting
…rectories

📝 (_data_extraction.py): remove unused functions and update function signatures
📝 (data_from_model.py): update function signatures and add support for generating a single example
📝 (schema_from_data.py): add function to add titles and descriptions to a schema based on a language model
…erate` and `_brainstorm` functions to track usage statistics of the language model

📝 (schema_from_data.py): update the description field in the `JSONSchemaTitleDescription` class to recommend PascalCase for the provided schema
🔧 (schema_from_data.py): update the `add_schema_titles_and_descriptions` function to use a new system message and message template for generating titles and descriptions for the schema based on a language model
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @closedLoop - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 7 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -32,6 +35,7 @@ def kindofsafe_exec(code, dependencies: dict = None):
): # Loading in code by chunks helps with dependency resolution
dependencies.update(variables)
exec(snippet, dependencies, variables)
DeprecationWarning("This is a deprecated function: use safer_exec")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Deprecation warning should use warnings.warn instead of DeprecationWarning directly.

Directly raising DeprecationWarning may not be visible to users depending on their warning filter settings. It's recommended to use warnings.warn() with the appropriate category.

Suggested change
DeprecationWarning("This is a deprecated function: use safer_exec")
import warnings
warnings.warn("This is a deprecated function: use safer_exec", DeprecationWarning)

@@ -59,24 +63,150 @@

# Things can throw weird errors if multiple definitions of the same name are in the same file

import networkx as nx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_refinement): Consider moving module imports to the top of the file.

Import statements are conventionally placed at the top of the file for better visibility and to avoid potential issues with circular imports and readability.

Suggested change
import networkx as nx
import networkx as nx
# Things can throw weird errors if multiple definitions of the same name are in the same file
g = nx.MultiDiGraph()

updates = add_entity_is_subset_edges(g)
print("Added edges:", updates)

nx.write_graphml(g, file_path.parent / "schema.graphml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (edge_case_not_handled): Potential issue with path handling for nx.write_graphml.

Ensure that file_path.parent is a valid directory path and that it has the necessary write permissions. Consider adding error handling for file writing operations.

@@ -0,0 +1,82 @@
import ast
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code_clarification): Consider using more specific AST node types for clarity.

Using specific AST node types instead of the generic 'ast' import could improve clarity and maintainability of the code.

Suggested change
import ast
from ast import NodeVisitor, parse


def safer_exec(model_code):
logger.warning("Executing generated data model code from datamodel_code_generator")
exec_variables = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Potential security risk with unrestricted exec usage.

Using 'exec' without strict controls can lead to security vulnerabilities. Consider implementing additional safeguards or using a safer alternative.

schema = RootModel[list[x]].model_json_schema()
else:
schema = data_model.model_json_schema()
return resolve_references(schema) if resolve_refs else schema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Potential infinite recursion in resolve_references.

The recursive call in 'resolve_references' lacks a clear base case for all paths, which might lead to infinite recursion under certain conditions.

promptedgraphs/llms/openai_chat.py Outdated Show resolved Hide resolved
logger = getLogger(__name__)


def is_potentially_unsafe(node): # sourcery skip: low-code-quality
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Unused skip comment (unused-skip-comment)

closedLoop and others added 6 commits May 8, 2024 18:52
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
- Update termcolor from "^2.3.0" to "^2.4.0" to fix a bug related to terminal colors
- Update pydantic from "^2.3.0" to "^2.6.3" to benefit from the latest features and bug fixes
- Update tiktoken from "^0.5.1" to "^0.6.0" to improve tokenization performance
- Update httpx from "^0.25.0" to "^0.27.0" to take advantage of the latest improvements and bug fixes
- Update spacy from "^3.6.1" to "^3.7.4" to benefit from the latest features and bug fixes
- Update beautifulsoup4 from "^4.12.2" to "^4.12.3" to fix a bug related to web scraping
- Update networkx from "^3.1" to "^3.2.1" to benefit from the latest features and bug fixes
- Update pandas from "^2.1.1" to "^2.2.1" to take advantage of the latest improvements and bug fixes
- Update transformers from "^4.37.2" to "^4.38.1" to benefit from the latest features and bug fixes
- Update python-dotenv from "^1.0.0" to "^1.0.1" to fix a bug related to loading environment variables
- Update dataclasses-json from "^0.6.0" to "^0.6.4" to benefit from the latest features and bug fixes
- Update sse-starlette from "^1.6.5" to "^2.0.0" to take advantage of the latest improvements and bug fixes
- Update pydantic-settings from "^2.0.3" to "^2.2.1" to benefit from the latest features and bug fixes
- Update pre-commit from "^3.3.2" to "^3.6.2" to fix a bug related to pre-commit hooks
- Update pre-commit-hooks from "^4.4.0" to "^4.4.0" to take advantage of the latest improvements and bug fixes
- Update pycodestyle from "^2.10.0" to "^2.10.0" to benefit from the latest features and bug fixes
-
…eflect changes in the codebase

📦 chore(pyproject.toml): update package version from 0.3.1 to 0.3.2 to match the updated version in __init__.py
@closedLoop closedLoop merged commit 201808f into main May 8, 2024
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant