检查其他资源
- 我为这个问题添加了一个非常描述性的标题。
- 我使用集成搜索在LangChain文档中进行了搜索。
- 我使用GitHub搜索找到了一个类似的问题,但没有找到。
- 我确信这是LangChain中的一个错误,而不是我的代码。
- 通过更新到LangChain的最新稳定版本(或特定集成包)无法解决此错误。
示例代码
以下代码:
import os
from typing import List
import dotenv
from langchain.output_parsers import OutputFixingParser
from langchain_core.output_parsers import PydanticOutputParser
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_openai import ChatOpenAI
dotenv.load_dotenv()
class Actor(BaseModel):
name: str = Field(description="name of an actor")
film_names: List[str] = Field(description="list of names of films they starred in")
actor_query = "Generate the filmography for a random actor."
parser = PydanticOutputParser(pydantic_object=Actor)
misformatted = "{'name': 'Tom Hanks', 'film_names': ['Forrest Gump']}"
new_parser = OutputFixingParser.from_llm(parser=parser, llm=ChatOpenAI(openai_api_base=os.getenv('OPENAI_API_BASE')))
print(new_parser.parse(misformatted))
错误信息和堆栈跟踪(如果适用)
Traceback (most recent call last):
File "/Users/zhangshenao/Desktop/LLM/happy-langchain/6-输出解析/2.使用OutputFixingParser自动修复解析器.py", line 39, in
print(new_parser.parse(misformatted))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain/output_parsers/fix.py", line 74, in parse
completion = self.retry_chain.invoke(
^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 2497, in invoke
input = step.invoke(input, config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/prompts/base.py", line 179, in invoke
return self._call_with_config(
^^^^^^^^^^^^^^0000000000000000000000000000000000000000000000000
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/runnables/config.py", line 380, in call_func_with_variable_args
return func(input, **kwargs) # type: ignore[call-arg]
^{^\nFile "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/prompts/base.py", line 153, in _format_prompt_with_error_handling
_inner_input = self._validate_input(inner_input)
^{^\nFile "/Library
2条答案
按热度按时间yyyllmsg1#
我使用的是同一个解析器。在将langchain和langchain_community从0.2.5更新到0.2.7后,出现了这个bug。为了立即解决问题,我认为回退到0.2.5应该可以解决它。
9ceoxa922#
应该通过这个修复:https://github.com/langchain-ai/langchain/pull/23967/files