我试图创建一个冒险游戏与人工智能,基于本教程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
3条答案
按热度按时间sq1bmfud1#
根据this article,我认为langchain将其大部分链移动到自己的目录中,称为chains。所以使用
from langchain.chains import LLMChain
应该可以wfauudbj2#
我可以通过在代码中添加这行代码来解决/消除“不支持从langchain根模块导入llm_cache”的相关警告:
doinxwow3#
截至2023年10月,
llms
模块都以不同的方式组织,例如: