instructor-php  by cognesy

PHP library for structured data extraction using LLMs

Created 1 year ago
282 stars

Top 92.5% on SourcePulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

Instructor for PHP enables structured data extraction from LLM outputs, simplifying integration for PHP developers. It handles complex data parsing, validation, and retries, allowing users to focus on application logic rather than LLM response handling.

How It Works

Instructor leverages PHP's type hinting and reflection capabilities to define data structures. It translates these structures into schemas for LLMs, automatically validates responses against these schemas, and manages retries with LLM feedback for invalid outputs. This approach reduces boilerplate code and improves the reliability of LLM-driven data extraction.

Quick Start & Requirements

  • Install via Composer: composer require cognesy/instructor-php
  • Requires PHP 8.2 or later.
  • Dependencies include Guzzle and various Symfony components.
  • API keys for LLM providers are necessary.
  • Official documentation and examples are available.

Highlighted Details

  • Supports multiple LLM providers (OpenAI, Anthropic, Gemini, Ollama, etc.) and local models.
  • Offers various extraction modes: JSON Schema, Tool Calling, and Markdown JSON.
  • Includes streaming support for partial results and custom validation callbacks.
  • Facilitates structured-to-structured processing and extraction of scalar/enum values.

Maintenance & Community

The project is actively maintained by cognesy. Community support is available via Twitter and GitHub. Contributions are welcomed.

Licensing & Compatibility

  • Licensed under the MIT License.
  • Compatible with any PHP framework due to minimal dependencies.

Limitations & Caveats

Instructor relies on PHP DocBlocks for certain advanced features like type hints for arrays and additional LLM instructions, which may require adherence to specific documentation conventions. The library is inspired by Python's Pydantic, but PHP's ecosystem lacks a direct equivalent, leading to reliance on a combination of PHP features and external components for its functionality.

Health Check
Last Commit

4 days ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
2
Star History
4 stars in the last 30 days

Explore Similar Projects

Starred by John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), Sasha Rush Sasha Rush(Research Scientist at Cursor; Professor at Cornell Tech), and
2 more.

llmparser by kyang6

0%
426
LLM tool for structured data extraction and classification
Created 2 years ago
Updated 2 years ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Jerry Liu Jerry Liu(Cofounder of LlamaIndex), and
1 more.

sparrow by katanaml

0.1%
5k
Data processing & instruction calling tool using ML, LLM, and Vision LLM
Created 3 years ago
Updated 1 day ago
Feedback? Help us improve.