Spaces:
Sleeping
Sleeping
Download debug_stream.py from bagustenan/backend: direct link, hf CLI and curl.
- Browser
- Download file 771 Bytes
-
https://huggingface.co/spaces/bagustenan/backend/resolve/main/debug_stream.py
- Command line
-
hf download hf://spaces/bagustenan/backend/debug_stream.py
-
curl -L -o debug_stream.py https://huggingface.co/spaces/bagustenan/backend/resolve/main/debug_stream.py
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()) | |