Metaphor(EXA) 基于大语言模型的搜索引擎


文章目录


关于 Metaphor

Metaphor是基于大语言模型的搜索引擎,允许用户使用完整的句子和自然语言搜索,还可以模拟人们在互联网上分享和谈论链接的方式进行查询内容。

Metaphor同时还能与LLMs结合使用,允许LLMs连接互联网,查询自己知识库外部的内容。


相关教程


使用示例

安装环境

shell 复制代码
!pip install exa_py
!pip install langchain 
!pip install llama_hub  
!pip install llama_index   

  • api_key 为从官网 https://exa.ai 注册后,个人的 key
  • 过去使用 MetaphorToolSpec,后面改为使用 ExaToolSpec
python 复制代码
from llama_hub.tools.exa.base import ExaToolSpec 
metaphor_tool = ExaToolSpec( api_key="xxx" )

metaphor_tool_list = metaphor_tool.to_tool_list() 

for tool in metaphor_tool_list:
    print(tool.metadata.name)


'''
search
retrieve_documents
search_and_retrieve_documents
search_and_retrieve_highlights
find_similar
current_date
'''

metaphor_tool.search('machine learning transformers', num_results=3)
'''
[Exa Tool] Autoprompt: Here's an insightful article on machine learning transformers:
[{'title': 'On the potential of Transformers in Reinforcement Learning',
  'url': 'https://lorenzopieri.com/rl_transformers/',
  'id': 'snjxQqPfYVWKEmVXunkqhg'},
 {'title': 'How Transformers work in deep learning and NLP: an intuitive introduction | AI Summer',
  'url': 'https://theaisummer.com/transformer/',
  'id': 'kzGcf36vWzWeyL28Az1fNQ'},
 {'title': 'Transformers in Computer Vision: Farewell Convolutions!',
  'url': 'https://towardsdatascience.com/transformers-in-computer-vision-farewell-convolutions-f083da6ef8ab?gi=a1d0a9a2896c',
  'id': 'xF0V2oTHAfVmfS5UvJIFDA'}]
'''

python 复制代码
# 使用 Mataphor 设置 OpenAI Agent

from llama_index.agent import OpenAIAgent
agent = OpenAIAgent.from_tools(
    metaphor_tool_list,
    verbose=True,
)

# 直接查询
agent.chat('what are the best restaurants in torando?')

python 复制代码
from llama_index.tools.tool_spec.load_and_search.base import LoadAndSearchToolSpec

# The search_and_retrieve_documents tool is the third in the tool list, as seen above
wrapped_retrieve = LoadAndSearchToolSpec.from_defaults(
  metaphor_tool_list[2],
)

# Just pass the wrapped tools and the get_date utility
agent = OpenAIAgent.from_tools(
  [*wrapped_retrieve.to_tool_list(), metaphor_tool_list[4]],
  verbose=True,
)
agent.chat('Can you summarize everything published in the last month regarding news on superconductors')

伊织 2024-01-27(六)

相关推荐
仙人掌_lz26 分钟前
Qwen-3 微调实战:用 Python 和 Unsloth 打造专属 AI 模型
人工智能·python·ai·lora·llm·微调·qwen3
美林数据Tempodata2 小时前
大模型驱动数据分析革新:美林数据智能问数解决方案破局传统 BI 痛点
数据库·人工智能·数据分析·大模型·智能问数
硅谷秋水2 小时前
NORA:一个用于具身任务的小型开源通才视觉-语言-动作模型
人工智能·深度学习·机器学习·计算机视觉·语言模型·机器人
正儿八经的数字经2 小时前
人工智能100问☞第46问:AI是如何“学习”的?
人工智能·学习
飞哥数智坊2 小时前
别卷提示词了!像带新人一样“带”AI,产出效率翻倍
人工智能
G皮T2 小时前
【Elasticsearch】正排索引、倒排索引(含实战案例)
大数据·elasticsearch·搜索引擎·kibana·倒排索引·搜索·正排索引
扫地的小何尚2 小时前
全新NVIDIA Llama Nemotron Nano视觉语言模型在OCR基准测试中准确率夺冠
c++·人工智能·语言模型·机器人·ocr·llama·gpu
m0_575470883 小时前
n8n实战:自动化生成AI日报并发布
人工智能·ai·自动化·ai自动写作
时空无限3 小时前
使用 ollama 在 mac 本地部署一个 qwen3:8b 模型
人工智能·语言模型