SuperAPI AI 工具集

langchain-perplexity

智能体与模型

查看项目

更新于 10-15 21:38

技能介绍

用途:为 LangChain 提供 Perplexity AI 集成,核心是 ChatPerplexity——在模型层内置实时联网搜索的聊天模型,另含 RAG 检索、工具调用与嵌入组件。

主要能力:ChatPerplexity 支持 sonar、sonar-pro、sonar-reasoning、sonar-deep-research 模型;可用 search_domain_filter 限定来源域名,用 search_recency_filter(hour/day/week/month)或 search_after_date_filter、search_before_date_filter 按日期过滤;disable_search=True 可关闭联网当普通 LLM 用;推理模型可设 reasoning_effort(low/medium/high)。响应元数据含引用与搜索结果,可开启 return_images、return_related_questions。

其他组件:PerplexitySearchRetriever 将实时搜索结果作为文档返回,用于 RAG;PerplexitySearchResults 可作为工具放入智能体;PerplexityEmbeddings 生成查询与文档嵌入。输出解析提供 strip_think_tags()、ReasoningJsonOutputParser、ReasoningStructuredOutputParser.from_pydantic(),用于清理 thinking 标签或解析推理与答案。ChatPerplexity 支持 with_structured_output 结构化输出。

使用方式:pip install -U langchain-perplexity;export PPLX_API_KEY=your_api_key。基本用法为 from langchain_perplexity import ChatPerplexity,构造模型后调用 invoke 或 stream。

适用场景:需要实时联网事实的问答、按域名或时间限定的检索、带推理的复杂问题、RAG 与工具型智能体。

限制:需 Perplexity API 密钥;推理与深度研究模型速度较慢;具体收费、配额与平台支持资料未提供。