Add stream mode example

This commit is contained in:
2026-05-28 16:52:07 +00:00
parent b538a7059a
commit d09de9c98e
+13
View File
@@ -0,0 +1,13 @@
import os
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
# Example of streaming with LangChain
if __name__ == "__main__":
# Use OpenAI API key from env
os.environ.setdefault("OPENAI_API_KEY", "sk-...")
model = ChatOpenAI(temperature=0.7)
# Stream response
for chunk in model.stream([HumanMessage(content="Hello, world!" )]):
print(chunk.content, end="", flush=True)
print("\n[Done]")