Download the PHP package easygithdev/phpopenai without Composer

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

PHPOpenAI

PHPOpenAI is a community-maintained library that enables the use of the OpenAI API in PHP.

The project is written in PHP and can be used to easily integrate the OpenAI API into your existing PHP project.

System Requirements

This project is based on PHP version 8.1 in order to use features such as enumerations. This project does not require any external dependencies. However, you must have the cURL extension installed for it to work properly.

Installation

The project uses Composer to manage dependencies. If you haven't already installed Composer, you can do so by following the instructions on the official Composer website.

Packagist install

To install the project, you can install the package from packagist.org using the following command:

Writing a first example

To use the OpenAI API, you need to sign up on their website and obtain an API key. Once you have your API key, you can use it in your PHP code to send requests to the OpenAI API.

To find out how to get your key, go to the following address:

https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key.

Here's an example code that shows you how to use the OpenAI API in PHP:

This code instantiates a new OpenAIApi object with an API key, and then creates a new Completion object to perform text completion with the GPT-3 AI language model provided by OpenAI.

The create() method is called on the Completion object to generate a new text completion. It takes two parameters:

The result of the completion is returned in the $response variable. The result can then be used for further processing, such as displaying the completed text or feeding it into another part of the program for additional processing.

Manage the API Key

You can use an environment variable to store your key. You can then use this variable as in the following example:

You can put the variable in Apache configuration file :

And then restart the service.

Now, you can use the environment variable by calling the getenv() function of PHP.

Manage the organization

If you wish to provide information about your organization, you must proceed as follows.

Manage the API's Url

If you need to modify the API's URL, you can proceed as follows:

To redefine a route, you need to extend the OpenAIRoute class or implement the Route interface.

Manage the reponses

The API returns responses in JSON format. To facilitate access to the different information, you can call toObject() or toArray() methods of the Handler object to access the data.

Manage the errors

Sometimes, the API returns errors. Therefore, it is necessary to be able to identify what caused the problem. To handle this difficulty, you have many options.

If you are using a Handler object with toObject() or toArray() methods, just use a try-catch structure.

If you are using the CurlResponse object, you can check that an error has occurred using the validators.

Learn more about errors.

An example of application

Here is a video showing an application that allows you to create images with a painting style defined by the user. This application is created using the PHPOpenAI project.

https://user-images.githubusercontent.com/3519890/230593418-22f26562-e88c-4a92-9601-93bb671a16c0.mp4

You can find the code here:

https://github.com/EasyGithDev/PHPOpenAI-Playground.git.

Code samples

Integrating OpenAI into your application is now as simple as a few lines of code.

You can find all codes here:

https://github.com/EasyGithDev/PHPOpenAI-Examples.

Text Completion using ChatGPT

Learn more about chat completion.

Text Completion using GPT-3

Learn more about text completion.

Text Completion using stream

The stream attribute in the OpenAI API is an optional parameter that you can use to control the data flow returned by the API. If you set this option to True, the API will return a response as a streaming data rather than a single response.

This means that you can retrieve the results of the API as they become available, rather than waiting for the complete response before processing them. This option can be useful for applications that require real-time processing of large amounts of data.

https://user-images.githubusercontent.com/3519890/229144053-d32e6416-0980-44ea-97b7-b2d4a2d26a5d.mp4

Text Edit

Learn more about text edit.

Image Generation Using DALL·E

rabit-32bits

Learn more about image generation.

Image Variation Using DALL·E

variation-1

Learn more about image variation.

Image Edit Using DALL·E

img-edit

Learn more about image edit.

Embedding

Learn more about embedding.

Audio Transcription (Speech to text) using Whisper

Learn more about audio transcription.

Audio Translation (Speech to text) using Whisper

Learn more about audio translation.

Model List

Learn more about model.

Model Retrieve

Learn more about model.

Model Delete

Learn more about model.

File List

Learn more about file.

File Upload

Learn more about file.

File Delete

Learn more about file.

File Retrieve

Learn more about model.

File Retrieve Content

Learn more about model.

Fine-tune List

Learn more about fine-tune.

Fine-tune Create

Learn more about fine-tune.

Fine-tune Retrieve

Learn more about fine-tune.

Fine-tune List Events

Learn more about fine-tune.

Fine-tune Cancel

Learn more about fine-tune.

Moderation

Learn more about moderation.

Testing

To run all tests:

To run only one test :

Summary

PHPOpenAI is a useful project for PHP developers who want to easily integrate the OpenAI API into their projects. With simple installation and the use of Composer, text classification, image generation and named entity recognition into your PHP application.


All versions of phpopenai with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-curl Version *
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 easygithdev/phpopenai contains the following files

Loading the files please wait ....