Skip to content

Commit

Permalink
Merge branch '3-using-diagnostics-rather-than-code-lens' of https://g…
Browse files Browse the repository at this point in the history
…ithub.com/typhonshambo/ai-styleguide into 3-using-diagnostics-rather-than-code-lens
  • Loading branch information
typhonshambo committed Jul 15, 2024
2 parents 0276789 + 1b2005c commit ef2308f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions app/gemini_analyzer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import google.generativeai as genai
from typing import List
from .gemini_config import AnalyzerConfigs
# for logging
import structlog

structlog.stdlib.recreate_defaults()
log = structlog.get_logger(__name__).info("module loaded successfully.")

__all__ = ["CodeAnalyzer"]


class CodeAnalyzer:
def __init__(self) -> None:
self.language: str = "python"
Expand All @@ -26,7 +28,7 @@ def analyze_code(self, lines: List[str]) -> str:
This method analyzes the input lines of code and generates a style guide using the Gemini model.
"""
try:
prompt = f'''Analyze the following {self.language} code according to {self.style_guide} style guidelines, the array below contains line-wise code:
prompt = f'''Analyze the following {self.language} code according to {self.style_guide} style guidelines:
{lines}
Expand All @@ -40,7 +42,7 @@ def analyze_code(self, lines: List[str]) -> str:
Using this JSON schema:
response = {{"line": int, "message": str, "severity": str, "start_char": int, "end_char": int}}
Return a `list[response]`
'''
'''

model = self.gemini_model
response = model.generate_content(prompt)
Expand Down
3 changes: 1 addition & 2 deletions app/gemini_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import streamlit as st


class AnalyzerConfigs:
"""
This class contains configuration settings for the CodeAnalyzer class.
Expand All @@ -25,5 +26,3 @@ class AnalyzerConfigs:
"google style": "https://google.github.io/styleguide/pyguide.html",
"pep8": "https://pep8.org/",
}


2 changes: 1 addition & 1 deletion app/response_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class ResponseData(TypedDict):
message: str
severity: str
start_char: int
end_char: int
end_char: int
4 changes: 3 additions & 1 deletion streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
st.subheader("Style Guide and Suggestions:")
# Expanders
for items in data:
with st.expander(f"Line `{items['line']}` | Severity: `{items['severity']}`"):
with st.expander(
f"Line `{items['line']}` | Severity: `{items['severity']}`"
):
st.write(items["message"])
# JSON output
st.subheader("Raw API response : ")
Expand Down

0 comments on commit ef2308f

Please sign in to comment.