langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
95.2k stars 15.44k forks source link

include_raw=True disable streaming #27461

Open underthesand opened 1 month ago

underthesand commented 1 month ago

Checked other resources

Example Code

Hello, there is no way to retrieve the tokens used (usage) with Azure when using streaming and structured_output.

structured_llm = llm.with_structured_output(Joke, include_raw=True)

for chunk in structured_llm.stream("Tell me a joke about cats")
    print(chunk)

https://python.langchain.com/docs/how_to/structured_output/

Error Message and Stack Trace (if applicable)

No response

Description

This code disables streaming. We have to wait for the complete generation to get a response.

Expected behavior: We should be able to use streaming and retrieve the usage metadata at the end.

System Info

System Information

OS: Linux OS Version: #47~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Oct 2 16:16:55 UTC 2 Python Version: 3.11.10 | packaged by conda-forge | (main, Sep 22 2024, 14:10:38) [GCC 13.3.0]

Package Information

langchain_core: 0.3.12 langchain: 0.3.3 langsmith: 0.1.128 langchain_openai: 0.2.2 langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph langserve

Other Dependencies

aiohttp: 3.9.5 async-timeout: Installed. No version info available. httpx: 0.27.0 jsonpatch: 1.33 numpy: 1.26.4 openai: 1.52.0 orjson: 3.10.5 packaging: 24.1 pydantic: 2.7.4 PyYAML: 6.0.1 requests: 2.32.3 SQLAlchemy: 2.0.35 tenacity: 8.5.0 tiktoken: 0.7.0 typing-extensions: 4.12.2

eyurtsev commented 1 month ago

We don't have a chunk for this kind of 2-tuple right now. What's your use case?

underthesand commented 2 weeks ago

hello, get tokens used (usage) with Azure when using streaming and structured_output