[Python] Error with file_search tool in langchain python library

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have an error with my langchain-openai when I use the file_search tool:

    File "/backend/.venv/lib/python3.11/site-packages/langchain_openai/chat_models/base.py", line 3386, in _convert_responses_chunk_to_generation_chunk
    | chunk.annotation.model_dump(exclude_none=True, mode="json")
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | AttributeError: 'dict' object has no attribute 'model_dump'


    My code to generate the response:

    prompt = chat_prompt
    vectore_store_id = "vs_68341b563aac8191af2df101ef7066a6"

    fileTool = {"type": "file_search", "vector_store_ids": [vectore_store_id]}

    llm_with_tools = self.llm.bind_tools([fileTool])

    chain = prompt | llm_with_tools
    output = ""
    async for chunk in chain.astream(
    {
    "query": query,
    "question": question,
    "context": query_context,
    "history": log,
    },
    ):
    try:
    print(chunk.type)
    output += chunk.text()
    yield AIMessageChunk(content=chunk.text())
    except Exception:
    print("Err")


    If I don't use the file_search tool, the code works fine.

    @property
    def chat_prompt(self):
    current_date = datetime.now().strftime("%B %d, %Y at %I:%M %p")

    messages = [
    SystemMessagePromptTemplate.from_template(
    "You are top mortgage subject matter expert working.\n"
    ),
    HumanMessagePromptTemplate.from_template("{query}"),
    ]

    prompt = ChatPromptTemplate(messages=messages)
    return prompt


    Packages:

    • pydantic 2.11.5
    • pydantic_core 2.33.2
    • pydantic-settings 2.9.1
    • langchain 0.3.25
    • langchain-core 0.3.61
    • langchain-openai 0.3.16

    Continue reading...

Compartilhe esta Página