Download the PHP package ruscoe/openai-php without Composer
On this page you can find all versions of the php package ruscoe/openai-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ruscoe/openai-php
More information about ruscoe/openai-php
Files in ruscoe/openai-php
Package openai-php
Short Description PHP library for the OpenAI API
License MIT
Homepage https://github.com/ruscoe/openai-php
Informations about the package openai-php
PHP library for the OpenAI API
An unofficial library for OpenAI's API.
Requirements
- PHP 5.4.0 or above
- Composer
- An OpenAI API key
Quick set up
git clone git@github.com:ruscoe/openai-php.git
cd openai-php
composer install
Usage examples
The following examples assume you store your API key in an environment variable. To do this on a Linux or MacOS system, run:
export OPENAI_API_KEY=sk-XA0yN...
Be sure to substitute your own API key after OPENAI_API_KEY=
.
Completions
This example asks the gpt-3.5-turbo
model to describe a keyboard.
It instructs the OpenAI API to use more than the default number of
tokens so a reasonable length description can be returned.
The response:
Chat
This example sends a simple chat message.
The response:
Images
Create image
This example asks for two images of a red six-sided dice in water.
The response
Create image variation
The source and response
Create image edit
The source and response
Fine-tuning a model
First, take a look at the official documentation on fine-tuning.
Create and upload your training file. Example:
training.jsonl
List your files to get the file ID:
Create a new training job using the file ID you've obtained:
List models to get the name of your new fine-tuned model:
The model name will start with curie:ft
and end with the current date and time.
Create a new completion using your fine-tuned model.
The response should include "animal".
The response should include "rock".
Available functions
Models
Class | Function | Description |
---|---|---|
OpenAIModels | getModels | Gets available OpenAI models. |
OpenAIModels | getModel | Gets a specific OpenAI model. |
Completions
Class | Function | Description |
---|---|---|
OpenAICompletions | create | Creates one or more completions from a given input. |
Chat
Class | Function | Description |
---|---|---|
OpenAIChat | create | Creates one or more completions from a chat conversation. |
Edits
Class | Function | Description |
---|---|---|
OpenAIEdits | create | Performs an edit on a given input. |
Images
Class | Function | Description |
---|---|---|
OpenAIImages | createAsURL | Generates a number of images and returns URLs. |
OpenAIImages | createAsBase64 | Generates a number of images and returns Base64 encoded image(s). |
OpenAIImages | createVariationAsURL | Generates a number of image variations and returns URL(s). |
OpenAIImages | createVariationAsBase64 | Generates a number of image variations and returns Base64 encoded image(s). |
OpenAIImages | createVariation | Generates a number of image variations from a given image. |
OpenAIImages | createEditAsURL | Generates a number of image edits and returns URL(s). |
OpenAIImages | createEditAsBase64 | Generates a number of image edits and returns Base64 encoded image(s). |
OpenAIImages | createEdit | Generates a number of image edits from a given image. |
Embeddings
Class | Function | Description |
---|---|---|
OpenAIEmbeddings | create | Creates an embedding vector from given input. |
Audio
Class | Function | Description |
---|---|---|
OpenAIAudio | transcribe | Transcribes text from an audio file. |
Files
Class | Function | Description |
---|---|---|
OpenAIFiles | getFiles | Gets files owned by the user's organization. |
OpenAIFiles | uploadFile | Uploads a file. |
OpenAIFiles | deleteFile | Deletes a file. |
OpenAIFiles | getFile | Gets information about a file. |
OpenAIFiles | getFileContent | Gets the content of a file. |
Fine-Tunes
Class | Function | Description |
---|---|---|
OpenAIFineTunes | create | Creates a fine-tune job. |
OpenAIFineTunes | getFineTunes | Gets existing fine-tunes. |
OpenAIFineTunes | cancelFineTune | Cancels a fine-tune job. |
OpenAIFineTunes | getFineTuneEvents | Gets status updates of a fine-tune job. |
OpenAIFineTunes | deleteModel | Deletes a fine-tuned model. |
Moderations
Class | Function | Description |
---|---|---|
OpenAIModerations | create | Requests a moderation result from OpenAI. |