PHPackages                             mathsgod/openai-chat - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mathsgod/openai-chat

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mathsgod/openai-chat
====================

OpenAI Chat completion wrapper. Support function calls and variable assignment.

2.1.1(2y ago)017MITPHPPHP ^8.0

Since Jun 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mathsgod/openai-chat)[ Packagist](https://packagist.org/packages/mathsgod/openai-chat)[ RSS](/packages/mathsgod-openai-chat/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (5)Versions (13)Used By (0)

openai-chat
===========

[](#openai-chat)

Installation
------------

[](#installation)

```
composer require mathsgod/openai-chat
```

Usage
-----

[](#usage)

To use the OpenAI chat, you need to create a new instance of the `System` class and pass the OpenAI API key as the first argument.

```
use OpenAI\Chat\System;

$system = new System($_ENV['OPENAI_API_KEY']);

echo $system->ask("Hello");
```

### Add a tool

[](#add-a-tool)

```
use OpenAI\Chat\Attributes\Tool;
use OpenAI\Chat\Attributes\Parameter;

#[Tool(description: 'Get the release date of iphone')]
function getIPhoneReleaseDate(#[Parameter("model of the phone")] string $model)
{
    return ["date" => "2022-09-14", "model" => $model];
}

$system->addTool(Closure::fromCallable("getIPhoneReleaseDate"));

echo $system->ask("When will iPhone 14 be released?");
```

#### Add a tool from a class method

[](#add-a-tool-from-a-class-method)

```
class Controller
{
    public $price = "$799";

    #[Tool(description: 'Get the price of iphone')]
    public function getIPhonePrice(#[Parameter("model of the phone")] string $model)
    {
        return ["price" => $this->price, "model" => $model];
    }
}

$system->addTool(Closure::fromCallable([new Controller(), "getIPhonePrice"]));

echo $system->ask("What is the price and release date of iphone14?");
```

### Get usage records

[](#get-usage-records)

After run the code above, you can get the usage records

```
print_r($system->getUsages());
```

### Streaming

[](#streaming)

```
$stream = $system->askAsStream("What is the price and release date of iphone14?");

$stream->on('data', function ($data) {
    echo $data;
});
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~33 days

Recently: every ~55 days

Total

12

Last Release

737d ago

Major Versions

1.6.0 → 2.0.02024-04-19

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18732337?v=4)[Raymond](/maintainers/mathsgod)[@mathsgod](https://github.com/mathsgod)

---

Top Contributors

[![mathsgod](https://avatars.githubusercontent.com/u/18732337?v=4)](https://github.com/mathsgod "mathsgod (36 commits)")

### Embed Badge

![Health badge](/badges/mathsgod-openai-chat/health.svg)

```
[![Health](https://phpackages.com/badges/mathsgod-openai-chat/health.svg)](https://phpackages.com/packages/mathsgod-openai-chat)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.2k](/packages/friendsofphp-php-cs-fixer)[symfony/lock

Creates and manages locks, a mechanism to provide exclusive access to a shared resource

514139.2M692](/packages/symfony-lock)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M208](/packages/illuminate-broadcasting)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
