from openai import OpenAI
from composo import Composo

openai_client = OpenAI()
composo_client = Composo()

# --- Example 1: Initial response with built-in tools ---
input_1 = (
    "Search the web for the latest news story on SpaceX and write a Python script "
    "to plot their latest 3 launch dates"
)

response = openai_client.responses.create(
    model="gpt-4.1",
    input=input_1,
    tools=[
        {"type": "web_search"},
        {"type": "code_interpreter", "container": {"type": "auto"}},
    ],
)

eval_result_1 = composo_client.evaluate(
    input=input_1,
    result=response,
    criteria="Reward responses that search the web and produce working Python code",
)

print("Example 1 evaluation:")
print(f"  Score: {eval_result_1.score}")
print(f"  Explanation: {eval_result_1.explanation}")

# --- Example 2: Follow-up using previous_response_id ---
# Note: Composo only sees this follow-up turn in isolation (not the full prior
# conversation), so the evaluation won't be particularly meaningful — but it
# should complete without errors.
input_2 = "Now also display the same data as a table."

follow_up = openai_client.responses.create(
    model="gpt-4.1",
    previous_response_id=response.id,
    input=input_2,
    tools=[
        {"type": "web_search"},
        {"type": "code_interpreter", "container": {"type": "auto"}},
    ],
)

eval_result_2 = composo_client.evaluate(
    input=input_2,
    result=follow_up,
    criteria="Reward responses that produce working Python code displaying data as a table",
)

print("\nExample 2 evaluation (follow-up, limited context):")
print(f"  Score: {eval_result_2.score}")
print(f"  Explanation: {eval_result_2.explanation}")
