如何使用 LangChain 的 LLMChain (python) 获取发送到 LLM 的准确消息?

cse*_*ell 5 python langchain py-langchain

目前,在 LangChain 中使用时LLMChain,我可以获取使用的模板提示和模型的响应,但是是否可以获取作为查询发送到模型的确切文本消息,而无需手动进行提示模板填充?

一个例子:

from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain

llm = OpenAI(model_name="gpt-3.5-turbo-0613")
prompt = PromptTemplate(input_variables=["a", "b"], template="Hello {a} and {b}")
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.call({"a": "some text", "b": "some other text"})
Run Code Online (Sandbox Code Playgroud)

chain我无法在或对象中找到我正在寻找的东西result。我尝试了一些选项,例如return_final_only=Trueinclude_run_info=True但它们不包含我正在寻找的内容。

小智 4

传递verbose=True给LLMChain构造函数

chain = LLMChain(prompt=..., llm=..., verbose=True)
Run Code Online (Sandbox Code Playgroud)

但问题是它只是通过标准输出打印。

我还在寻找如何获取准确使用的提示字符串