Skip to content

Commit

Permalink
edit type ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed Jan 3, 2025
1 parent 16f6591 commit 95227a9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions docassemble/GithubFeedbackForm/github_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from urllib.parse import urlencode, quote_plus
from docassemble.base.util import log, get_config, interview_url
import re

try:
import google.generativeai as genai
except:
Expand All @@ -25,6 +26,7 @@
]
USERNAME = get_config("github issues", {}).get("username")


def _get_token() -> Optional[str]:
return (get_config("github issues") or {}).get("token")

Expand Down Expand Up @@ -172,7 +174,12 @@ def feedback_link(
)


def is_likely_spam_from_genai(body: Optional[str], context:Optional[str] = None, gemini_api_key:Optional[str] = None, model="gemini-2.0-flash-exp") -> bool:
def is_likely_spam_from_genai(
body: Optional[str],
context: Optional[str] = None,
gemini_api_key: Optional[str] = None,
model="gemini-2.0-flash-exp",
) -> bool:
"""
Check if the body of the issue is likely spam with the help of Google Gemini Flash experimental.
Expand All @@ -189,28 +196,28 @@ def is_likely_spam_from_genai(body: Optional[str], context:Optional[str] = None,

if not gemini_api_key:
gemini_api_key = get_config("google gemini api key")

if not gemini_api_key:
log("Not using Google Gemini Flash to check for spam: no token provided")
return False

try:
genai.configure(api_key=gemini_api_key)
model = genai.GenerativeModel(
model_name="gemini-2.0-flash-exp",
system_instruction = f"""
system_instruction=f"""
You are reviewing a feedback form for {context}. Your job is to allow as many
relevant feedback responses as possible while filtering out irrelevant and spam feedback,
especially targeted advertising that isn't pointing out a problem on the guided interview.
Rate the user's feedback as 'spam' or 'not spam' based on the context of the guided interview.
Answer only with the exact keywords: 'spam' or 'not spam'.
"""
""",
)
except Exception as e:
log(f"Error configuring Google Gemini Flash: {e}")
return False

try:
response = model.generate_content(body)
if response.text.strip() == "spam":
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ exclude = '''(?x)(
[[tool.mypy.overrides]]
module = "docassemble.base.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "google.*"
ignore_missing_imports = true

0 comments on commit 95227a9

Please sign in to comment.