我正在尝试修改现有的 Colab 示例以结合 langchain 内存和上下文文档加载。在两个单独的测试中,每个实例都完美运行。现在我想将两者(训练上下文加载和对话记忆)合二为一 - 这样我就可以加载之前训练的数据,并在我的聊天机器人中保存对话历史记录。问题是我不知道如何使用“ConversationChain”来实现这一点,它只需要一个参数,即“输入”。
当我使用“ConversationChain”时,我可以传递以下内容:
query = "What is the title of the document?"
docs = docsearch.similarity_search(query)
chain.run(input_documents=docs, question=query)
有人能指出我正确的方向吗?
我正在使用这里的内存示例:https ://www.pinecone.io/learn/langchain-conversational-memory/
我对 Python 和 langchain 的了解有限。
我试过:
with open('/content/gdrive/My Drive/ai-data/docsearch.pkl', 'rb') as f:
docsearch = pickle.load(f)
model_kwargs = {"model": "text-davinci-003", "temperature": 0.7, "max_tokens": -1, "top_p": 1, "frequency_penalty": 0, "presence_penalty": 0.5, "n": 1, "best_of": 1}
llm = OpenAI(model_kwargs=model_kwargs)
def count_tokens(chain, query):
with get_openai_callback() as cb:
docs = docsearch.similarity_search(query)
# working older version: result = chain.run(query)
result …Run Code Online (Sandbox Code Playgroud)