Download the PHP package ogi/prompt without Composer

On this page you can find all versions of the php package ogi/prompt. 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 prompt

CI

Prompt

A PHP package that transforms class properties into XML-formatted prompts, ready for Large Language Model (LLM) API calls. It recursively handles arrays, collections, nested arrays, and nested Prompt instances, converting them into XML with appropriate tags.


Why XML Structured Prompts?

Structured prompts are essential when interacting with Large Language Models (LLMs) to ensure consistency, clarity, and optimal performance. XML provides a standardized way to structure data, making it an excellent choice for formatting prompts:

By using XML-formatted prompts, developers can provide clear and unambiguous instructions to LLMs, potentially enhancing the models' understanding and response accuracy.


Table of Contents


Installation

Install the package via Composer:


Features


Usage

Basic Example

Create a PHP class that extends the Prompt class provided by the package. Define your data using public properties.

Output:


Handling Arrays

The package automatically handles arrays and converts them into XML using <entry> and <list> tags.

Output:


Using Collections

The package supports any object that implements the Traversable interface, such as PHP's ArrayObject or collections from frameworks like Laravel's Illuminate\Support\Collection.

Output:


Nested Prompt Instances

You can have properties that are instances of the Prompt class. These will be rendered recursively within <prompt> tags.

Output:


Using the GeneralPromptTemplate

The GeneralPromptTemplate is an abstract class that allows you to define more structured prompts with context, purpose, goals, and instructions for input and output. You can extend this class and set properties to generate XML prompts.

Output:


Custom Objects with toArray() or __toString__

The package can handle custom objects that implement toArray() or __toString().

Objects with toArray()

Output:

Objects with __toString()

Output:


Handling Special Cases

Private and Protected Properties

Only public properties are included in the XML output. Private and protected properties are excluded.

Output:

Null and Empty Values

Properties with null values or empty arrays are handled gracefully.

Output:

Boolean Values

Boolean values are converted as follows:

Output:

Numeric Values

Numeric values are converted to strings and included in the output.

Output:

Special Characters

Special characters are properly escaped to produce valid XML.

Output:

Objects Without toArray() or __toString__

Objects that cannot be converted to a string or array are represented as empty tags.

Output:

Circular References

The package handles circular references gracefully to prevent infinite recursion.

Output:


Testing

The package includes a comprehensive test suite using PHPUnit to ensure reliability and correctness. Tests cover:

Running Tests

To run the tests, execute:

Or if you have added a Composer script:


Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bugfix.
  3. Write tests for your changes.
  4. Ensure all tests pass.
  5. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the MIT License.


Additional Notes


Need Help?

If you have any questions or need assistance, please open an issue on the GitHub repository.


Happy Coding!


All versions of prompt with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
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 ogi/prompt contains the following files

Loading the files please wait ....