Leanpub Header

Skip to main content

PHPでAIアプリケーションを構築する

PapiAI、Laravel、Symfonyを使った実践ガイド

本物の AI エージェントを PHP で構築。Python は不要です。2 つの完全なプロジェクト、10 の LLM プロバイダー、本番運用に必要な論点をすべて網羅。

This book is a translation into Japanese of Building AI Applications with PHP which was originally written in English

Minimum price

$9.00

$15.00

You pay

$15.00

Author earns

$12.00
$

...Or Buy With Credits!

You can get credits with a paid monthly or annual Reader Membership, or you can buy them here.
PDF
EPUB
WEB
About

About

About the Book

PHP 開発者は日々、Laravel や Symfony を使って意欲的なアプリケーションを構築しています。ところが、AI が関わった瞬間に「Python を使うべきだ」と言われがちです。本書は、それが必ずしも必要ではないことを示します。

PHPでAIアプリケーションを構築する では、2 つの完全な本番対応 AI アプリケーションをゼロから構築する方法を、順を追って解説します。ひとつは Laravel によるインテリジェントなカスタマーサポートエージェント、もうひとつは Symfony による AI コンテンツ生成パイプラインです。どちらも、実行時依存ゼロで 10 の LLM プロバイダーをサポートし、本格的なエージェント実行基盤を備えたオープンソースの PHP ライブラリ、PapiAI を使用しています。

本書では、本番環境で本当に重要となる AI アプリケーション開発の要点を学べます。リアルタイムのストリーミング応答、データベースを問い合わせるツールをエージェントに持たせる方法、リクエストをまたいだ会話メモリの管理、スキーマによる構造化出力の検証、埋め込みとベクトル検索を用いた RAG パイプラインの構築、キューによる非同期処理、プロンプトインジェクションへの対策、コスト管理、そして安心してデプロイする方法までを扱います。

これは API エンドポイントの紹介本ではありません。デモと実運用可能なプロダクトを分ける、アーキテクチャ、パターン、そして実践から得られた知見をまとめたガイドです。しかも、すべてあなたがすでに知っている言語で書かれています。

This book is a translation into Japanese of Building AI Applications with PHP which was originally written in English

Author

About the Author

Marcello Duarte

Marcello Duarte was awarded Best UK Agile Coach in 2014. He has helped teams across Europe adopt Agile ways of working and improve engineering practices such as Scrum, TDD, refactoring, collaborative product ownership, and software quality. He is also the co-creator of PhpSpec, a well-known tool for TDD/SpecBDD in PHP, and brings many years of experience as a software engineering leader, consultant, trainer, and open-source author.

Translations

Translations

Contents

Table of Contents

PHPでAIアプリケーションを構築する

  1. PapiAI、Laravel、Symfonyを使った実践ガイド

第1部:基礎

第1章:AIネイティブなPHPアプリケーション

  1. 構築するもの
  2. 対象読者
  3. 必要なもの
  4. AIアプリケーションの解剖学
  5. PapiAIのインストール

第2章:初めてのエージェント

  1. プロバイダー
  2. エージェント
  3. レスポンス
  4. ストリーミング
  5. プロバイダーの切り替え
  6. フェイルオーバー

第3章:ツール — AIに手を与える

  1. ツール呼び出しの仕組み
  2. クロージャを使ったツールの作成
  3. PHPアトリビュートを使ったツールの作成
  4. ツールの設計原則
  5. エージェント型ループとmaxTurns

第4章:会話とメモリ

  1. Conversationオブジェクト
  2. メッセージ
  3. なぜコンテキスト管理が重要なのか
  4. コンテキストウィンドウの戦略
  5. 会話の永続化

第5章:構造化出力

  1. スキーマシステム
  2. スキーマの型
  3. 制約と修飾子
  4. バリデーション

第6章:検索拡張生成(RAG)

  1. RAGの仕組み
  2. PapiAIでのエンベディング
  3. ベクトルストア
  4. RAGパイプラインの構築
  5. ツールとしてのRAG
  6. RAGの品質のチューニング
  7. 本番環境での考慮事項

第7章:ミドルウェア

  1. MiddlewareInterface
  2. 組み込みミドルウェア
  3. ミドルウェアのスタッキング
  4. カスタムミドルウェア

第2部:Laravelプロジェクトの構築

第8章:プロジェクトのセットアップ — サポートエージェント

  1. スキャフォールディング
  2. 設定
  3. データベースのセットアップ
  4. システムプロンプト

第9章:ツールの構築

  1. OrderLookup
  2. KnowledgeBase
  3. InventoryCheck
  4. サービスプロバイダーへのツールの登録
  5. ドメインモデル

第10章:チャットコントローラーとストリーミング

  1. コントローラー
  2. ルート
  3. フロントエンド
  4. フローのテスト

第11章:セキュリティ

  1. プロンプトインジェクション
  2. ツールのセキュリティ
  3. APIキーの管理
  4. レート制限
  5. コスト管理

第3部:Symfonyプロジェクトの構築

第12章:プロジェクトのセットアップ — コンテンツパイプライン

  1. スキャフォールディング
  2. バンドルの設定
  3. データベーススキーマ
  4. 記事のスキーマ

第13章:コンテンツ生成パイプライン

  1. パイプライン・オーケストレーター
  2. Messengerを使った非同期処理
  3. コントローラー
  4. Twigテンプレート
  5. ワーカーの実行

第14章:パフォーマンス

  1. ストリーミング
  2. キャッシング
  3. モデルの選択
  4. 非同期処理
  5. トークンの最適化
  6. 接続の再利用

第15章:アーキテクチャのパターン

  1. サービスとしてのエージェント
  2. 関心事の分離
  3. プロンプトの管理
  4. ルーターパターン
  5. オブザーバビリティ(可観測性)

第16章:AIアプリケーションのテスト

  1. ツールのテスト
  2. モックプロバイダーを使ったテスト
  3. スキーマのテスト
  4. 統合テスト

第17章:デプロイと本番環境の懸念事項

  1. 環境設定
  2. ヘルスチェック
  3. モニタリング
  4. タイムアウト
  5. スケーリング

付録 A:プロバイダーリファレンス

  1. プロバイダーの機能マトリックス
  2. プロバイダーのコンストラクタパラメータ

付録 B:スキーマリファレンス

  1. 制約
  2. 検証メソッド

付録 C:ミドルウェアリファレンス

  1. RetryMiddleware
  2. RateLimitMiddleware
  3. CacheMiddleware
  4. LoggingMiddleware
  5. カスタムミドルウェア

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub