note07-LLMRequestChain

54 阅读1分钟

大模型当前数据只有截止到训练数据日期的数据。

为了得到最新的结果, 可以使用 LLMRequesetChain

可以向该 chain 传入请求 url,这里以 bing 返回的请求结果为例,这个结果会返回到参数 requests_result 中。

from langchain.chains import LLMChain, SequentialChain, ConversationChain, LLMRequestsChain
from langchain_community.chat_models import ChatOpenAI
from langchain_core.prompts import PromptTemplate
from langchain.memory import ConversationBufferMemory, ConversationSummaryMemory
import tools
tools.init()
llm = ChatOpenAI(model_name='gpt-3.5-turbo-1106')

# 用于获取最新消息, 比如获取 2025 的消息
prompt = PromptTemplate.from_template('''请根据如下搜索结果,回答用户问题。
搜索结果:
----------------
{requests_result}
问题:{question}
回答:
----------------
''')
# print(prompt.template)
llm_chain = LLMChain(llm=llm, prompt=prompt, verbose=True)
chain = LLMRequestsChain(llm_chain=llm_chain, verbose=True)
question = 'neuro是谁?'
inputs = {
    'question': question,
    # 'url': 'https://www.google.com/search?q=' + question.replace(' ', '+')
    'url': 'https://cn.bing.com/search?q=' + question.replace(' ', '+')
}
# print(inputs['url'])
result = chain.run(inputs)
print(result)

image.png

挂了梯子请求 API 会出现问题,所以不能挂梯子。

但是不挂梯子谷歌还用不了。