PHP library for accessing the fuzzy.ai API.
PHP 5.3.3 or later with the cURL extension.
You can install the library via Composer:
composer require fuzzy-ai/sdk
To load the library, use Composer's autoload:
require_once('vendor/autoload.php');
All API calls require an API key from https://fuzzy.ai/
$client = new FuzzyAi\Client('YourAPIKey');
list($result, $evalID) = $client->evaluate('YourAgentID', array('input1' => 42));
This is the main class and serves as an entry point to the API.
- FuzzyAi\Client($key, $root) Constructor that takes the following arguments and returns a new Client object.
key
: Your Fuzzy.ai API keyroot
(optional): The API endpoint (defaults to https://api.fuzzy.ai)
- evaluate($agentId, $inputs) The main method to use, it performs a single inference. Returns an array of outputs and an evaluation ID (for training feedback, see below).
agentId
: The ID of the Agent to perform the evaluation againstinputs
: An associative array of input name => values.
- feedback($evaluationId, $performance) This is the method used for training better results. Returns a feedback object.
evaluationId
: Unique identifier returned from an evaluate() call.performance
: The performance metrics (as an associative array) to provide the learning.
- newAgent($props) Use this method to create a new Agent. Returns an Agent object.
props
: An associative array representing an agent with at leastinputs
,outputs
, andrules
.
- getAgent($agentId) This will fetch an existing agent definition. Returns an Agent object.
agentId
: ID of the agent to retrieve
This class represents an Agent and provides full CRUD features.
- FuzzyAi\Agent($client) Constructor - takes an HTTP Client object, but it's easier to use either
newAgent
orgetAgent
from above to create the Agent object. - evaluate($inputs) Like Client::evaluate, but on an existing Agent instance. NOTE Returns an Evaluation object.
inputs
: An associative array of input name => values.
- create($props) Creates a new agent (although Client::newAgent is likely easier).
props
: An associative array representing an agent with at leastinputs
,outputs
, andrules
.
- read($props) Reads an agent definition from the API. Probably easier to use Client::getAgent().
id
: Agent ID to read.
- update($props) Updates the current agent instance with $props.
props
: New agent properties.
- delete() Deletes current agent from the API.
This class represents a single evaluation.
- read($id) Load a single evaluation object by ID.
- feedback($values) Provide learning feedback data to a single evaluation . Returns a Feedback object.
values
: the performance metrics to provide for feedback.
The examples/
directory has some examples of using the library.
Install dependencies:
composer install
Run the tests:
./vendor/bin/phpunit