PHP code example of joshfinlayau / laravel-anthropic-web
1. Go to this page and download the library: Download joshfinlayau/laravel-anthropic-web library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joshfinlayau / laravel-anthropic-web example snippets
use JoshFinlayAU\LaravelAnthropicWeb\Facades\AnthropicWeb;
$response = AnthropicWeb::complete('What are the latest developments in AI?');
echo $response;
$result = AnthropicWeb::completeWithWebSearch(
'What are the current interest rates in Australia?',
searchOptions: ['max_uses' => 3]
);
$analysis = AnthropicWeb::completeWithWebFetch(
'Analyze the content at https://example.com/article',
fetchOptions: [
'citations' => ['enabled' => true],
'allowed_domains' => ['example.com']
]
);
$research = AnthropicWeb::completeWithWebTools(
'Research the latest trends in renewable energy and analyze the top 3 articles you find',
searchOptions: ['max_uses' => 5],
fetchOptions: ['citations' => ['enabled' => true]]
);
// Simple JSON response
$data = AnthropicWeb::completeJson('Return information about Paris as JSON');
// JSON with schema validation
$schema = [
'type' => 'object',
'properties' => [
'name' => ['type' => 'string'],
'population' => ['type' => 'integer'],
'country' => ['type' => 'string']
]
];
$cityData = AnthropicWeb::completeJson(
'Return information about Tokyo',
$schema
);
// JSON response with web search
$currentData = AnthropicWeb::completeJsonWithWebSearch(
'Find current stock price for Apple and return as JSON',
['type' => 'object', 'properties' => ['symbol' => ['type' => 'string'], 'price' => ['type' => 'number']]]
);