Improved Language Detection Functionality (Tasks 1-3) #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Task 1: Core Language Detection Function (
pypacter/src/pypacter.py
)This pull request implements three new features for Pypacter, enhancing its language detection capabilities:
A new function,
detect_programming_language(code_snippet: str) -> str
, has been added to the core Pypacter package. This function takes a code snippet as input and uses the DEFAULT_MODEL from thepypacter.models
module to analyze it with a Large Language Model (LLM). The detected programming language is returned.The LLM prompt has been carefully crafted to handle various scenarios:
Task 2: Language Detection API Endpoint (
pypacter-api/src/pypacter_api/api.py
)A new API endpoint, /detect-language, has been added to the
pypacter-api
package. This endpoint accepts a POST request with a JSON body containing the code_snippet field. It performs the following actions:Task 3: Language Detection CLI Command (
pypacter-cli/src/pypacter_cli/cli.py
)A new CLI command, detect-language, has been added to the
pypacter-cli package
. This command allows users to detect the programming language of a code snippet through the command line. It offers two ways to provide the code snippet:detect_programming _language
function and presents the detected language in a user-friendly format.These enhancements have been implemented with a focus on the provided guidelines:
Next Steps:
Please reach out if there has been any kind of oversight from my end.