模块“chainlit”没有属性“langchain_factory”

cet*_*ian 4 attributes langchain large-language-model

我下载了仓库:https ://github.com/menloparklab/falcon-langchain

virtualenv为此创建了一个来安装requirments.txt并运行该应用程序。

使用以下命令运行应用程序后。

chainlit run app.py -w
Run Code Online (Sandbox Code Playgroud)

但我收到错误:

module 'chainlit' has no attribute 'langchain_factory'
Run Code Online (Sandbox Code Playgroud)

Cod*_*ker 5

在 Chainlit 的早期版本中,该factory概念作为 API 的一部分包含在内。然而,在收到反馈并评估其实用性后,开发人员决定将其删除,以简化 API 并避免用户混淆。

在最新版本的 Chainlit 中,您将不再找到以下 API:langchain_factorylangchain_runlangchain_postprocessllama_index_factorylangflow_factory

如果您的代码如下所示,

@cl.langchain_factory
def factory():
    prompt = PromptTemplate(template=template, input_variables=["question"])
    llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)

    return llm_chain
Run Code Online (Sandbox Code Playgroud)

如果您的机器上安装了最新版本的 chainlit,请使用以下代码来使用 chainlit,

@cl.on_chat_start
def main():
    # Instantiate the chain for that user session
    prompt = PromptTemplate(template=template, input_variables=["question"])
    llm_chain = LLMChain(prompt=prompt, llm=llm, verbose=True)

    # Store the chain in the user session
    cl.user_session.set("llm_chain", llm_chain)


@cl.on_message
async def main(message: str):
    # Retrieve the chain from the user session
    llm_chain = cl.user_session.get("llm_chain")  # type: LLMChain

    # Call the chain asynchronously
    res = await llm_chain.acall(message, callbacks=[cl.AsyncLangchainCallbackHandler()])

    # Do any post processing here

    # Send the response
    await cl.Message(content=res["text"]).send()
Run Code Online (Sandbox Code Playgroud)

了解更多:Chainlit v0.6.0 迁移指南