检查其他资源
- 我为这个问题添加了一个非常描述性的标题。
- 我使用集成搜索在LangChain文档中进行了搜索。
- 我使用GitHub搜索查找了一个类似的问题,但没有找到。
- 我确信这是LangChain中的一个错误,而不是我的代码。
- 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。
示例代码
from langchain_aws import ChatBedrock
from pydantic import BaseModel, Field
class Joke(BaseModel):
setup: str = Field(description="The setup of the joke")
punchline: str = Field(description="The punchline to the joke")
chat = ChatBedrock(
model_id="anthropic.claude-3-haiku-20240307-v1:0",
model_kwargs={"temperature": 0.1},
region_name="my-region-name",
credentials_profile_name="my-profile-name",
streaming=True,
).bind_tools([Joke])
chat.invoke(""tell me a joke")```
### Error Message and Stack Trace (if applicable)
```shell
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
Cell In[22], [line 1](vscode-notebook-cell:?execution_count=22&line=1)
----> [1](vscode-notebook-cell:?execution_count=22&line=1) chain.invoke("tell me a joke")
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4653, in RunnableBindingBase.invoke(self, input, config, **kwargs)
[4647](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4647) def invoke(
[4648](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4648) self,
[4649](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4649) input: Input,
[4650](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4650) config: Optional[RunnableConfig] = None,
[4651](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4651) **kwargs: Optional[Any],
[4652](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4652) ) -> Output:
-> [4653](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4653) return self.bound.invoke(
[4654](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4654) input,
[4655](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4655) self._merge_configs(config),
[4656](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4656) **{**self.kwargs, **kwargs},
[4657](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/runnables/base.py:4657) )
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:265, in BaseChatModel.invoke(self, input, config, stop, **kwargs)
[254](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:254) def invoke(
[255](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:255) self,
[256](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:256) input: LanguageModelInput,
(...)
[260](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:260) **kwargs: Any,
[261](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:261) ) -> BaseMessage:
[262](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:262) config = ensure_config(config)
[263](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:263) return cast(
[264](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:264) ChatGeneration,
--> [265](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:265) self.generate_prompt(
[266](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:266) [self._convert_input(input)],
[267](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:267) stop=stop,
[268](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:268) callbacks=config.get("callbacks"),
[269](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:269) tags=config.get("tags"),
[270](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:270) metadata=config.get("metadata"),
[271](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:271) run_name=config.get("run_name"),
[272](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:272) run_id=config.pop("run_id", None),
[273](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:273) **kwargs,
[274](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:274) ).generations[0][0],
[275](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:275) ).message
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:698, in BaseChatModel.generate_prompt(self, prompts, stop, callbacks, **kwargs)
[690](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:690) def generate_prompt(
[691](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:691) self,
[692](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:692) prompts: List[PromptValue],
(...)
[695](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:695) **kwargs: Any,
[696](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:696) ) -> LLMResult:
[697](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:697) prompt_messages = [p.to_messages() for p in prompts]
--> [698](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:698) return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:555, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)
[553](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:553) if run_managers:
[554](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:554) run_managers[i].on_llm_error(e, response=LLMResult(generations=[]))
--> [555](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:555) raise e
[556](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:556) flattened_outputs = [
[557](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:557) LLMResult(generations=[res.generations], llm_output=res.llm_output) # type: ignore[list-item]
[558](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:558) for res in results
[559](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:559) ]
[560](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:560) llm_output = self._combine_llm_outputs([res.llm_output for res in results])
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:545, in BaseChatModel.generate(self, messages, stop, callbacks, tags, metadata, run_name, run_id, **kwargs)
[542](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:542) for i, m in enumerate(messages):
[543](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:543) try:
[544](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:544) results.append(
--> [545](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:545) self._generate_with_cache(
[546](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:546) m,
[547](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:547) stop=stop,
[548](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:548) run_manager=run_managers[i] if run_managers else None,
[549](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:549) **kwargs,
[550](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:550) )
[551](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:551) )
[552](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:552) except BaseException as e:
[553](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:553) if run_managers:
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:770, in BaseChatModel._generate_with_cache(self, messages, stop, run_manager, **kwargs)
[768](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:768) else:
[769](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:769) if inspect.signature(self._generate).parameters.get("run_manager"):
--> [770](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:770) result = self._generate(
[771](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:771) messages, stop=stop, run_manager=run_manager, **kwargs
[772](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:772) )
[773](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:773) else:
[774](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_core/language_models/chat_models.py:774) result = self._generate(messages, stop=stop, **kwargs)
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521, in ChatBedrock._generate(self, messages, stop, run_manager, **kwargs)
[519](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:519) if self.streaming:
[520](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:520) response_metadata: List[Dict[str, Any]] = []
--> [521](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521) for chunk in self._stream(messages, stop, run_manager, **kwargs):
[522](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:522) completion += chunk.text
[523](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:523) response_metadata.append(chunk.message.response_metadata)
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442, in ChatBedrock._stream(self, messages, stop, run_manager, **kwargs)
[440](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:440) if "claude-3" in self._get_model():
[441](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:441) if _tools_in_params({**kwargs}):
--> [442](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442) result = self._generate(
[443](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:443) messages, stop=stop, run_manager=run_manager, **kwargs
[444](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:444) )
[445](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:445) message = result.generations[0].message
[446](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:446) if isinstance(message, AIMessage) and message.tool_calls is not None:
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521, in ChatBedrock._generate(self, messages, stop, run_manager, **kwargs)
[519](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:519) if self.streaming:
[520](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:520) response_metadata: List[Dict[str, Any]] = []
--> [521](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521) for chunk in self._stream(messages, stop, run_manager, **kwargs):
[522](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:522) completion += chunk.text
[523](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:523) response_metadata.append(chunk.message.response_metadata)
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442, in ChatBedrock._stream(self, messages, stop, run_manager, **kwargs)
[440](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:440) if "claude-3" in self._get_model():
[441](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:441) if _tools_in_params({**kwargs}):
--> [442](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442) result = self._generate(
[443](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:443) messages, stop=stop, run_manager=run_manager, **kwargs
[444](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:444) )
[445](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:445) message = result.generations[0].message
[446](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:446) if isinstance(message, AIMessage) and message.tool_calls is not None:
[... skipping similar frames: ChatBedrock._generate at line 521 (734 times), ChatBedrock._stream at line 442 (734 times)]
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521, in ChatBedrock._generate(self, messages, stop, run_manager, **kwargs)
[519](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:519) if self.streaming:
[520](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:520) response_metadata: List[Dict[str, Any]] = []
--> [521](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:521) for chunk in self._stream(messages, stop, run_manager, **kwargs):
[522](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:522) completion += chunk.text
[523](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:523) response_metadata.append(chunk.message.response_metadata)
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442, in ChatBedrock._stream(self, messages, stop, run_manager, **kwargs)
[440](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:440) if "claude-3" in self._get_model():
[441](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:441) if _tools_in_params({**kwargs}):
--> [442](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:442) result = self._generate(
[443](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:443) messages, stop=stop, run_manager=run_manager, **kwargs
[444](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:444) )
[445](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:445) message = result.generations[0].message
[446](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:446) if isinstance(message, AIMessage) and message.tool_calls is not None:
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:517, in ChatBedrock._generate(self, messages, stop, run_manager, **kwargs)
[514](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:514) llm_output: Dict[str, Any] = {}
[515](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:515) tool_calls: List[Dict[str, Any]] = []
[516](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:516) provider_stop_reason_code = self.provider_stop_reason_key_map.get(
--> [517](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:517) self._get_provider(), "stop_reason"
[518](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:518) )
[519](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:519) if self.streaming:
[520](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/chat_models/bedrock.py:520) response_metadata: List[Dict[str, Any]] = []
File ~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:585, in BedrockBase._get_provider(self)
[583](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:583) if self.provider:
[584](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:584) return self.provider
--> [585](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:585) if self.model_id.startswith("arn"):
[586](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:586) raise ValueError(
[587](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:587) "Model provider should be supplied when passing a model ARN as "
[588](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:588) "model_id"
[589](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:589) )
[591](https://file+.vscode-resource.vscode-cdn.net/Users/tommasodelorenzo/Documents/clients/kontrata/juztina/ai-core/app/~/Documents/clients/kontrata/juztina/ai-core/.venv/lib/python3.12/site-packages/langchain_aws/llms/bedrock.py:591) return self.model_id.split(".")[0]
RecursionError: maximum recursion depth exceeded while calling a Python object```
### Description
- I am trying to stream with tool calling (recently added by Anthropic).
- Setting `streaming = False` works.
- Setting `streaming = True` I get recursion error.
- The same setting works using `ChatAnthropic` class.
### System Info
Python 3.12.1
langchain-anthropic==0.1.19
langchain-aws==0.1.10
langchain-core==0.2.13
langchain-openai==0.1.15
langchain-qdrant==0.1.1
1条答案
按热度按时间blpfk2vs1#
获取相同的错误...当删除
streaming=True
时,它可以正常工作。