"""Load a local document into a new space and ask it a question."""

from pathlib import Path

from contextbase import Answer, ContextBase
from contextbase.types import SpaceLLMConfig


def load_and_ask(
    client: ContextBase,
    handbook: Path,
    question: str,
    *,
    llm_config: SpaceLLMConfig,
) -> Answer:
    """Create a space with the supplied model and retain it for reuse."""
    space = client.spaces.create('SDK handbook', llm_config=llm_config)
    document = space.documents.upload(handbook)
    space.documents.wait_indexed([document.id], timeout=120)
    return space.query(question)
