langchain-ai / langchain-google

MIT License
76 stars 79 forks source link

TypeError: Additional kwargs key is_blocked already exists #222

Closed duob-ai closed 3 weeks ago

duob-ai commented 1 month ago

This is probably related to this issue here.

Certain prompts in a simple RAG chain seem to cause a TypeError. Same prompts previously caused the IndexError mentioned in the above issue. No problems with other LLM providers like Azure.

Full log from Langsmith

TypeError("Additional kwargs key is_blocked already exists in left dict and value has unsupported type <class 'bool'>.")Traceback (most recent call last):

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1980, in _atransform_stream_with_config chunk: Output = await asyncio.create_task( # type: ignore[call-arg] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/log_stream.py", line 237, in tap_output_aiter async for chunk in output:

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform async for output in final_pipeline:

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 4748, in atransform async for item in self.bound.atransform(

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2883, in atransform async for chunk in self._atransform_stream_with_config(

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1980, in _atransform_stream_with_config chunk: Output = await asyncio.create_task( # type: ignore[call-arg] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/log_stream.py", line 237, in tap_output_aiter async for chunk in output:

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 2853, in _atransform async for output in final_pipeline:

File "/usr/local/lib/python3.11/site-packages/langchain_core/output_parsers/transform.py", line 60, in atransform async for chunk in self._atransform_stream_with_config(

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1980, in _atransform_stream_with_config chunk: Output = await asyncio.create_task( # type: ignore[call-arg] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/tracers/log_stream.py", line 237, in tap_output_aiter async for chunk in output:

File "/usr/local/lib/python3.11/site-packages/langchain_core/output_parsers/transform.py", line 38, in _atransform async for chunk in input:

File "/usr/local/lib/python3.11/site-packages/langchain_core/utils/aiter.py", line 97, in tee_peer item = await iterator.anext() ^^^^^^^^^^^^^^^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/runnables/base.py", line 1334, in atransform async for output in self.astream(final, config, **kwargs):

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 319, in astream raise e

File "/usr/local/lib/python3.11/site-packages/langchain_core/language_models/chat_models.py", line 312, in astream generation += chunk

File "/usr/local/lib/python3.11/site-packages/langchain_core/outputs/chat_generation.py", line 74, in add generation_info = merge_dicts( ^^^^^^^^^^^^

File "/usr/local/lib/python3.11/site-packages/langchain_core/utils/_merge.py", line 40, in merge_dicts raise TypeError(

TypeError: Additional kwargs key is_blocked already exists in left dict and value has unsupported type <class 'bool'>.

lkuligin commented 1 month ago

could you share a reproducible snippet, please?

duob-ai commented 1 month ago

could you share a reproducible snippet, please?

I‘m basically using the RAG chain reference implementation from here: https://github.com/langchain-ai/chat-langchain/blob/master/backend/chain.py

Only difference is the llm that I‘m using: llm = ChatVertexAI(model_name="gemini-1.5-pro-preview-0514")

Strangely it works fine for most prompts and it only throws the error in like 10-20% of the cases. Error is reproducible when using the same prompts.

The same prompts previously (v 1.0.1) gave me the IndexError in the issue mentioned above. That’s why I think both issues are related

lkuligin commented 3 weeks ago

I assume I have a fix, but it would be great if you could provide a reproducible example for a test case.