gpt4 book ai didi

python - 如何使用 Langchain 获得更详细的结果来源

转载 作者:行者123 更新时间:2023-12-02 05:48:21 24 4
gpt4 key购买 nike

我正在尝试使用 Langchain 和特定 URL 作为源数据来整理一个简单的“带有来源的问答”。该 URL 由一个页面组成,其中包含大量信息。

问题是 RetrievalQAWithSourcesChain 只给我返回整个 URL 作为结果的来源,这在这种情况下不是很有用。

有没有办法获得更详细的源信息?也许页面上特定部分的标题?指向页面正确部分的可点击 URL 会更有帮助!

我有点不确定结果源的生​​成是语言模型、URL加载器的函数还是仅仅是RetrievalQAWithSourcesChain的函数。

我尝试过使用 UnstructedURLLoaderSeleniumURLLoader,希望更详细的数据读取和输入会有所帮助 - 遗憾的是没有。

相关代码摘录:

llm = ChatOpenAI(temperature=0, model_name='gpt-3.5-turbo')
chain = RetrievalQAWithSourcesChain.from_llm(llm=llm, retriever=VectorStore.as_retriever())

result = chain({"question": question})

print(result['answer'])
print("\n Sources : ",result['sources'] )

最佳答案

ChatGPT 非常灵活,越明确,您可以获得的结果越好。 This link show the docs for the function you are using 。 langchain.prompts.BasePromptTemplate 有一个参数,可让您向 ChatGPT 提供更明确的指令。

看起来基本提示模板是这样的

Use the following knowledge triplets to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.\n\n{context}\n\nQuestion: {question}\nHelpful Answer:

您可以添加另一句话,为 ChatGPT 提供更清晰的说明

Please format the answer with JSON of the form { "answer": "{your_answer}", "relevant_quotes": ["list of quotes"] }. Substitutde your_answer as the answer to the question, but also include relevant quotes from the source material in the list.

您可能需要稍微调整一下才能使 ChatGPT 良好响应。然后你应该能够解析它。

ChatGPT API 中有 3 种消息类型

  • 用户 - 最终用户发送给模型的消息
  • 模型 - 从模型到最终用户的消息
  • 系统 - 提示工程师向模型添加指令的消息。 Lang 链不使用此功能,因为它是一次性提示

我强烈推荐这些courses在 ChatGPT 上,因为它们来自 Andrew Ng 并且质量非常高。

关于python - 如何使用 Langchain 获得更详细的结果来源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76482024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com