Download the PHP package cognesy/instructor-php without Composer

On this page you can find all versions of the php package cognesy/instructor-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package instructor-php

About This Monorepo

This monorepo contains a set of dev-friendly, framework agnostic components offering 4 main capabilities:

Framework integration packages:

Read More

Overview of Capabilities

The library offers a set of small, focused building blocks.

Structured output

Purpose: turn messy model output into typed PHP data. Benefit: you stop hand-parsing JSON or text before using LLM results.

Detailed docs: packages/instructor/docs/

Unified inference

Purpose: call different LLM providers through one API. Benefit: switch providers without rewriting request code.

Detailed docs: packages/polyglot/docs/

Batch inference (Early Access)

Purpose: submit requests to provider-native asynchronous batch APIs. Benefit: process many requests in the background, then check status and fetch results through one API, with cancellation and job listing where supported.

Detailed docs: BatchInference API and provider capabilities.

Embeddings

Purpose: generate vectors through the same provider layer. Benefit: keep retrieval and inference in one stack.

Detailed docs: packages/polyglot/docs/

Structured decisions

Purpose: evaluate application state with typed yes/no, choice, and score questions. Benefit: use probabilities to decide when to act or ask for review.

Detailed docs: Decision API and full example.

Vector stores and retrieval

Purpose: persist embeddings, index documents, retrieve evidence, and assemble bounded RAG context. Benefit: use replaceable in-memory, Qdrant, or Pgvector stores without coupling retrieval to generation.

Detailed docs: packages/retrieval/README.md

Agents SDK

Purpose: build tool-using agents as a simple loop over state. Benefit: add tools and control flow without inventing your own agent runtime first.

Detailed docs: packages/agents/docs/

Code agent bridges

Purpose: drive external coding agents like Codex, Claude Code, and OpenCode from PHP. Benefit: automate reviews, summaries, and coding workflows through one interface.

Detailed docs: packages/agent-ctrl/docs/

Framework integration

Purpose: install framework-native runtime wiring instead of assembling your own glue. Benefit: get a supported bundle or package surface for container bindings, events, observability, and testing.

Symfony docs highlights:

Usage

Installation

You can install Instructor via Composer:

Basic Example

This is a simple example demonstrating how Instructor retrieves structured information from provided text (or chat message sequence).

Response model class is a plain PHP class with typehints specifying the types of fields of the object.

NOTE: Instructor supports classes / objects as response models. In case you want to extract simple types or enums, you need to wrap them in Scalar adapter - see section below: Extracting Scalar Values.

Validation

Instructor validates results of LLM response against validation rules specified in your data model.

For further details on available validation rules, check Symfony Validation constraints.

Max Retries

In case maxRetries parameter is provided and LLM response does not meet validation criteria, Instructor will make subsequent inference attempts until results meet the requirements or maxRetries is reached.

Instructor uses validation errors to inform LLM on the problems identified in the response, so that LLM can try self-correcting in the next attempt.

Output Modes

Instructor supports multiple output modes through Cognesy\Instructor\Enums\OutputMode to allow working with various models depending on their capabilities.

Additionally, you can use OutputMode::Text to get LLM to generate text output without any structured data extraction.

Unified LLM API

Instructor ecosystem uses Polyglot as an unified inference API layer supporting 20+ LLM providers.

Polyglot takes care of translation of familiar OpenAI chat completion API conventions into LLM provider specific idioms / APIs, so you can easily switch between LLM providers without rewriting your LLM connectivity code.

Example (using sync API)

Example (using streaming API)

Example (customize LLM connection)

Documentation

Check out the documentation website for more details and examples of how to use Instructor for PHP.

Feature Highlights

Core features

Various extraction modes

Flexible inputs

Customization

Sync and streaming support

Observability

Support for multiple LLMs / API providers

Other capabilities

Documentation and examples

What is Instructor?

Instructor is a library that allows you to extract structured, validated data from multiple types of inputs: text, images or OpenAI style chat sequence arrays. It is powered by Large Language Models (LLMs).

Instructor simplifies LLM integration in PHP projects. It handles the complexity of extracting structured data from LLM outputs, so you can focus on building your application logic and iterate faster.

Instructor for PHP is inspired by the Instructor library for Python created by Jason Liu.

Here's a simple CLI demo app using Instructor to extract structured data from text:

How Instructor Enhances Your Workflow

Instructor introduces three key enhancements compared to direct API usage.

Response Model

Specify a PHP class to extract data into via the 'magic' of LLM chat completion. And that's it.

Instructor reduces brittleness of the code extracting the information from textual data by leveraging structured LLM responses.

Instructor helps you write simpler, easier to understand code: you no longer have to define lengthy function call definitions or write code for assigning returned JSON into target data objects.

Validation

Response model generated by LLM can be automatically validated, following set of rules. Currently, Instructor supports only Symfony validation.

You can also provide a context object to use enhanced validator capabilities.

Max Retries

You can set the number of retry attempts for requests.

Instructor will repeat requests in case of validation or deserialization error up to the specified number of times, trying to get a valid response from LLM.

Support for LLM Providers

Instructor offers out-of-the-box support for the following LLM providers:

For usage examples, check Hub section or examples directory in the code repository.

Instructor in Other Languages

Check out implementations in other languages below:

If you want to port Instructor to another language, please reach out to us on Twitter we'd love to help you get started!

Instructor Packages

This repository is a monorepo containing all Instructor's components (required and optional). It hosts all that you need to work with LLMs via Instructor.

Individual components are also distributed as standalone packages that can be used independently.

Links to read-only repositories of the standalone package distributions:

NOTE: If you are just starting to use Instructor, I recommend using the instructor-php package. It contains all the required components and is the easiest way to get started with the library.

License

This project is licensed under the terms of the MIT License.

Support

If you have any questions or need help, please reach out to me on Twitter or GitHub.

Contributing

If you want to help, check out some of the issues. All contributions are welcome - code improvements, documentation, bug reports, blog posts / articles, or new cookbooks and application examples.

Contributors

Contributors


All versions of instructor-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3|^8.4|^8.5
ext-ctype Version *
adbario/php-dot-notation Version ^3.3
aimeos/map Version ^3.8
gioni06/gpt3-tokenizer Version ^1.2
helgesverre/toon Version ^3.2
phpdocumentor/reflection-docblock Version ^5.6 || ^6.0
psr/event-dispatcher Version ^1.0
psr/http-client Version ^1.0
psr/http-message Version ^2.0
psr/log Version ^3.0
symfony/console Version ^7.3 || ^8.0
symfony/config Version ^7.3 || ^8.0
symfony/filesystem Version ^7.3 || ^8.0
symfony/process Version ^7.3 || ^8.0
symfony/property-access Version ^7.3 || ^8.0
symfony/property-info Version ^7.3 || ^8.0
symfony/serializer Version ^7.3 || ^8.0
symfony/type-info Version ^7.3 || ^8.0
symfony/validator Version ^7.3 || ^8.0
symfony/var-dumper Version ^7.3 || ^8.0
symfony/yaml Version ^7.3 || ^8.0
twig/twig Version ^3.0
vlucas/phpdotenv Version ^5.6
yethee/tiktoken Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cognesy/instructor-php contains the following files

Loading the files please wait ...