Download the PHP package algorithmia/algorithmia without Composer
On this page you can find all versions of the php package algorithmia/algorithmia. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download algorithmia/algorithmia
More information about algorithmia/algorithmia
Files in algorithmia/algorithmia
Package algorithmia
Short Description PHP Client for Algorithmia.com
License MIT
Homepage https://algorithmia.com
Informations about the package algorithmia
Algorithmia Common Library (PHP)
PHP client library for accessing the Algorithmia API For API documentation, see the PHPDocs
Installation
Using the package manager Composer, run:
For non-Composer system, use the source
Authentication
First, create an Algorithmia client and authenticate with your API key. You must replace YOUR_API_KEY with your personal key:
Note that you can also set the api key as an environment variable:
Now you're ready to call AI algorithms from your code.
Calling algorithms
The following examples of calling algorithms are organized by type of input/output which vary between algorithms.
Note: a single algorithm may have different input and output types, or accept multiple types of input, so consult the algorithm's description for usage examples specific to that algorithm.
Text input/output
Call an algorithm with text input by simply passing a string into its pipe
method.
If the algorithm output is text, then the result
field of the response will be a string.
You can also call algorithms asynchronously and get back a promise:
JSON input/output
Call an algorithm with JSON input by passing in any object that can be serialized to JSON such as strings or arrays.
For algorithms that return JSON, the result
field of the response will be the appropriate
deserialized type.
Binary input/output
Call an algorithm with binary input by passing the binary file contents wrapped in an Algorithmia\ByteArray into the pipe
method.
Similarly, if the algorithm response is binary data, then the result
field of the response
will be binary.
Error handling
API errors and Algorithm exceptions will result in throwing an AlgoException
:
Request options
The client exposes options that can configure algorithm requests. This includes support for changing the timeout or indicating that the API should include stdout in the response.
Working with data
The Algorithmia client also provides a way to manage both Algorithmia hosted data and data from Dropbox or S3 accounts that you've connected to you Algorithmia account.
List items in a directory
Work with a directory by instantiating a DataDirectory
object.
Create directories
Create directories by instantiating a DataDirectory
object and calling create()
.
Upload files to a directory
Upload files by calling put
on a DataFile
object,
or by calling putFile
on a DataDirectory
object.
Note: you can also instantiate a DataFile
by either $client->file('/path/to/file')
or $client->dir('path')->file('filename')
Download contents of file
Download files by calling getString
, getBytes
, getJson
, or getFile
on a DataFile
object:
Note: the getFile()
method uses streams, so if you're getting large files, that's the way you'll want to do it to avoid memory issues.
Delete files and directories
Delete files and directories by calling delete
on their respective DataFile
or DataDirectory
object.
DataDirectories take an optional force
parameter that indicates whether the directory should be deleted
if it contains files or other directories.
Directory permissions
Directory permissions may be set when creating a directory, or may be updated on already existing directories.
Running the tests
Running the tests will connect to the Algorithmia server and execute a variety of connections and exercises to validate the client. You'll need to provide your API KEY to run the tests in a file called "apikey.txt" in the /tests directory. Just create that file and paste in your API KEY with nothing else in the file.
Then you can run the tests by executing:
./vendor/bin/phpunit -v tests
Reading the tests is also a great way to see code examples.