我不太清楚langchain中的sync stream 和 async steam有什么關系和區別
sync stream
from langchain.chat_models import init_chat_model
from langchain_deepseek.chat_models import ChatDeepSeek
import dotenv
dotenv.load_dotenv()messages = [
("system", "You are a helpful translator. Translate the user sentence to French."),
("human", "I love programming."),
]
llm = ChatDeepSeek(model="deepseek-chat")for chunk in llm.stream("Write me a 1 verse song about goldfish on the moon"):print(chunk.content, end="", flush=True)
Async Streaming
# async stream
import asyncioasync def main(): async for chunk in llm.astream("Write me a 1 verse song about goldfish on the moon"):print(chunk.content, end="|", flush=True)asyncio.run(main())
給langchain提了一個issue一個文檔pr不知道能不能過。