DanielFatkic / openai-client

⚡️ OpenAI PHP is a supercharged PHP API client that allows you to interact with OpenAI API.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenAI PHP

GitHub Workflow Status (master) Total Downloads Latest Version License


OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API.

This project is a work-in-progress. Code and documentation are currently under development and are subject to change.

Get Started

Requires PHP 8.1+

First, install OpenAI via the Composer package manager:

composer require openai-php/client dev-main

Then, interact with OpenAI's API:

$client = OpenAI::client('YOUR_API_KEY');

$result = $client->completions()->create([
    'model' => 'davinci',
    'prompt' => 'PHP is',
]);

echo $result['choices'][0]['text']; // an open-source, widely-used, server-side scripting language.

Usage

Models Resource

list

Lists the currently available models, and provides basic information about each one such as the owner and availability.

$client->models()->list(); // ['data' => [...], ...]

retrieve

Retrieves a model instance, providing basic information about the model such as the owner and permissioning.

$client->models()->retrieve($model); // ['id' => 'text-davinci-002', ...]

delete

Delete a fine-tuned model.

$client->models()->delete($model); // ['id' => 'curie:ft-acmeco-2021-03-03-21-44-20', ...]

Completions Resource

create

Creates a completion for the provided prompt and parameters.

$client->completions()->create($parameters); // ['choices' => [...], ...]

Edits Resource

create

Creates a new edit for the provided input, instruction, and parameters.

$client->edits()->create(); // ['choices' => [...], ...]

Embeddings Resource

create

Creates an embedding vector representing the input text.

$client->embeddings()->create(); // ['data' => [...], ...]

Files Resource

list

Returns a list of files that belong to the user's organization.

$client->files()->list(); // ['data' => [...], ...]

delete

Delete a file.

$client->files()->delete($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]

retrieve

Returns information about a specific file.

$client->files()->retrieve($file); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]

upload

Upload a file that contains document(s) to be used across various endpoints/features.

$client->files()->upload([
        'purpose' => 'fine-tune',
        'file' => fopen('my-file.jsonl', 'r'),
    ]); // ['id' => 'file-XjGxS3KTG0uNmNOK362iJua3', ...]

download

Returns the contents of the specified file.

$client->files()->download($file); // '{"prompt": "<prompt text>", ...'

FineTunes Resource

create

Creates a job that fine-tunes a specified model from a given dataset.

$client->fineTunes()->create($parameters); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]

list

List your organization's fine-tuning jobs.

$client->fineTunes()->list(); // ['data' => [...], ...]

retrieve

Gets info about the fine-tune job.

$client->fineTunes()->retrieve($fineTuneId); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]

cancel

Immediately cancel a fine-tune job.

$client->fineTunes()->cancel($fineTuneId); // ['id' => 'ft-AF1WoRqd3aJAHsqc9NY7iL8F', ...]

list events

Get fine-grained status updates for a fine-tune job.

$client->fineTunes()->listEvents($fineTuneId); // ['data' => [...], ...]

Moderations Resource

create

Classifies if text violates OpenAI's Content Policy.

$client->moderations()->create($parameters); // ['id' => 'modr-5MWoLO', ...]

OpenAI PHP is an open-sourced software licensed under the MIT license.

About

⚡️ OpenAI PHP is a supercharged PHP API client that allows you to interact with OpenAI API.

License:MIT License


Languages

Language:PHP 100.0%