langchain-ai / langchain

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

when using qianfan chat streaming occurs TypeError: Additional kwargs key sentence_id already exists in left dict and value has unsupported type <class 'int'>. #18441

Closed Tangent-90C closed 2 months ago

Tangent-90C commented 7 months ago

Checked other resources

Example Code

qianfan_model = QianfanChatEndpoint(model='ERNIE-Bot', qianfan_ak=...... ,
                                    qianfan_sk=......)

for chunk in qianfan_model.stream(input_prompt):
    all_output += chunk.content
    print(chunk.content, end="", flush=True)

Error Message and Stack Trace (if applicable)

Traceback (most recent call last): File "E:\JMIT\JMIT3\code\ans.py", line 247, in print(retrieve_ans_chat_stream('我想離婚,孩子該怎麼判?', history=[('你好', '你好呀')])) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\JMIT\JMIT3\code\ans.py", line 236, in retrieve_ans_chat_stream for chunk in qianfan_model.stream(input_prompt): File "E:\envs\JMIT\Lib\site-packages\langchain_core\language_models\chat_models.py", line 250, in stream raise e File "E:\envs\JMIT\Lib\site-packages\langchain_core\language_models\chat_models.py", line 241, in stream generation += chunk File "E:\envs\JMIT\Lib\site-packages\langchain_core\outputs\chat_generation.py", line 57, in add generation_info = merge_dicts( ^^^^^^^^^^^^ File "E:\envs\JMIT\Lib\site-packages\langchain_core\utils_merge.py", line 38, in merge_dicts raise TypeError( TypeError: Additional kwargs key created already exists in left dict and value has unsupported type <class 'int'>.

Description

This bug occurs when the langchain_core>0.1.12 Downgrading to langchain_core==0.1.12 is bug-free

System Info

langchain==0.1.10 langchain-community==0.0.25 langchain-core==0.1.28 langchain-text-splitters==0.0.1

windows

Python 3.11.7

liugddx commented 7 months ago

The logic of chunk merging is relatively complicated. I think it is possible to formulate some keys that need to be merged.

image image

@baskaryan Please give me some suggestions and I will fix it.

axiangcoding commented 5 months ago

Same issue. any update on this error?

liugddx commented 5 months ago

Same issue. any update on this error?

It has been solved, please see the associated PR.https://github.com/langchain-ai/langchain/pull/18889

axiangcoding commented 5 months ago

Same issue. any update on this error?

It has been solved, please see the associated PR.#18889

Thanks. Update to the latest langchain can fix this issue.