定制 joshfinlayau/laravel-anthropic-web 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

joshfinlayau/laravel-anthropic-web

Composer 安装命令:

composer require joshfinlayau/laravel-anthropic-web

包简介

Laravel client for Anthropic's Claude API with web search and fetch capabilities

README 文档

README

Tests Latest Stable Version License

A Laravel package for Anthropic's Claude API with web search and fetch capabilities.

Features

This package supports Claude's web tools that other packages don't:

  • Web search for current information
  • Web fetch to analyze content from URLs
  • Latest Claude models (Sonnet 4, Opus 4.1)
  • JSON response formatting with schema validation
  • Proper beta headers for new API features

Useful for applications requiring AI with real-time web data access.

Installation

composer require joshfinlayau/laravel-anthropic-web

Publish the config file:

php artisan vendor:publish --tag=anthropic-web-config

Add your API key to .env:

ANTHROPIC_API_KEY=your-api-key-here

Basic Usage

Simple Text Completion

use JoshFinlayAU\LaravelAnthropicWeb\Facades\AnthropicWeb;

$response = AnthropicWeb::complete('What are the latest developments in AI?');
echo $response;

Web Search

$result = AnthropicWeb::completeWithWebSearch(
    'What are the current interest rates in Australia?',
    searchOptions: ['max_uses' => 3]
);

Web Fetch

$analysis = AnthropicWeb::completeWithWebFetch(
    'Analyze the content at https://example.com/article',
    fetchOptions: [
        'citations' => ['enabled' => true],
        'allowed_domains' => ['example.com']
    ]
);

Combined Web Tools

$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]]
);

JSON Response Format

// 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']]]
);

Advanced Usage

Custom Tool Configuration

$searchTool = AnthropicWeb::webSearchTool([
    'max_uses' => 5,
    'allowed_domains' => ['reuters.com', 'bbc.com'],
    'user_location' => AnthropicWeb::userLocation('Sydney', 'NSW', 'AU', 'Australia/Sydney')
]);

$request = AnthropicWeb::buildMessageRequest(
    'claude-sonnet-4-20250514',
    [['role' => 'user', 'content' => 'Latest news about climate change']],
    4000,
    [$searchTool]
);

$response = AnthropicWeb::createMessage($request);

Streaming Responses

$stream = AnthropicWeb::createStreamedMessage([
    'model' => 'claude-sonnet-4-20250514',
    'max_tokens' => 4000,
    'messages' => [['role' => 'user', 'content' => 'Tell me about quantum computing']],
    'tools' => [AnthropicWeb::webSearchTool()]
]);

foreach ($stream as $chunk) {
    echo $chunk['content'][0]['text'] ?? '';
}

Configuration

The config file allows you to set defaults:

return [
    'api_key' => env('ANTHROPIC_API_KEY'),
    'models' => [
        'default' => 'claude-sonnet-4-20250514',
        'fast' => 'claude-3-5-haiku-latest',
        'powerful' => 'claude-opus-4-1-20250805',
    ],
    'web_tools' => [
        'search' => ['max_uses' => 5],
        'fetch' => ['max_uses' => 10, 'citations_enabled' => true],
    ],
];

Available Models

  • claude-opus-4-1-20250805 (Most capable)
  • claude-opus-4-20250514
  • claude-sonnet-4-20250514 (Recommended default)
  • claude-3-7-sonnet-20250219
  • claude-3-5-haiku-latest (Fastest)

Web Tools

Web Search Tool

Searches the internet for current information:

AnthropicWeb::webSearchTool([
    'max_uses' => 5,
    'allowed_domains' => ['example.com'],
    'blocked_domains' => ['spam.com'],
    'user_location' => [
        'city' => 'Brisbane',
        'region' => 'Queensland',
        'country' => 'AU',
        'timezone' => 'Australia/Brisbane'
    ]
])

Web Fetch Tool

Fetches and analyzes specific web pages:

AnthropicWeb::webFetchTool([
    'max_uses' => 10,
    'allowed_domains' => ['trusted-site.com'],
    'citations' => ['enabled' => true],
    'max_content_tokens' => 100000
])

Error Handling

try {
    $response = AnthropicWeb::complete('Your prompt here');
} catch (\Exception $e) {
    Log::error('Anthropic API failed: ' . $e->getMessage());
}

Requirements

  • PHP 8.1+
  • Laravel 9.0+

License

MIT

Contributing

Pull requests welcome. Please include tests for new features.

joshfinlayau/laravel-anthropic-web 适用场景与选型建议

joshfinlayau/laravel-anthropic-web 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「ai」 「web-search」 「claude」 「anthropic」 「web-fetch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 joshfinlayau/laravel-anthropic-web 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 joshfinlayau/laravel-anthropic-web 我们能提供哪些服务?
定制开发 / 二次开发

基于 joshfinlayau/laravel-anthropic-web 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-26