PHPackages                             apie/ai-instructor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. apie/ai-instructor

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

apie/ai-instructor
==================

Use a LLM to create an object in PHP similar to Instructor in Python

1.0.0.x-dev(3mo ago)010MITPHPPHP &gt;=8.3

Since May 3Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/apie-lib/ai-instructor)[ Packagist](https://packagist.org/packages/apie/ai-instructor)[ RSS](/packages/apie-ai-instructor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (8)Versions (3)Used By (0)

[![](https://raw.githubusercontent.com/apie-lib/apie-lib-monorepo/main/docs/apie-logo.svg)](https://raw.githubusercontent.com/apie-lib/apie-lib-monorepo/main/docs/apie-logo.svg)

ai-instructor
=============

[](#ai-instructor)

[![Latest Stable Version](https://camo.githubusercontent.com/b664c2f1254630e8a07299628c9687b023695ff856cb290794fe4e2ccf3dfa51/68747470733a2f2f706f7365722e707567782e6f72672f617069652f61692d696e7374727563746f722f76)](https://packagist.org/packages/apie/ai-instructor) [![Total Downloads](https://camo.githubusercontent.com/8d0d5df378f8f390f792e088cf9bbfe2db97ab97df8943dbfb941a0cb6c256a7/68747470733a2f2f706f7365722e707567782e6f72672f617069652f61692d696e7374727563746f722f646f776e6c6f616473)](https://packagist.org/packages/apie/ai-instructor) [![Latest Unstable Version](https://camo.githubusercontent.com/f3a44e9149eee6f86c02d5240f036c1b26e0d7936385758bc77277c8e1cde866/68747470733a2f2f706f7365722e707567782e6f72672f617069652f61692d696e7374727563746f722f762f756e737461626c65)](https://packagist.org/packages/apie/ai-instructor) [![License](https://camo.githubusercontent.com/5c0af47075bc306f655df55c1ce5d725838a469de852922fef8917da5b01ec46/68747470733a2f2f706f7365722e707567782e6f72672f617069652f61692d696e7374727563746f722f6c6963656e7365)](https://packagist.org/packages/apie/ai-instructor) [![PHP Composer](https://camo.githubusercontent.com/d3b459d509a9083a20f24e96243343aab0a82c84e0d054abdeb9b4653d5f61b7/68747470733a2f2f617069652d6c69622e6769746875622e696f2f70726f6a656374436f7665726167652f636f7665726167652d61692d696e7374727563746f722e737667)](https://apie-lib.github.io/projectCoverage/ai-instructor/index.html)

[![PHP Composer](https://github.com/apie-lib/ai-instructor/actions/workflows/php.yml/badge.svg?event=push)](https://github.com/apie-lib/ai-instructor/actions/workflows/php.yml)

This package is part of the [Apie](https://github.com/apie-lib) library. The code is maintained in a monorepo, so PR's need to be sent to the [monorepo](https://github.com/apie-lib/apie-lib-monorepo/pulls)

Documentation
-------------

[](#documentation)

Instructor is a library for Python that works with LLM's to force a specific structure. Wouldn't it be nice if we have the same functionality in PHP? That's what apie/ai-instructor does. Like you have some class in PHP and ask AI to fill it in for you from a chat prompt given by the user:

```
class MovieReview {
    public function __construct(
        public string $name,
        public string $description,
        public int $rating
    ) {
    }
}
```

### Requirements

[](#requirements)

You need a OpenAI key or a valid ollama service running (in Docker or locally).

### Setup

[](#setup)

The simplest standalone setup is using any of the static methods in `AiInstructor`:

```
use Apie\AiInstructor\AiInstructor;
// ollama
$instructor = AiInstructor::createForOllama('http://localhost:11434');
// openAI
$instructor = AiInstructor::createForOpenAi('api-key');
// custom:
$instructor = AiInstructor::createForCustomConfig(
    'api-key',
    'http://localhost:11434/'
);
$result = $instructor->instruct(
    MovieReview::class,
    'tinyllama',
    'You are an AI bot that comes up with a movie review for a movie made from the description given by the user. It should follow the format given. If you can not come up with a movie review of the description given by the user, then make a review of a random Hollywood movie.',
    'I think the Lord of the Rings movie has dated terrible'
);
var_dump($result); // dumps a MovieReview instance.
```

It would give a response like this:

```
object(MovieReview)#160 (3) {
  ["name"]=>
  string(21) "The Lord of the Rings"
  ["description"]=>
  string(472) "Once a groundbreaking epic, The Lord of the Rings now feels surprisingly outdated. The ambitious scope and Howard Shore’s majestic score still impress, but the early-2000s CGI and practical-effects limitations often pull you out of Middle-earth. Pacing issues and theatrical dialogue that once felt grand now come across as heavy-handed. While die-hard fans may forgive its age, newcomers might struggle to stay immersed in a story weighed down by its own technical era."
  ["rating"]=>
  int(4)
}

```

### Setup with Apie

[](#setup-with-apie)

You can also set it up with the [Apie library](https://github.com/apie-lib/apie-lib-monorepo). In This case you would need to require apie/apie-bundle for Symfony or apie/laravel-apie for Laravel to setup the key and url in the Laravel/Symfony configuration:

```
apie:
  ai:
    base_url: http://localhost:11434
    api_key: 'ignored-for-ollama'
```

It is recommended to use environment variables for the api key: Symfony:

```
apie:
  ai:
    api_key: '%env(AI_API_KEY)%'
```

Laravel:

```
// config/apie.php
return [
    'ai' => [
        'api_key' => env('AI_API_KEY'),
    ]
];
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance82

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~289 days

Total

2

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/afaff46a911649ad95e1f4909bb19a54731c209c4bcd4e5c1c7604e05bde2089?d=identicon)[pjordaan](/maintainers/pjordaan)

---

Top Contributors

[![pjordaan](https://avatars.githubusercontent.com/u/2209895?v=4)](https://github.com/pjordaan "pjordaan (5 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/apie-ai-instructor/health.svg)

```
[![Health](https://phpackages.com/badges/apie-ai-instructor/health.svg)](https://phpackages.com/packages/apie-ai-instructor)
```

###  Alternatives

[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[pixelopen/cloudflare-turnstile-bundle

A simple package to help integrate Cloudflare Turnstile on Symfony.

31205.8k3](/packages/pixelopen-cloudflare-turnstile-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
