[Python] Importing LLMChain from langchain root module is no longer supported

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create an adventure game with AI, based on this tutorial https://www.youtube.com/watch?v=nhYcTh6vw9A&t=966s

    However, I am getting error message like this:


    Importing LLMChain from langchain root module is no longer supported.
    ​

    This is the code:

    from cassandra.cluster import Cluster
    from cassandra.auth import PlainTextAuthProvider
    from langchain.memory import CassandraChatMessageHistory, ConversationBufferMemory
    from langchain.llms import OpenAI
    from langchain import LLMChain, PromptTemplate
    import json

    cloud_config= {
    'secure_connect_bundle': 'secure-connect-choose-your-own-adventure.zip'
    }

    with open("choose_your_own_adventure-token.json") as f:
    secrets = json.load(f)

    CLIENT_ID = secrets["clientId"]
    CLIENT_SECRET = secrets["secret"]
    ASTRA_DB_KEYSPACE = ""
    OPENAI_API_KEY = ""

    auth_provider = PlainTextAuthProvider(CLIENT_ID, CLIENT_SECRET)
    cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
    session = cluster.connect()

    message_history = CassandraChatMessageHistory(
    session_id="anything",
    session=session,
    keyspace=ASTRA_DB_KEYSPACE,
    ttl_seconds=3600
    )

    message_history.clear()

    cass_buff_memory = ConversationBufferMemory(
    memory_key="chat_history",
    chat_memory=message_history
    )

    template = """..."""

    prompt = PromptTemplate(
    input_variables=["chat_history", "human_input"],
    template=template
    )

    llm = OpenAI(openai_api_key=OPENAI_API_KEY)
    llm_chain = LLMChain(
    llm=llm,
    prompt=prompt,
    memory=cass_buff_memory
    )

    choice = "start"

    while True:
    response = llm_chain.predict(human_input=choice)
    print(response.strip())

    if "The End." in response:
    break

    choice = input("Your reply: ") ```

    I tried to import libraries and expected them to work

    Continue reading...

Compartilhe esta Página