Download the PHP package shanginn/openai-sdk without Composer

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

OpenAI SDK PHP

Latest Stable Version Total Downloads License Build Status Coverage Status

A modern, strongly-typed PHP SDK for interacting with the OpenAI API, focusing initially on the Chat Completions endpoint. Built with asynchronous capabilities in mind using amphp/http-client and robust serialization/deserialization via crell/serde.

Features

Installation

Install the package via Composer:

Usage

Simple Text Generation (OpenaiSimple)

This is the easiest way to get a text response for a simple prompt.

Basic Completion (Openai Core Class)

If you need more control over the request parameters or want to handle the response object directly.

Advanced Usage

Tool Calling

Define a tool class implementing ToolInterface (often by extending AbstractTool and using #[OpenaiToolSchema]) and detail its parameters using #[Field] attributes from spiral/json-schema-generator. The SDK will attempt to deserialize the model's arguments into an instance of your tool class.

1. Define the Tool Schema:

2. Call the Tool using OpenaiSimple:

This simplifies the process of forcing a specific tool call and getting the parsed arguments.

3. Call the Tool using Core Openai Class:

This gives you more control over the request and access to the full response, including the tool call ID.

JSON Schema Output

Force the model to generate a JSON object conforming to your predefined PHP class structure. Define the schema class implementing JsonSchemaInterface (often by extending AbstractJsonSchema and using #[OpenaiSchema]) and detail its properties using #[Field] attributes.

1. Define the JSON Schema Class:

2. Generate JSON using OpenaiSimple:

This simplifies getting the deserialized schema object directly.

3. Generate JSON using Core Openai Class:

Provides access to the full response, including the raw JSON string before deserialization.

Image Input

Provide an array of ContentPartInterface objects (TextContentPart, ImageContentPart) to the UserMessage constructor. Requires a vision-capable model like gpt-4o.

Error Handling

The SDK throws specific exceptions found in the Shanginn\Openai\Exceptions namespace for easier error management.

Dependencies

Contributing

Contributions are welcome! Please follow these general steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix (git checkout -b feature/my-new-feature).
  3. Make your changes.
  4. Add tests for your changes.
  5. Ensure tests pass (vendor/bin/phpunit).
  6. Ensure code style compliance (e.g., using PHP CS Fixer or Rector with provided config, if any).
  7. Commit your changes (git commit -am 'Add some feature').
  8. Push to the branch (git push origin feature/my-new-feature).
  9. Create a new Pull Request.

License

This project is licensed under the MIT License


All versions of openai-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
symfony/serializer Version ^7
crell/serde Version ^1.3
amphp/http Version ^2.1
amphp/file Version ^3
amphp/http-client Version ^5.3
spiral/json-schema-generator Version ^1.1
symfony/property-access Version ^7.2
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 shanginn/openai-sdk contains the following files

Loading the files please wait ...