[Python] "NotImplementedError" encountered while "llm.bind_tools()"

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

  1. Stack

    Stack Membro Participativo

    I'm learning the langgraph tutorial code.

    When I used a customized llm which was inherited from the BaseChatModel, then the NotImplementedError occured. Here's my code:

    from typing import List
    from langchain_core.messages import SystemMessage
    from pydantic import BaseModel
    from langchain_openai import ChatOpenAI

    template = """Your job is to get information from a user about what type of prompt template they want to create.

    You should get the following information from them:

    - What the objective of the prompt is
    - What variables will be passed into the prompt template
    - Any constraints for what the output should NOT do
    - Any requirements that the output MUST adhere to

    If you are not able to discern this info, ask them to clarify! Do not attempt to wildly guess.

    After you are able to discern all the information, call the relevant tool."""

    def get_messages_info(messages):
    return [SystemMessage(content=template)] + messages

    class PromptInstructions(BaseModel):
    """Instructions on how to prompt the LLM."""
    objective: str
    variables: List[str]
    constraints: List[str]
    requirements: List[str]

    llm = CustomizedChatAI(secret_id=SecretID, secret_key=SecretKey) # inherited from langchain_core.language_models.BaseChatModel

    # llm = ChatOpenAI(
    # api_key="key",
    # base_url="url",
    # streaming=False,
    # model="model-name"
    # )

    llm_with_tool = llm.bind_tools([PromptInstructions])


    and then I got the error msg:

    ---------------------------------------------------------------------------
    NotImplementedError Traceback (most recent call last)
    Cell In[40], line 31
    24 llm = CustomizedChatAI(secret_id=SecretID, secret_key=SecretKey)
    25 # llm = ChatOpenAI(
    26 # api_key="key", #
    27 # base_url="https:url",
    28 # streaming=False,
    29 # model="model-name"
    30 # )
    ---> 31 llm_with_tool = llm.bind_tools([PromptInstructions])
    33 def info_chain(state):
    34 messages = get_messages_info(state["messages"])

    File C:\ProgramData\miniforge3\envs\llm\lib\site-packages\langchain_core\language_models\chat_models.py:1120, in BaseChatModel.bind_tools(self, tools, **kwargs)
    1115 def bind_tools(
    1116 self,
    1117 tools: Sequence[Union[Dict[str, Any], Type, Callable, BaseTool]],
    1118 **kwargs: Any,
    1119 ) -> Runnable[LanguageModelInput, BaseMessage]:
    -> 1120 raise NotImplementedError()

    NotImplementedError:


    but if i switch the llm to another customized model which wrapped by ChatOpenAI class, it works. According to the information I found, the class ChatOpenAI is inherited from the class BaseChatModel, then why it failed when I use the first customized llm inherited from the Class BaseChatModel?

    Continue reading...

Compartilhe esta Página