diff options
| author | Bobby <[email protected]> | 2024-06-06 15:27:54 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-06-06 15:27:54 +0000 |
| commit | 246671c3a83648b2aa7fd834486393052a301ac9 (patch) | |
| tree | fd773543e2ff32c9d289ea77ce44b1a9e1fc2f09 | |
| parent | f34a3c0fc64c8e4b8f10235edd84ff87fac4ef66 (diff) | |
| download | thatcomputerscientist-246671c3a83648b2aa7fd834486393052a301ac9.tar.xz thatcomputerscientist-246671c3a83648b2aa7fd834486393052a301ac9.zip | |
Add to env
| -rw-r--r-- | .github/workflows/main.yml | 9 | ||||
| -rw-r--r-- | blog/context_processors.py | 46 |
2 files changed, 30 insertions, 25 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 90f0922c..70eed5b4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,10 @@ jobs: key: ${{ secrets.KEY_ED25519 }} port: ${{ secrets.PORT }} script: | - if [ -z "$GEMINI_API_KEY" ]; then - export GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }} - fi + # if [ -z "$GEMINI_API_KEY" ]; then + # export GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }} + # fi + # Add to /home/ubuntu/.env + grep -qxF 'GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}' /home/ubuntu/.env || echo 'GEMINI_API_KEY=${{ secrets.GEMINI_API_KEY }}' >> /home/ubuntu/.env + cat /home/ubuntu/.env sh /home/ubuntu/deploy.sh diff --git a/blog/context_processors.py b/blog/context_processors.py index c4c5cd66..0279562b 100644 --- a/blog/context_processors.py +++ b/blog/context_processors.py @@ -20,32 +20,34 @@ gemini_api_key = os.getenv("GEMINI_API_KEY") akismet_api = akismet.Akismet( key=os.getenv("AKISMET_API_KEY"), - blog_url="https://preview.thatcomputerscientist.com" - if settings.DEBUG - else "https://thatcomputerscientist.com", + blog_url=( + "https://preview.thatcomputerscientist.com" + if settings.DEBUG + else "https://thatcomputerscientist.com" + ), ) def check_spam(user_ip, user_agent, comment, author): - spam = False - akismet_data = { - "comment_type": "comment", - "comment_author": author, - "comment_content": comment, - "is_test": settings.DEBUG, - } - spam = akismet_api.comment_check(user_ip, user_agent, **akismet_data) - - if spam: - return spam - - # Now we check with Google Generative AI + # spam = False + # akismet_data = { + # "comment_type": "comment", + # "comment_author": author, + # "comment_content": comment, + # "is_test": settings.DEBUG, + # } + # spam = akismet_api.comment_check(user_ip, user_agent, **akismet_data) + + # if spam: + # return spam + + # Now we check with Google Generative AI if gemini_api_key is None: - return spam + return False else: genai.configure(api_key=gemini_api_key) - - model = genai.GenerativeModel('gemini-1.5-flash') + + model = genai.GenerativeModel("gemini-1.5-flash") input_prompt = f"Comment Processing Checker. This is for a personal blog site. Output only Y or N for the included text. Y if the comment seems like spam. N if the comment seems safe. Do not access links. Just mark Y or N for the text. \n\nText: {comment}" @@ -54,9 +56,9 @@ def check_spam(user_ip, user_agent, comment, author): r_text = response.text if r_text == "Y": - spam = True - - return spam + return True + else: + return False def add_excerpt(post): |
