# This demo shows how to use the Sec-Gemini SDK to access files.

# This tells UV to load the local sec_gemini package.
# Run this demo with: SEC_GEMINI_API_KEY=your_api_key uv run demo_files.py
# /// script
# dependencies = [
#   "sec-gemini-3",
# ]
#
# [tool.uv.sources]
# sec_gemini = { path = "../", editable = true }
# ///

import asyncio
import os
import tempfile

from sec_gemini import SecGemini

API_KEY = os.environ.get("SEC_GEMINI_API_KEY", "pass your sec gemini api key here")


async def main():
    client = SecGemini(api_key=API_KEY)
    await client.start()
    session = await client.create_session()

    print("Uploading files...")
    with tempfile.TemporaryDirectory() as tmpdir:
        with open(os.path.join(tmpdir, "secret.txt"), "w") as f:
            f.write("The secret it 'friendly potatoes")
        await session.files.upload(file_path=f.name)
    files = await session.files.list()
    for f in files:
        print(f" - File: {f.filename} ({f.url})")

    prompt = "I gave you a file. what's the secret message in it?"
    print(f"We now ask Sec-Gemini to access the file and answer: {prompt}")
    await session.prompt(prompt)
    print("Streaming messages...")
    async for msg in session.messages.stream():
        print(f"\nMessage> Title: {msg.get('title')}")
        print(f"         Content: {msg.get('content')}")

    print("Closing client...")
    await session.delete()
    await client.close()


if __name__ == "__main__":
    asyncio.run(main())
