承接 lonnieezell/scribe 相关项目开发

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

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

lonnieezell/scribe

Composer 安装命令:

composer require lonnieezell/scribe

包简介

A simple AI prompting library for CodeIgniter 4

README 文档

README

A CodeIgniter 4 package that gives you a clean, driver-based abstraction for talking to AI language models. Point it at Claude, OpenAI, or Gemini — your application code stays the same regardless of which provider you use.

PHPStan PHP Version License: MIT

📖 Full Documentation →

What it does

You define a Prompt class that describes what you want the AI to do. Scribe takes care of building the system prompt, calling the right provider, and returning a normalized AIResponse you can work with in plain PHP.

<?php

// Define once
class SummarizePrompt extends BasePrompt
{
    public function __construct(private string $text) {}

    public function systemPrompt(): string
    {
        return 'You are a concise summarizer. Return a 2-sentence summary.';
    }

    public function userPrompt(): string
    {
        return 'Summarize: ' . $this->text;
    }
}

// Use anywhere in your CI4 app
$response = service('scribe')->run(new SummarizePrompt($articleText));
echo $response->content;

Key Features

  • Driver-based — swap providers (Claude, OpenAI, Gemini) without touching your prompt classes
  • Structured output — pass a JSON schema and get typed data back via toArray()
  • Test-friendlyFakeDriver lets you unit-test prompts without any HTTP calls
  • CI4-native — auto-discovered via Composer, wired into CI4's service layer; no manual wiring needed

What it isn't

  • No streaming — responses are returned as a complete string, not streamed token-by-token
  • No conversation management — each run() call is stateless; multi-turn chat history is your responsibility
  • No agent loop — there is no built-in tool-calling or autonomous reasoning loop
  • Not a full AI framework — no embeddings, RAG, vector search, or fine-tuning helpers
  • Not a managed client — it does not retry, throttle, or rotate API keys on your behalf

If you need those features, this library is intentionally out of scope for them.

Requirements

  • PHP 8.2+
  • CodeIgniter 4.7+

Installation

Install via Composer:

composer require lonnieezell/scribe

Publish the config file so you can add your API keys:

php spark publish:config AI

Then open app/Config/AI.php and set at least one driver's apiKey:

public array $drivers = [
    'claude' => [
        'apiKey' => env('CLAUDE_API_KEY', ''),
        'model'  => 'claude-haiku-4-5',
    ],
    // ...
];

Quick Start

1. Create a Prompt class

<?php

namespace App\Prompts;

use Myth\Scribe\Prompts\BasePrompt;

class ClassifyEmailPrompt extends BasePrompt
{
    public function __construct(private string $emailBody) {}

    public function systemPrompt(): string
    {
        return 'Classify the email as spam or not_spam.';
    }

    public function userPrompt(): string
    {
        return $this->emailBody;
    }

    public function schema(): ?array
    {
        return [
            'type'       => 'object',
            'properties' => ['label' => ['type' => 'string', 'enum' => ['spam', 'not_spam']]],
            'required'   => ['label'],
        ];
    }
}

2. Run it

$response = service('scribe')->run(new ClassifyEmailPrompt($body));
$result   = $response->toArray(); // ['label' => 'spam']

3. Test it

use Myth\Scribe\Drivers\FakeDriver;

$fake = new FakeDriver(['content' => '{"label":"spam"}']);
// inject $fake into your service or swap the driver in config

Configuration

The AI config class lives at app/Config/AI.php after publishing. The key settings:

Key Description
$defaultDriver Driver used when none is specified on the prompt (default: 'claude')
$drivers['claude'] Anthropic Claude settings: apiKey, model, timeout
$drivers['openai'] OpenAI settings: apiKey, model, timeout
$drivers['gemini'] Google Gemini settings: apiKey, model, timeout

A specific prompt can override the driver at runtime:

$prompt = new SummarizePrompt($text);
$prompt->driver = 'openai';

Documentation

Full documentation — installation, core concepts, configuration, structured output, testing, and the changelog — is available at:

https://lonnieezell.github.io/scribe

Contributing

  1. Fork the repo and create a feature branch.
  2. Run the full CI suite before opening a PR: composer ci
  3. All new code must include tests and pass PHPStan level 5.

License

MIT — see LICENSE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固