Skip to main content

SearxNG搜索API (SearxNG Search API)

本文档介绍如何使用自托管的SearxNG搜索API来搜索网络。

您可以查看此链接以获取有关Searx API参数的更多信息。

import pprint
from langchain.utilities import SearxSearchWrapper
search = SearxSearchWrapper(searx_host="http://127.0.0.1:8888")

对于某些搜索引擎,如果直接提供了answer,则包装器将打印答案而不是完整的搜索结果列表。如果您想获取所有结果,可以使用包装器的results方法。

search.run("法国的首都是什么")
    '巴黎是法国的首都,是欧洲最大的国家,面积为550,000平方公里(6500万居民)。巴黎在2011年底有2,234万居民。她是法兰西岛地区(1200万人口)的核心。'

自定义参数 (Custom Parameters)

SearxNG支持135个搜索引擎。您还可以使用任意命名的参数自定义Searx包装器,这些参数将传递给Searx搜索API。在下面的示例中,我们将更有趣地使用自定义搜索参数来查询Searx搜索API。

在此示例中,我们将使用engines参数来查询维基百科。

search = SearxSearchWrapper(
searx_host="http://127.0.0.1:8888", k=5
) # k用于指定最大项目数
search.run("大型语言模型", engines=["wiki"])
    '大型语言模型(LLMs)代表了人工智能的重大进展,通过学习的知识来改变领域。LLM的大小在过去几年中每年增长10倍,随着这些模型的复杂性和规模增加,它们的能力也在增强。\n\nGPT-3可以翻译语言、写作文、生成计算机代码等等,而且几乎不需要监督。2020年7月,OpenAI发布了GPT-3,这是当时已知的最大语言模型。简单来说,GPT-3被训练成预测句子中的下一个单词,就像文本消息自动完成功能一样。\n\n大型语言模型(LLM)是一种深度学习算法,它可以根据从大规模数据集中获得的知识识别、总结、翻译、预测和生成文本和其他内容。大型语言模型是转换器模型最成功的应用之一。\n\n当今众所周知的语言模型,如OpenAI的GPT-3、Google的PaLM或LaMDA、Meta的Galactica或OPT、Nvidia/Microsoft的Megatron-Turing、AI21 Labs的Jurassic-1等等...\n\n大型语言模型(LLMs)如GPT-3越来越多地被用于生成文本。使用这些工具时应谨慎,因为它们可能会生成具有偏见、不可验证、构成原创研究或侵犯版权的内容。'

传递其他Searx参数给searx,例如language

search = SearxSearchWrapper(searx_host="http://127.0.0.1:8888", k=1)
search.run("深度学习", language="es", engines=["wiki"])
    'Aprendizaje profundo (en inglés, deep learning) es un conjunto de algoritmos de aprendizaje automático (en inglés, machine learning) que intenta modelar abstracciones de alto nivel en datos usando arquitecturas computacionales que admiten transformaciones no lineales múltiples e iterativas de datos expresados en forma matricial o tensorial. 1'

使用元数据获取结果

在这个例子中,我们将使用categories参数来查找科学论文,并将结果限制在一个time_range范围内(并非所有引擎都支持时间范围选项)。

我们还希望以结构化的方式获取包含元数据的结果。为此,我们将使用包装器的results方法。

