shipfastlabs/toolkit-perplexity 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shipfastlabs/toolkit-perplexity

Composer 安装命令:

composer require shipfastlabs/toolkit-perplexity

包简介

Perplexity tools for the Laravel AI SDK - Search and Ask (Sonar)

README 文档

README

Latest Version Total Downloads

Perplexity tools for the Laravel AI SDK - Search and Ask (Sonar)

Part of the shipfastlabs/toolkit catalog of reusable AI tools for the Laravel AI SDK.

Installation

composer require shipfastlabs/toolkit-perplexity

Usage

Register every Perplexity tool at once with the Perplexity helper:

use Shipfastlabs\Toolkit\Perplexity\Perplexity;

$tools = Perplexity::all(); // Collection<int, Tool>

Or add individual tools to an agent's tools():

use Shipfastlabs\Toolkit\Perplexity\PerplexitySearch;
use Shipfastlabs\Toolkit\Perplexity\PerplexityAsk;

$tools = [
    new PerplexitySearch,
    new PerplexityAsk,
];

Tools

PerplexitySearch

Search the web for real-time information and get a ranked list of sources. Uses the Perplexity Search API.

Parameter Type Required Description
query string yes The search query to look up on the web.
max_results integer no Maximum number of results to return (1-20). Defaults to 10.
search_recency_filter string no Restrict results to a recent window: "hour", "day", "week", "month", or "year". No filter by default.

PerplexityAsk

Ask a question and get a direct, cited answer grounded in a live web search using Perplexity's Sonar models. The response includes the answer text plus the search_results and citations used.

Parameter Type Required Description
query string yes The question to ask Perplexity.
model string no Sonar model: "sonar", "sonar-pro", "sonar-reasoning", "sonar-reasoning-pro", or "sonar-deep-research". Defaults to "sonar".
search_mode string no "web" for the open web, "academic" for scholarly sources, or "sec" for SEC filings. Defaults to "web".

Provider setup

Both tools read their API key from Laravel's services config and their optional defaults from the ai config.

1. Add the Perplexity service to config/services.php

// config/services.php

return [

    // ... existing services ...

    'perplexity' => [
        'key' => env('PERPLEXITY_API_KEY'),
    ],

];

2. Add toolkit defaults to config/ai.php

// config/ai.php

return [

    // ... existing laravel/ai config ...

    'toolkit' => [
        'perplexity' => [
            'search' => [
                'max_results' => (int) env('PERPLEXITY_SEARCH_MAX_RESULTS', 10),
                'recency' => env('PERPLEXITY_SEARCH_RECENCY'),
            ],
            'ask' => [
                'model' => env('PERPLEXITY_ASK_MODEL', 'sonar'),
                'search_mode' => env('PERPLEXITY_ASK_SEARCH_MODE', 'web'),
            ],
        ],
    ],

];

3. Add environment variables to .env

PERPLEXITY_API_KEY=pplx-your-key-here

# Search defaults
PERPLEXITY_SEARCH_MAX_RESULTS=10
PERPLEXITY_SEARCH_RECENCY=

# Ask defaults
PERPLEXITY_ASK_MODEL=sonar
PERPLEXITY_ASK_SEARCH_MODE=web
Config key Env var Default Description
services.perplexity.key PERPLEXITY_API_KEY - Required. Your Perplexity API key.
ai.toolkit.perplexity.search.max_results PERPLEXITY_SEARCH_MAX_RESULTS 10 Default search results (1-20).
ai.toolkit.perplexity.search.recency PERPLEXITY_SEARCH_RECENCY - Default recency filter (hour/day/week/month/year).
ai.toolkit.perplexity.ask.model PERPLEXITY_ASK_MODEL "sonar" Default Sonar model.
ai.toolkit.perplexity.ask.search_mode PERPLEXITY_ASK_SEARCH_MODE "web" Default search mode (web/academic/sec).

Safety

  • Both tools validate required inputs before calling the API.
  • max_results is clamped to its valid 1-20 range.
  • model, search_mode, and search_recency_filter are validated against allow-lists, falling back to safe defaults.
  • API errors are caught and returned as friendly string messages.
  • Requires a valid Perplexity API key.

Perplexity API

These tools use the Perplexity API. You'll need an API key from your Perplexity account settings.

Full API reference:

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固