承接 kipchak/driver-anthropic 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

kipchak/driver-anthropic

最新稳定版本:1.8

Composer 安装命令:

composer require kipchak/driver-anthropic

包简介

An Anthropic driver for the Kipchak API Development Kit (ADK)

README 文档

README

A fully typed Anthropic driver for the Kipchak API Development Kit. Built on the official Anthropic PHP SDK, it provides multiple named connections, automatic default model injection, and clean access to the Messages API including streaming and tool use.

Requirements

  • PHP 8.4+
  • Kipchak ^2
  • kipchak/driver-config ^1
  • anthropic-ai/sdk ^0.6

Installation

composer require kipchak/driver-anthropic

Initialise

Add to your drivers/drivers.php:

\Kipchak\Driver\Anthropic\Anthropic::initialise($container);

Configuration

Create config/kipchak.anthropic.php:

<?php

use function Kipchak\Core\env;

return [
    'connections' => [
        'default' => [
            'api_key'       => env('ANTHROPIC_API_KEY', ''),
            'default_model' => env('ANTHROPIC_DEFAULT_MODEL', 'claude-sonnet-4-6'),
        ],
    ],
];
KeyRequiredDescription
api_keyYesAnthropic API key
default_modelNoModel injected automatically when none is specified on a call
max_retriesNoOverride the SDK default of 2 automatic retries

Usage

use Kipchak\Driver\Anthropic\Anthropic;

$anthropic = Anthropic::get();           // 'default' connection
$anthropic = Anthropic::get('secondary'); // named connection

Creating a Message

$response = $anthropic->messages()->create(
    messages: [
        ['role' => 'user', 'content' => 'What is the capital of France?'],
    ],
);

echo $response->content[0]->text; // 'The capital of France is Paris.'

The configured default_model is applied automatically. Pass model: explicitly to override:

$response = $anthropic->messages()->create(
    messages:  [['role' => 'user', 'content' => 'Hello']],
    model:     'claude-haiku-4-5-20251001',
    maxTokens: 512,
    system:    'You are a concise assistant. Reply in one sentence.',
);

Multi-Turn Conversations

$response = $anthropic->messages()->create(
    messages: [
        ['role' => 'user',      'content' => 'My name is Alice.'],
        ['role' => 'assistant', 'content' => 'Hello Alice, how can I help?'],
        ['role' => 'user',      'content' => 'What is my name?'],
    ],
);

Streaming

$stream = $anthropic->messages()->createStream(
    messages: [['role' => 'user', 'content' => 'Tell me a short story.']],
);

foreach ($stream as $event) {
    // handle streaming events
}

Tool Use

$tools = [
    [
        'name'         => 'get_weather',
        'description'  => 'Get the current weather for a location.',
        'input_schema' => [
            'type'       => 'object',
            'properties' => [
                'location' => ['type' => 'string', 'description' => 'City and country'],
            ],
            'required'   => ['location'],
        ],
    ],
];

$response = $anthropic->messages()->create(
    messages: [['role' => 'user', 'content' => 'What is the weather in Dubai?']],
    tools:    $tools,
);

foreach ($response->content as $block) {
    if ($block->type === 'tool_use') {
        $result = callTool($block->name, $block->input);

        // Send the tool result back
        $followup = $anthropic->messages()->create(
            messages: [
                ['role' => 'user', 'content' => 'What is the weather in Dubai?'],
                ['role' => 'assistant', 'content' => $response->content],
                ['role' => 'user', 'content' => [
                    ['type' => 'tool_result', 'tool_use_id' => $block->id, 'content' => $result],
                ]],
            ],
            tools: $tools,
        );
    }
}

Raw SDK Access

For anything not covered by the driver wrapper, use raw() to access the full Anthropic SDK client directly:

$client = $anthropic->raw();

Running Tests

composer install
./vendor/bin/phpunit

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固