Download the PHP package ami-praha/ai-item-finder without Composer

On this page you can find all versions of the php package ami-praha/ai-item-finder. 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 ai-item-finder

AI Item Finder

A Laravel package that uses Large Language Models (LLM) to find the closest matching item from a list. This package leverages OpenAI's GPT models to perform intelligent matching based on semantic similarity rather than simple string matching.

Features

Requirements

Installation

Install the package via Composer:

Publish the configuration file:

Add your OpenAI API key to your .env file:

Optionally, you can also set the model:

Usage

Basic Usage

Using the Service Class Directly

Advanced Usage with Custom Instructions

Using Different Models

Custom System Message

If you need complete control over the AI's behavior, you can set a custom system message:

Using List Description for Better Accuracy

You can provide a description of what the list items represent to help the AI make more accurate matches:

Handling Low-Confidence Matches

By default, the package evaluates match confidence and returns null if the match confidence is below 80%. You can customize this behavior:

Configuration

The configuration file config/ai-item-finder.php contains the following options:

Performance Considerations

Two-Step Confidence Evaluation

By default, when confidence scoring is enabled (setAllowNoResult(true)), the package uses a two-step approach:

  1. First API call: Finds the best matching item from your list
  2. Second API call: Evaluates the confidence score for that specific match

This separation provides more accurate and unbiased confidence scores because:

However, this comes with performance tradeoffs:

Cost Implications

Example costs with gpt-4o-mini (approximate):

Latency Implications

Optimizing for High-Volume Scenarios

If you're processing many searches or need faster response times, disable confidence scoring:

When to Use Confidence Scoring

Enable confidence scoring when:

Disable confidence scoring when:

Accessing Confidence Data

When confidence scoring is enabled, you can access the score, reasoning, and the matched item that was evaluated after finding a match:

Available Methods

setList(array $list)

Set the list of items to search through.

setSearchedItem(string $key, mixed $value)

Set the item you're searching for. The key is used for context, and the value is what will be matched.

setDescriptionOfList(string $description)

Set a description of what the list items represent. This provides additional context to the AI for more accurate matching.

setAdditionalInstructions(string $instructions)

Add additional instructions to guide the AI's matching behavior.

setCustomSystemMessage(string $message)

Override the default system message entirely.

setAllowNoResult(bool $allowNoResult = true)

Set whether to allow null to be returned if the confidence score is below the threshold. When set to true (default), the find() method will return null if the best match has a confidence score below the threshold set by setNoResultConfidenceThreshold(). When set to false, the closest match will always be returned regardless of confidence.

setNoResultConfidenceThreshold(int $threshold)

Set the minimum confidence threshold (0-100) required for returning a match. Default is 80%. This threshold only applies when setAllowNoResult(true) is set. If the best match has a confidence score below this threshold, null will be returned instead.

setModel(string $model)

Set the OpenAI model to use (e.g., 'gpt-4.1', 'gpt-4.1-mini', 'gpt-5').

find()

Execute the search and return the closest matching item. Returns array|null - the matched item from the list, or null if no sufficiently confident match is found (when allowNoResult is true and confidence is below the threshold).

getConfidenceScore()

Get the confidence score (0-100) of the last match. Returns int|null - the confidence score, or null if no match has been performed yet or if confidence scoring was disabled (setAllowNoResult(false)). This method should be called after find().

getConfidenceReasoning()

Get the reasoning behind the confidence score of the last match. Returns string|null - a text explanation of why the confidence score was assigned, or null if no match has been performed yet or if confidence scoring was disabled. This method should be called after find().

getConfidenceEvaluationMatchedItem()

Get the matched item that was used for the confidence evaluation. Returns array|null - the matched item that was evaluated for confidence scoring, or null if no match has been performed yet or if confidence scoring was disabled (setAllowNoResult(false)). This method should be called after find(). Note that this returns the same item as find() when a match is found, but provides access to it even when examining confidence data.

getModel()

Get the OpenAI model being used. Returns string - the OpenAI model name (e.g., 'gpt-4.1-mini', 'gpt-4o', 'gpt-5').

getApiUrl()

Get the OpenAI API URL. Returns string - the API endpoint URL.

getList()

Get the list of items to search through. Returns array - the array of items that was set via setList().

getDescriptionOfList()

Get the description of the list. Returns string|null - the description of what the list items represent, or null if not set.

getSearchedItemKey()

Get the searched item key. Returns string|null - the key name for the searched item, or null if not set.

getSearchedItemValue()

Get the searched item value. Returns mixed - the value being searched for, or null if not set.

getAdditionalInstructions()

Get the additional instructions. Returns string|null - the additional instructions for the AI, or null if not set.

getSystemMessage()

Get the complete system message that will be sent to the AI. Returns string|null - the constructed system message including custom message, list description, and additional instructions.

getAllowNoResult()

Get whether no result is allowed. Returns bool - whether null results are allowed when confidence is low.

getNoResultConfidenceThreshold()

Get the no result confidence threshold. Returns int - the confidence threshold (0-100) below which null is returned.

Error Handling

The package provides specific exception classes for different error scenarios:

Exception Types

InvalidConfigurationException - Thrown when configuration is invalid:

InvalidInputException - Thrown when input data is invalid:

InvalidApiResponseException - Thrown when the API returns unexpected data:

All exceptions extend the base AiItemFinderException class, which extends PHP's standard Exception.

Usage Examples

You can also catch all package exceptions using the base exception class:

Use Cases

License

MIT License

Author

AMI Praha a.s.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


All versions of ai-item-finder with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3|^8.4|^8.5
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/http Version ^10.0|^11.0|^12.0
guzzlehttp/guzzle Version ^7.0
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 ami-praha/ai-item-finder contains the following files

Loading the files please wait ...