backend / debug_stream.py
riosiahaan's picture
Deploy to new spaces
495399f
Raw History Blame Contribute Delete
771 Bytes
import os
import asyncio
from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.messages import HumanMessage
load_dotenv()
async def test_stream():
print("Testing Gemini Streaming...")
llm = ChatGoogleGenerativeAI(
model="gemini-2.5-flash",
temperature=0,
streaming=True,
api_key=os.getenv("GOOGLE_API_KEY")
)
print("Invoking astream...")
try:
async for chunk in llm.astream([HumanMessage(content="Halo, hitung 1 sampai 5!")]):
print(f"Chunk received: {chunk.content}", end="|", flush=True)
print("\nDone.")
except Exception as e:
print(f"\nError: {e}")
if __name__ == "__main__":
asyncio.run(test_stream())