Week 13

    ANTI-PLAGIARISM_INATOR ARCHITECTURE

    HUNTER (model A)
    -Autonomous Web Agent
    locates professionaly used AI generated images
    ->
    JUDGE (model B)
    -Visual Forensics Model
    finds source images used in generation

Initially, I had high hopes for this project. I wanted to create a tool that could find AI images used for advertising, and then find original artists so they could be notified. This tool could also be used to notify victims of nonconsensual generative image modification, which is a massive issue brought on by the boom of AI tools. I spent hours attempting to find models I could actually get an API connection working with, before I abandoned this idea due to scope.

    STUPID_AI (20Q) ARCHITECTURE

    SECRET WORD (input)
    -Human
    information known by Oracle, not by Guesser
    ->
    GUESSER (model A)
    -Reasoning Agent
    asks yes or no question to increase confidence
    ->
    ORACLE (model B)
    -Verification Agent
    answers yes or no question based on input
    ->
    LOOP TO GUESSER

This project was much more manageable. The basic concept is that one model knows a secret word. A separate model tries to guess the secret word by asking yes or no questions to the first model. They have 20 attempts to get it right. The prototype was built in VS Code using llama-3.3-70b (Oracle) and llama-3.1-8b (Guesser).

STUPID_AI (20Q):

    import os
import time
import requests
from dotenv import load_dotenv

load_dotenv(".secret.env")
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
if not GROQ_API_KEY:
    raise RuntimeError("GROQ_API_KEY not found in .secret.env")

HEADERS = {
    "Authorization": f"Bearer {GROQ_API_KEY}",
    "Content-Type": "application/json"
}

MODEL_GUESSER = "llama-3.1-8b-instant"
MODEL_ORACLE = "llama-3.3-70b-versatile"
TURN_DELAY = 2.2

def call_model(messages, model_name, max_tokens=50):
    url = "https://api.groq.com/openai/v1/chat/completions"
    data = {
        "model": model_name,
        "messages": messages,
        "max_tokens": max_tokens
    }
    response = requests.post(url, headers=HEADERS, json=data)
    if response.status_code != 200:
        raise RuntimeError(response.text)
    return response.json()["choices"][0]["message"]["content"].strip()

def main():
    print("GROQ_API_KEY loaded successfully!\n")
    print("20 Questions Game Started!\n")

    secret_word = input("Enter a secret word (guesser cannot see this): ").strip()
    print("\nSecret word stored. Game begins!\n")

    asked_questions = []
    turn = 1
    guessed_correctly = False

    while turn <= 20:
        is_final_turn = turn == 20

        guesser_prompt = [
            {
                "role": "system",
                "content": (
                    "You are the Guesser in a 20 Questions game. "
                    "Ask one yes/no question per turn to figure out the secret word. "
                    "Do NOT repeat previous questions. "
                    "If this is turn 20 or if you are confident you know the word, "
                    "output ONLY your final guess word. "
                    "Before the final guess, only ask yes/no questions."
                )
            },
            {
                "role": "user",
                "content": (
                    f"Turn {turn}. Previous Q&A:\n"
                    + "\n".join(f"Q: {q} A: {a}" for q, a in asked_questions)
                    + ("\nProvide your final guess now:" if is_final_turn else "\nProvide your next yes/no question:")
                )
            }
        ]

        guess_output = call_model(
            guesser_prompt,
            MODEL_GUESSER,
            max_tokens=20
        ).strip()

        if secret_word.lower() in guess_output.lower():
            print(f"* Turn {turn}")
            print(f"AI ISN'T STUPID!!\nQ: {guess_output}\nA: Correct\n")
            guessed_correctly = True
            break

        oracle_prompt = [
            {
                "role": "system",
                "content": (
                    f"You are the Oracle. The secret word is '{secret_word}'. "
                    "Answer only 'Yes' or 'No' for normal questions. "
                    "If this is the final turn, answer 'Correct' if the Guesser's guess "
                    "matches exactly, else 'Incorrect'."
                )
            },
            {
                "role": "user",
                "content": guess_output
            }
        ]

        oracle_answer = call_model(
            oracle_prompt,
            MODEL_ORACLE,
            max_tokens=10
        ).strip()

        print(f"* Turn {turn}")
        print(f"Q: {guess_output}")
        print(f"A: {oracle_answer}\n")

        if not is_final_turn:
            asked_questions.append((guess_output, oracle_answer))

        if oracle_answer.lower() == "correct":
            guessed_correctly = True
            print(
                f"AI ISN'T STUPID! Guesser got it in {turn} turns! "
                f"The word was: {secret_word}"
            )
            break

        turn += 1
        time.sleep(TURN_DELAY)

    if not guessed_correctly:
        print(f"AI IS STUPID! Guesser did not get it. The word was: {secret_word}")

if __name__ == "__main__":
    main()