Download the PHP package xp-forge/openai without Composer

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

OpenAI APIs for XP

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version

This library implements OpenAI APIs with a low-level abstraction approach.

TikToken

Encodes text to tokens. Download the vocabularies cl100k_base (used for GPT-3.5 and GPT-4.0) and o200k_base (used for Omni and O1) first!

Completions

Using the REST API, see https://platform.openai.com/docs/api-reference/making-requests

Streaming

The REST API can use server-sent events to stream responses, see https://platform.openai.com/docs/api-reference/streaming

Embeddings

To create an embedding for a given text, use https://platform.openai.com/docs/guides/embeddings/what-are-embeddings

Text to speech

To stream generate audio, use the API's transmit() method, which sends the given payload and returns the response. See https://platform.openai.com/docs/guides/text-to-speech/overview

Speech to text

To convert audio into text, upload files via the API's open() method, which returns an Upload instance. See https://platform.openai.com/docs/guides/speech-to-text/overview

You can also stream uploads from InputStreams as follows:

Tracing the calls

REST API calls can be traced with the logging library:

Tool calls

There are two types of tools: Built-ins like file_search and code_interpreter (available in the assistants API) as well as custom functions, see https://platform.openai.com/docs/guides/function-calling

Defining functions

Custom functions map to instance methods in a class:

The Param annnotation may define a description and a JSON schema type:

Passing custom functions

Custom functions are registered in a Functions instance and passed via tools inside the payload.

Invoking custom functions

If tool calls are requested by the LLM, invoke them and return to next completion cycle. See https://platform.openai.com/docs/guides/function-calling/configuring-parallel-function-calling

Passing context

Functions can be passed a context as follows by annotating parameters with the Context annotation:

Azure OpenAI

These endpoints differ slightly in how they are invoked, which is handled by the AzureAI implementation. See https://learn.microsoft.com/en-us/azure/ai-services/openai/overview

Distributing requests

The Distributed endpoint allows to distribute requests over multiple endpoints. The ByRemainingRequests class uses the x-ratelimit-remaining-requests header to determine the target. See https://platform.openai.com/docs/guides/rate-limits

For more complex load balancing, have a look at this blog article using Azure API management

Realtime API

Coming soon

See also


All versions of openai with dependencies

PHP Build Version
Package Version
Requires xp-framework/core Version ^12.0 | ^11.0 | ^10.0
xp-framework/logging Version ^11.2
xp-framework/reflection Version ^3.0 | ^2.0
xp-forge/marshalling Version ^2.3
xp-forge/rest-client Version ^5.7
xp-forge/websockets Version ^4.0
php Version >=7.4.0
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 xp-forge/openai contains the following files

Loading the files please wait ....