[Python] How do I update my get_history() function to use...

Discussão em 'Python' iniciado por Stack, Julho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I’m updating a LangChain-based app to use the new langchain_postgres package instead of the deprecated langchain_community.chat_message_histories.

    Previously, my function looked like this:

    from langchain_community.chat_message_histories import PostgresChatMessageHistory
    import os

    def get_history(session_id: str) -> PostgresChatMessageHistory:
    connection_string = os.getenv("POSTGRES_CONNECTION_STRING")
    if not connection_string:
    raise ValueError("POSTGRES_CONNECTION_STRING environment variable is not set")

    return PostgresChatMessageHistory(
    session_id=session_id,
    connection_string=connection_string,
    table_name="chat_message_history",
    )


    After switching from:

    from langchain_community.chat_message_histories import PostgresChatMessageHistory

    to:

    from langchain_postgres import PostgresChatMessageHistory

    …I get this warning in VSCode:

    Expected 2 more positional arguments (Pylance reportCallIssue)

    What I’ve Tried

    I understand that the new PostgresChatMessageHistory requires more arguments, but I can’t find updated documentation or examples that clarify which ones are mandatory and what values to use for them.

    Question

    What is the correct way to rewrite my get_history() function to work with langchain_postgres.PostgresChatMessageHistory?

    Thanks in advance!

    Continue reading...

Compartilhe esta Página