langchain LLMRequestsChain

42 篇文章 0 订阅
24 篇文章 0 订阅

原文:LLMRequestsChain – LangChain中文网

LLMRequestsChain

使用请求库从URL获取HTML结果,然后使用LLM解析结果

from langchain.llms import OpenAIfrom langchain.chains import LLMRequestsChain, LLMChain

定义使用的提示:

from langchain.prompts import PromptTemplate template = """Between >>> and <<< are the raw search result text from google.Extract the answer to the question '{query}' or say "not found" if the information is not contained.Use the formatExtracted:<answer or "not found">>>> {requests_result} <<<Extracted:""" PROMPT = PromptTemplate(    input_variables=["query", "requests_result"],    template=template,)

实例化LLMRequestsChain:

chain = LLMRequestsChain(llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=PROMPT))

定义输入:

question = "What are the Three (3) biggest countries, and their respective sizes?"inputs = {    "query": question,    "url": "https://www.google.com/search?q=" + question.replace(" ", "+")}

运行LLMRequestsChain:

chain(inputs)

输出如下:

{'query': 'What are the Three (3) biggest countries, and their respective sizes?', 'url': 'https://www.google.com/search?q=What+are+the+Three+(3)+biggest+countries,+and+their+respective+sizes?', 'output': '俄罗斯(17,098,242平方公里),加拿大(9,984,670平方公里),美国(9,826,675平方公里)'}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值