gridwb/laravel-perplexity
最新稳定版本:1.1.0
Composer 安装命令:
composer require gridwb/laravel-perplexity
包简介
perplexity.ai API for Laravel
README 文档
README
Laravel Perplexity is a convenient wrapper for interacting with the Perplexity API in Laravel applications.
Table of Contents
Installation
-
Install the package
composer require gridwb/laravel-perplexity
-
Publish the configuration file
php artisan vendor:publish --tag="perplexity-config" -
Add environment variables
PERPLEXITY_API_URL=https://api.perplexity.ai PERPLEXITY_API_KEY=your-api-key-here
Usage
Search Resource
search
Search request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $response = Perplexity::search()->search([ 'query' => 'latest AI developments 2024', ]); foreach ($response->results as $result) { echo $result->title; echo $result->url; echo $result->snippet; echo $result->date; echo $result->lastUpdated; }
Chat Resource
completions
Completions request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $response = Perplexity::chat()->completions([ 'model' => 'sonar', 'messages' => [ [ 'role' => 'user', 'content' => 'How many stars are there in our galaxy?', ], ], ]); foreach ($response->choices as $choice) { echo $choice->message->content; // full content // ... }
completions streamed
Streamed completions request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; use Gridwb\LaravelPerplexity\Responses\Chat\CompletionResponse; $stream = Perplexity::chat()->completionsStreamed([ 'model' => 'sonar', 'messages' => [ [ 'role' => 'user', 'content' => 'How many stars are there in our galaxy?', ], ], ]); /** @var CompletionResponse $response */ foreach ($stream as $response) { foreach ($response->choices as $choice) { echo $choice->delta->content; // delta content // ... } }
create async completion
Create an asynchronous completion request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $response = Perplexity::chat()->createAsyncCompletion([ 'request' => [ 'model' => 'sonar-deep-research', 'messages' => [ [ 'role' => 'user', 'content' => 'How many stars are there in our galaxy?', ], ], ], ]); echo $response->id; echo $response->model; echo $response->status->value; // ...
list async completions
List asynchronous completions request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $limit = 10; $nextToken = '<string>'; $response = Perplexity::chat()->listAsyncCompletions($limit, $nextToken); foreach ($response->requests as $request) { echo $request->id; echo $request->model; echo $request->status->value; // ... }
get async completion
Get a specific asynchronous completion request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $requestId = '<string>'; $response = Perplexity::chat()->getAsyncCompletion($requestId); echo $response->id; echo $response->model; echo $response->status->value; // ...
generate auth token
Generate auth token request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $tokenName = '<string>'; $response = Perplexity::chat()->generateAuthToken($tokenName); echo $response->authToken; echo $response->createdAtEpochSeconds; echo $response->tokenName;
revoke auth token
Revoke auth token request:
<?php use Gridwb\LaravelPerplexity\Facades\Perplexity; $authToken = '<string>'; Perplexity::chat()->revokeAuthToken($authToken);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 297
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-05