Add stream mode example
This commit is contained in:
@@ -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]")
|
||||||
Reference in New Issue
Block a user