13 lines
456 B
Python
13 lines
456 B
Python
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]") |