python-3.x 不再支持来自langchain根模块的XMLLLMChain

uwopmtnx  于 2023-10-21  发布在  Python
关注(0)|答案(3)|浏览(419)

我试图创建一个冒险游戏与人工智能,基于本教程https://www.youtube.com/watch?v=nhYcTh6vw9A&t=966s
但是,我收到这样的错误消息:
不再支持langchain根模块的XMLLLMChain。
这是代码:

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
sq1bmfud

sq1bmfud1#

根据this article,我认为langchain将其大部分链移动到自己的目录中,称为chains。所以使用from langchain.chains import LLMChain应该可以

wfauudbj

wfauudbj2#

我可以通过在代码中添加这行代码来解决/消除“不支持从langchain根模块导入llm_cache”的相关警告:

from langchain.globals import set_llm_cache, get_llm_cache
doinxwow

doinxwow3#

截至2023年10月,llms模块都以不同的方式组织,例如:

from langchain.llms import GPT4All, OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains.prompt_selector import ConditionalPromptSelector
from langchain.memory import ConversationBufferWindowMemory

相关问题