search = SearxSearchWrapper(searx_host="http://127.0.0.1:8888")
results = search.results(
"大型语言模型提示",
num_results=5,
categories="科学",
time_range="年",
)
pprint.pp(results)
    [{'snippet': '… on natural language instructions, large language models (… the '
'prompt used to steer the model, and most effective prompts … to '
'prompt engineering, we propose Automatic Prompt …',
'title': '大型语言模型是人类级别的提示工程师',
'link': 'https://arxiv.org/abs/2211.01910',
'engines': ['google scholar'],
'category': '科学'},
{'snippet': '… Large language models (LLMs) have introduced new possibilities '
'for prototyping with AI [18]. Pre-trained on a large amount of '
'text data, models … language instructions called prompts. …',
'title': 'Promptchainer: 通过可视化编程链接大型语言模型提示',
'link': 'https://dl.acm.org/doi/abs/10.1145/3491101.3519729',
'engines': ['google scholar'],
'category': '科学'},
{'snippet': '… can introspect the large prompt model. We derive the view '
'ϕ0(X) and the model h0 from T01. However, instead of fully '
'fine-tuning T0 during co-training, we focus on soft prompt '
'tuning, …',
'title': '共训练改进了基于提示的大型语言模型的学习',
'link': 'https://proceedings.mlr.press/v162/lang22a.html',
'engines': ['google scholar'],
'category': '科学'},
{'snippet': '… With the success of large language models (LLMs) of code and '
'their use as … prompt design process become important. In this '
'work, we propose a framework called Repo-Level Prompt …',
'title': '用于代码的大型语言模型的存储库级提示生成',
'link': 'https://arxiv.org/abs/2206.12839',
'engines': ['google scholar'],
'category': '科学'},
{'snippet': '… Figure 2 | The benefits of different components of a prompt '
'for the largest language model (Gopher), as estimated from '
'hierarchical logistic regression. Each point estimates the '
'unique …',
'title': '语言模型能否从上下文中学习解释?',
'link': 'https://arxiv.org/abs/2204.02329',
'engines': ['google scholar'],
'category': '科学'}]

从arxiv获取论文

results = search.results(
"大型语言模型提示", num_results=5, engines=["arxiv"]
)
pprint.pp(results)
    [{'snippet': '由于大型预训练语言模型的先进改进,基于提示的微调在各种下游任务中被证明是有效的。尽管已经研究了许多提示方法,但仍然不清楚三种提示类型(即人工设计的提示、模式提示和空提示)中哪种类型的提示在少样本和完全监督设置下最有效。在这项工作中,我们在少样本和完全监督设置下对这三种提示类型进行了实证比较。我们的实验结果表明,模式提示通常是最有效的。此外,当训练数据规模增大时,性能差距往往会减小。',
'title': '自然语言处理任务是否可以通过自然语言解决?',
'link': 'http://arxiv.org/abs/2203.00902v1',
'engines': ['arxiv'],
'category': '科学'},
{'snippet': '交叉提示自动化作文评分(AES)要求系统使用非目标提示的作文为目标提示的作文评分。由于往往难以获得大量预分级的特定提示的作文,交叉提示AES的任务对于实际AES系统的开发至关重要,但它仍然是一个未充分研究的领域。专为特定提示AES设计的模型严重依赖于特定提示的知识,并在交叉提示设置中表现不佳,而当前的交叉提示AES方法要么需要一定数量的标记目标提示作文,要么需要大量未标记的目标提示作文以进行多步骤的迁移学习。为了解决这些问题,我们引入了Prompt Agnostic Essay Scorer(PAES)用于交叉提示AES。我们的方法在训练过程中不需要访问标记或未标记的目标提示数据,并且是一种单阶段方法。PAES在实践中易于应用,并在Automated Student Assessment Prize(ASAP)数据集上实现了最先进的性能。',
'title': 'Prompt Agnostic Essay Scorer:一种面向交叉提示的领域泛化方法',
'link': 'http://arxiv.org/abs/2008.01441v1',
'engines': ['arxiv'],
'category': '科学'},
{'snippet': '提示研究表明,在许多任务中,即使没有或几乎没有监督训练,也可以获得出色的性能。然而,在机器翻译中,提示仍然是一个未被充分研究的领域。我们通过对翻译的提示策略进行系统研究来填补这个空白,研究了提示模板和演示示例选择的各种因素。我们进一步探索了使用单语数据的使用以及跨语言、跨领域和句子到文档的迁移学习在提示中的可行性。在以GLM-130B(Zeng等人,2022)为测试平台的大量实验证明,1)提示示例的数量和质量很重要,使用次优示例会导致翻译退化;2)提示示例的几个特征,如语义相似性,与其提示性能显示出显著的Spearman相关性;然而,没有一个相关性足够强;3)使用通过零-shot提示从单语数据构建的伪并行提示示例可以改善翻译;4)通过从其他设置中选择的提示示例转移知识可以实现改进的性能。最后,我们对模型输出进行了分析,并讨论了提示仍然存在的几个问题。',
'title': '用于机器翻译的大型语言模型提示:以案例研究为例',
'link': 'http://arxiv.org/abs/2301.07069v2',
'engines': ['arxiv'],
'category': '科学'},
{'snippet': '大型语言模型可以以零-shot方式执行新任务,只需使用指定所需行为的自然语言提示。这些提示通常是手工设计的,但也可以通过基于梯度的方法从标记数据中学习。然而,什么因素使提示有效,特别是当提示是自然语言时,这个问题尚未得到充分探讨。在本文中,我们研究了有效提示所共有的常见属性。我们首先提出了一种基于Langevin动力学的人类可读提示调整方法(F LUENT P ROMPT),该方法结合了流畅性约束,以找到有效和流畅的提示的多样分布。我们的分析揭示了有效提示与任务领域的主题相关,并校准了标签词的先验概率。基于这些发现,我们还提出了一种仅使用未标记数据生成提示的方法,其在三个任务上的平均准确率比强基线高出7.0%。',
'title': '走向人类可读的提示调整:《闪灵》是一部好电影,也是一个好提示吗?',
'link': 'http://arxiv.org/abs/2212.10539v1',
'engines': ['arxiv'],
'category': '科学'},
{'snippet': '以GPT-3为案例研究,我们展示了0-shot提示可以显著优于few-shot提示。我们认为在这些情况下,few-shot示例的功能更好地描述为定位已经学习的任务,而不是元学习。这种分析促使我们重新思考提示在控制和评估强大的语言模型中的作用。在这项工作中,我们讨论了提示编程的方法,强调通过自然语言的视角考虑提示的有用性。我们探索了利用叙述和文化锚点的能力来编码微妙意图的技术,以及在产生结论之前将问题分解为组成部分的技术。在这种更全面的提示编程理论的指导下,我们还介绍了一种元提示的概念,该元提示用于生成自己的自然语言提示,用于各种任务。最后,我们讨论了如何将这些更一般的与语言模型交互的方法纳入现有和未来的基准测试和实际应用中。',
'title': '大型语言模型的提示编程:超越few-shot范式',
'link': 'http://arxiv.org/abs/2102.07350v1',
'engines': ['arxiv'],
'category': '科学'}]

