Fact Check: A lightning strike can cook a tree from the inside out.

Status: True

Assertion

A lightning strike can cook a tree from the inside out.

Results

<|assistant|> – True: The statements provided are accurate and align with scientific knowledge about lightning’s effects on trees. Therefore, I would classify this statement as “True.”

Assumptions

– Lightning generates extremely high temperatures (approximately 20,000-30,000 degrees Celsius).
– The intense heat and pressure changes from lightning strikes can rapidly vaporize sap within a tree’s trunk or branches.
– The statement is metaphorical rather than literal when describing the effect of lightning on trees (i.e., it doesn’t imply that wood is cooked like food).
– Different factors, such as species, age, health, location of the strike, and surrounding environment, can influence how severely a tree is damaged by a lightning strike.
– The term “cooking” used in this context refers to rapid heating and splitting caused by intense heat, not actual cooking processes like those used for food preparation.

Fact Checker Output

<|assistant|> – True: Lightning generates extremely high temperatures (approximately 20,000-30,000 degrees Celsius). This assertion is accurate based on scientific research and observations of lightning strikes; the temperature can indeed reach these extreme levels due to the rapid discharge of electricity.

– True: The intense heat and pressure changes from lightning strikes can rapidly vaporize sap within a tree’s trunk or branches. This statement is true, as the extreme temperatures generated by a lightning strike are capable of boiling water at that point in the tree, which would also result in the rapid vaporization of sap and potentially lead to internal damage.

– True: The statement is metaphorical rather than literal when describing the effect of lightning on trees (i.e., it doesn’t imply that wood is cooked like food). This assertion is true, as there are no instances where a tree would literally be “cooked” by lightning in the same way one might cook food; instead, it refers to the rapid heating and damage caused by an electrical discharge.

– True: Different factors, such as species,

Model Used

microsoft/Phi-3-mini-4k-instruct-gguf

Script Name

fact_checker_mongodb.py

Script Code

import os
import sys
import requests
from langchain_openai.llms import OpenAI
from langchain.prompts import PromptTemplate
from dotenv import load_dotenv
from statements import get_random_statement
from mongodb_helper import insert_record  # Import MongoDB helper functions
import html

# Load environment variables from .env file
load_dotenv()

# Define category IDs
CATEGORY_IDS = {
    "True": 2,
    "False": 3,
    "Debatable": 4
}

def create_wordpress_post(title, content, category):
    data = {
        "title": title,
        "content": content,
        "status": "publish",
        "categories": [CATEGORY_IDS[category]]
    }

    response = requests.post(
        os.getenv("WORDPRESS_POSTS_URL"),
        json=data,
        auth=(os.getenv("WORDPRESS_USERNAME"), os.getenv("WORDPRESS_PASSWORD"))
    )

    if response.status_code == 201:
        print("Blog post created successfully.")
    else:
        print(f"Failed to create blog post: {response.status_code} - {response.text}")

def fact_check(assertion):
    llm = OpenAI(temperature=0.7)

    # Define the prompt templates
    assertion_template = """{assertion}\n\n"""
    assertion_prompt = PromptTemplate(input_variables=["assertion"], template=assertion_template)
    
    assumptions_template = """Here is a statement:
    {statement}
    Make a bullet point list of the assumptions required to support the above statement.\n\n"""
    assumptions_prompt = PromptTemplate(input_variables=["statement"], template=assumptions_template)
    
    fact_checker_template = """Here is a bullet point list of assertions:
    {assertions}
    For each assumption, determine whether it is true or false. Explain your reasoning.\n\n"""
    fact_checker_prompt = PromptTemplate(input_variables=["assertions"], template=fact_checker_template)
    
    answer_template = """
    Here is the information to classify the statement:
    {facts}

    Based on the above information, how would you classify the statement? Respond with one of the following options:
    - True
    - False
    - Debatable
    """
    answer_prompt = PromptTemplate(input_variables=["facts"], template=answer_template)
    
    # Format prompts and extract the string content
    formatted_assertion = assertion_prompt.format_prompt(assertion=assertion).text
    assertion_output = llm.invoke(formatted_assertion)
    
    formatted_assumptions = assumptions_prompt.format_prompt(statement=assertion_output).text
    assumptions_output = llm.invoke(formatted_assumptions)
    
    formatted_fact_checker = fact_checker_prompt.format_prompt(assertions=assumptions_output).text
    fact_checker_output = llm.invoke(formatted_fact_checker)
    
    formatted_answer = answer_prompt.format_prompt(facts=fact_checker_output).text
    final_output = llm.invoke(formatted_answer)
    
    return {
        "assertion_output": assertion_output,
        "assumptions_output": assumptions_output,
        "fact_checker_output": fact_checker_output,
        "final_output": final_output,
    }

def extract_status(final_output):
    final_output = final_output.lower().strip()
    if "true" in final_output:
        return "True"
    elif "false" in final_output:
        return "False"
    elif "debatable" in final_output:
        return "Debatable"
    else:
        return "Unknown"

if __name__ == "__main__":
    if len(sys.argv) > 1:
        assertion = sys.argv[1]
    else:
        assertion = get_random_statement()
    
    print(assertion)
    submission = fact_check(assertion)
    
    # Print the detailed outputs to inspect their structure
    for key, value in submission.items():
        print(f"{key}: {value}")
    
    # Extract the final output for status determination
    final_output = submission['final_output']
    
    # Determine the status based on the final output text
    status = extract_status(final_output)
    
    # Record the result in MongoDB
    try:
        print("Attempting to insert record into MongoDB...")
        insert_record(
            script_name="fact_checker_mongodb.py",
            script_code=html.escape(open(__file__).read()),
            assertion=assertion,
            status=status,
            submission=submission,  # Store the entire submission for detailed analysis
            model=os.getenv("MODEL_NAME")
        )
        print("Record inserted into MongoDB successfully.")
    except Exception as e:
        print(f"Failed to insert record into MongoDB: {e}")
    
    print(final_output)
    
    # Create a blog post on WordPress
    blog_title = f"Fact Check: {assertion}"
    blog_content = f"""
    <h1>Status: {status}</h1>
    <h2>Assertion</h2>
    <p>{assertion}</p>
    <h2>Results</h2>
    <p>{final_output}</p>
    <h3>Assumptions</h3>
    <p>{submission['assumptions_output']}</p>
    <h3>Fact Checker Output</h3>
    <p>{submission['fact_checker_output']}</p>
    <h4>Model Used</h4>
    <p>{os.getenv("MODEL_NAME")}</p>
    <h4>Script Name</h4>
    <p>fact_checker_mongodb.py</p>
    <h4>Script Code</h4>
    <pre>{html.escape(open(__file__).read())}</pre>
    """
    create_wordpress_post(blog_title, blog_content, status)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *