# =====================================================
# Victor Evidence SDK — LLM-Only Integration Example
#
# example_llm_only_v1_0.py
#
# Architecture:
#   LLM → Victor → Application
#
# This example demonstrates evaluation of whether
# sufficient admissible evidence exists within a
# language model response without corpus retrieval.
#
# Victor Evidence validates semantic admissibility only.
# It does NOT generate content.
#
# Dependencies:
# pip install requests openai anthropic
# =====================================================


# =====================================================
# CONFIGURATION
# =====================================================

LLM_PROVIDER = "openai"  # openai, anthropic, ollama

OPENAI_API_KEY = "YOUR_OPENAI_API_KEY"
ANTHROPIC_API_KEY = "YOUR_ANTHROPIC_API_KEY"
VICTOR_API_KEY = "YOUR_VICTOR_API_KEY"

MODEL = "gpt-4o-mini"


# =====================================================
# LLM GENERATION FUNCTION
# =====================================================

def generate_answer(prompt):

    if LLM_PROVIDER == "openai":

        from openai import OpenAI
        client = OpenAI(api_key=OPENAI_API_KEY)

        response = client.responses.create(
            model=MODEL,
            input=prompt
        )

        return response.output_text.strip()

    elif LLM_PROVIDER == "anthropic":

        from anthropic import Anthropic
        client = Anthropic(api_key=ANTHROPIC_API_KEY)

        response = client.messages.create(
            model="claude-3-sonnet-20240229",
            max_tokens=1024,
            messages=[{"role": "user", "content": prompt}]
        )

        return response.content[0].text.strip()

    elif LLM_PROVIDER == "ollama":

        import ollama

        response = ollama.chat(
            model="llama3",
            messages=[{"role": "user", "content": prompt}]
        )

        return response["message"]["content"].strip()

    else:
        raise Exception("Unsupported LLM provider.")


# =====================================================
# INITIALIZE VICTOR
# =====================================================

from victor_ai_sdk_v1_0 import VictorAI

victor = VictorAI(victor_api_key=VICTOR_API_KEY)


# =====================================================
# USER QUESTION
# =====================================================

question = "What are human rights?"


# =====================================================
# STEP 1 — GENERATE LLM RESPONSE
# =====================================================

answer_text = generate_answer(question)


# =====================================================
# STEP 2 — EVALUATE EVIDENCE SUFFICIENCY
# =====================================================

result = victor.validate(
    question=question,
    answer=answer_text
)


# =====================================================
# STEP 3 — APPLICATION GATING
# =====================================================

print("\nLLM Output:\n")
print(answer_text)

print("\nVictor Gate:", result.get("gate"))
print("Retrieval Strength:", result.get("retrieval_pct"))

if result.get("gate") == "PASS":
    print("\nSufficient admissible evidence detected.")
else:
    print("\nSufficient admissible evidence not established.")