alab10

By Ayush S1h ago (Jun 27, 2026)

alab10

python
!pip install -q google-genai

from google import genai
from getpass import getpass

api_key = getpass("Enter Gemini API Key: ")

client = genai.Client(api_key=api_key)

rules = [
    "ignore previous",
    "fake news",
    "all men",
    "all women"
]

while True:

    prompt = input("Enter Prompt: ")

    violation = False

    for word in rules:

        if word in prompt.lower():

            print("\nWarning: Unsafe Prompt Detected")

            violation = True

            break

    if not violation:

        response = client.models.generate_content(
            model="gemini-2.5-flash",
            contents=prompt
        )

        print("\nResponse:")
        print(response.text)

    choice = input("\nContinue? (y/n): ")

    if choice.lower() != "y":
        break

Views

0

Lines

46

Characters

788

Likes

0

Details

Language
Python
Created
Jun 27, 2026
Updated
1h ago
Size
0.8 KB

Build your snippet library

Join thousands of developers organizing and sharing code snippets.