import asyncio
from honcho import Honcho
async def restaurant_recommendation_chat():
    honcho = Honcho()
    app = await honcho.apps.get_or_create(name="food-app")
    user = await honcho.apps.users.get_or_create(app_id=app.id, name="food-lover")
    session = await honcho.apps.users.sessions.create(app_id=app.id, user_id=user.id)
    # Store multiple user messages about food preferences
    user_messages = [
        "I absolutely love spicy Thai food, especially curries with coconut milk.",
        "Italian cuisine is another favorite - fresh pasta and wood-fired pizza are my weakness!",
        "I try to eat vegetarian most of the time, but occasionally enjoy seafood.",
        "I can't handle overly sweet desserts, but love something with dark chocolate."
    ]
    # Store the user's messages in the session
    for message in user_messages:
        await honcho.apps.users.sessions.messages.create(
            app_id=app.id,
            user_id=user.id,
            session_id=session.id,
            content=message,
            is_user=True
        )
        print(f"User: {message}")
    # Ask for restaurant recommendations based on preferences
    print("\nRequesting restaurant recommendations...")
    print("Assistant: ", end="", flush=True)
    full_response = ""
    # Stream the response
    with honcho.apps.users.sessions.with_streaming_response.stream(
        app_id=app.id,
        user_id=user.id,
        session_id=session.id,
        queries="Based on this user's food preferences, recommend 3 restaurants they might enjoy in the Lower East Side."
    ) as response:
        for chunk in response.iter_text():
            print(chunk, end="", flush=True)
            full_response += chunk
            await asyncio.sleep(0.01)
    # Store the assistant's complete response
    await honcho.apps.users.sessions.messages.create(
        app_id=app.id,
        user_id=user.id,
        session_id=session.id,
        content=full_response,
        is_user=False
    )
# Run the async function
if __name__ == "__main__":
    asyncio.run(restaurant_recommendation_chat())