在这个例子中,我们查询it类别下的大型语言模型。然后我们过滤来自github的结果。

results = search.results("大型语言模型", num_results=20, categories="it")
pprint.pp(list(filter(lambda r: r["engines"][0] == "github", results)))
    [{'snippet': '使用预训练的大型源代码语言模型的指南',
'title': 'Code-LMs',
'link': 'https://github.com/VHellendoorn/Code-LMs',
'engines': ['github'],
'category': 'it'},
{'snippet': 'Dramatron使用大型语言模型生成连贯的脚本和剧本。',
'title': 'dramatron',
'link': 'https://github.com/deepmind/dramatron',
'engines': ['github'],
'category': 'it'}]

我们也可以直接查询来自github和其他源代码库的结果。

results = search.results(
"大型语言模型", num_results=20, engines=["github", "gitlab"]
)
pprint.pp(results)
    [{'snippet': "《大型语言模型的水印》论文的实现,作者是Kirchenbauer和Geiping等人。",
'title': 'Peutlefaire / LMWatermark',
'link': 'https://gitlab.com/BrianPulfer/LMWatermark',
'engines': ['gitlab'],
'category': 'it'},
{'snippet': '使用预训练的大型源代码语言模型的指南',
'title': 'Code-LMs',
'link': 'https://github.com/VHellendoorn/Code-LMs',
'engines': ['github'],
'category': 'it'},
{'snippet': '',
'title': 'Simen Burud / Large-scale Language Models for Conversational '
'Speech Recognition',
'link': 'https://gitlab.com/BrianPulfer',
'engines': ['gitlab'],
'category': 'it'},
{'snippet': 'Dramatron使用大型语言模型生成连贯的脚本和剧本。',
'title': 'dramatron',
'link': 'https://github.com/deepmind/dramatron',
'engines': ['github'],
'category': 'it'},
{'snippet': '《LoRA:大型语言模型的低秩适应》论文的代码',
'title': 'LoRA',
'link': 'https://github.com/microsoft/LoRA',
'engines': ['github'],
'category': 'it'},
{'snippet': '《评估代码训练的大型语言模型》论文的代码',
'title': 'human-eval',
'link': 'https://github.com/openai/human-eval',
'engines': ['github'],
'category': 'it'},
{'snippet': '趋势始于《Chain of Thought Prompting Elicits Reasoning in Large '
'Language Models》。',
'title': 'Chain-of-ThoughtsPapers',
'link': 'https://github.com/Timothyxxx/Chain-of-ThoughtsPapers',
'engines': ['github'],
'category': 'it'},
{'snippet': 'Mistral:一种强大的偏北风:用Hugging Face 🤗 Transformers构建的透明和可访问的大规模语言模型训练框架。',
'title': 'mistral',
'link': 'https://github.com/stanford-crfm/mistral',
'engines': ['github'],
'category': 'it'},
{'snippet': '寻找导致大型语言模型显示反比例缩放的任务的奖励',
'title': 'prize',
'link': 'https://github.com/inverse-scaling/prize',
'engines': ['github'],
'category': 'it'},
{'snippet': 'Optimus:第一个大规模预训练的VAE语言模型',
'title': 'Optimus',
'link': 'https://github.com/ChunyuanLI/Optimus',
'engines': ['github'],
'category': 'it'},
{'snippet': '大型语言模型研讨会(UNC Chapel Hill的COMP790-101,2022年秋季)',
'title': 'llm-seminar',
'link': 'https://github.com/craffel/llm-seminar',
'engines': ['github'],
'category': 'it'},
{'snippet': '用于链式思维推理的大型语言模型的数据和工具的中央开放资源。由Samwald研究小组开发:https://samwald.info/',
'title': 'ThoughtSource',
'link': 'https://github.com/OpenBioLink/ThoughtSource',
'engines': ['github'],
'category': 'it'},
{'snippet': '包括机器人学/强化学习中使用大型语言/多模态模型的论文、代码和相关网站的综合列表',
'title': 'Awesome-LLM-Robotics',
'link': 'https://github.com/GT-RIPL/Awesome-LLM-Robotics',
'engines': ['github'],
'category': 'it'},
{'snippet': '用于大规模语言建模的生物医学训练数据筛选工具',
'title': 'biomedical',
'link': 'https://github.com/bigscience-workshop/biomedical',
'engines': ['github'],
'category': 'it'},
{'snippet': 'ChatGPT @ Home:大型语言模型(LLM)聊天机器人应用程序,由ChatGPT编写',
'title': 'ChatGPT-at-Home',
'link': 'https://github.com/Sentdex/ChatGPT-at-Home',
'engines': ['github'],
'category': 'it'},
{'snippet': '设计和部署大型语言模型应用程序',
'title': 'dust',
'link': 'https://github.com/dust-tt/dust',
'engines': ['github'],
'category': 'it'},
{'snippet': 'Polyglot:多语言中平衡能力的大型语言模型',
'title': 'polyglot',
'link': 'https://github.com/EleutherAI/polyglot',
'engines': ['github'],
'category': 'it'},
{'snippet': '《从大型语言模型中学习视频表示》论文的代码发布',
'title': 'LaViLa',
'link': 'https://github.com/facebookresearch/LaViLa',
'engines': ['github'],
'category': 'it'},
{'snippet': 'SmoothQuant:用于大型语言模型的准确高效的训练后量化',
'title': 'smoothquant',
'link': 'https://github.com/mit-han-lab/smoothquant',
'engines': ['github'],
'category': 'it'},
{'snippet': '该存储库包含题为“XL-Sum:用于44种语言的大规模多语言抽象摘要”的论文的代码、数据和模型,发表在计算语言学协会的发现:ACL-IJCNLP 2021。',
'title': 'xl-sum',
'link': 'https://github.com/csebuetnlp/xl-sum',
'engines': ['github'],
'category': 'it'}]