PHPackages                             sonichaos360/lugpt - 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. [API Development](/categories/api)
4. /
5. sonichaos360/lugpt

ActiveProject[API Development](/categories/api)

sonichaos360/lugpt
==================

A PHP library for interacting with OpenAI's Completions and ChatCompletions API.

1.0.1(2y ago)356MITPHPPHP &gt;=5.6

Since May 7Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Sonichaos360/LuGPT)[ Packagist](https://packagist.org/packages/sonichaos360/lugpt)[ RSS](/packages/sonichaos360-lugpt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (5)Used By (0)

LuGPT
=====

[](#lugpt)

A PHP library for interacting with OpenAI's Completions and ChatCompletions API.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Initialization](#initialization)
    - [Chat](#chat)
    - [Completion](#completion)
    - [Conversations](#conversations)
- [Todo](#todo)
- [Issues](#issues)
- [Contributing](#contributing)
- [License](#license)

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

[](#installation)

Install the library using [Composer](https://getcomposer.org/):

```
composer require sonichaos360/lugpt
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

Initialize the `LuGPT` class with your OpenAI API key:

```
require_once 'vendor/autoload.php';

use Sonichaos360\LuGPT\Completions;

$apiKey = 'your_openai_api_key';
$model = 'gpt-3.5-turbo';
$maxTokens = '1500';
$temp = '1';
$conversationsPath = '../conversations'; //Optional, necessary only if you will manage conversation history using createConversation()

$luGPT = new Completions($apiKey, $model, $maxTokens, $temp, $conversationsPath);
```

In this example, we are using the `gpt-3.5-turbo` model, which is optimized for chat. The chat-optimized models can be used with the `chat()` method. If you want to use the `completion()` method, you will need to use `text-davinci-003` or another non-chat-optimized model. A list of all available OpenAI models can be found [here](https://platform.openai.com/docs/models).

### Chat

[](#chat)

Send a message using Chat Completions API:

```
$systemMessage = 'You are an assistant that translates English to French.';
$userMessage = 'Translate the following sentence: "Hello, how are you?"';
$response = $luGPT->Chat($systemMessage, $userMessage);

echo $response['choices'][0]['message']['content'];
```

### Conversations

[](#conversations)

Create and manage conversations:

```
// Create a new conversation
$conversationId = $luGPT->createConversation();

// Send messages within the conversation
$systemMessage = 'You are an assistant that translates between any languages.';
$userMessage1 = 'Translate the following sentence from English to French: "Hello, how are you?"';
$response1 = $luGPT->Chat($systemMessage, $userMessage1, $conversationId);

echo $response1['choices'][0]['message']['content']." | ";

$userMessage2 = 'Now, please translate this: "I am fine, thank you."';
$response2 = $luGPT->Chat($systemMessage, $userMessage2, $conversationId);

echo $response2['choices'][0]['message']['content']." | ";
```

This example uses a `conversationId`, which allows the API to remember the context of previous messages and responses. The conversations will be created as separate JSON files stored in the `$conversationsPath` directory.

### Completion

[](#completion)

Send a prompt to the `text-davinci-003` or other non chat completions optimized model:

```
$prompt = 'Translate the following English sentence to French: "Hello, how are you?"';
$response = $luGPT->Completion($prompt);

echo $response["choices"][0]["text"];
```

TODO
----

[](#todo)

Here are some upcoming features and improvements we have planned for the LuGPT library. We encourage contributors to take on these tasks or suggest new ones by creating issues on GitHub:

1. Refactor the `saveTokens()` function, which was deactivated due to strange behavior with non-English language characters.
2. Improve error handling and provide more informative error messages.
3. Implement unit tests for the library to ensure code quality and functionality.

Please consider contributing to the development of these features or suggesting new ones by creating an issue or submitting a pull request. Your input and collaboration are greatly appreciated.

Issues
------

[](#issues)

If you encounter any problems or have suggestions for improvements, we welcome you to create an issue on GitHub. To do so, please follow these steps:

1. Navigate to the [Issues](https://github.com/sonichaos360/lugpt/issues) section of the LuGPT repository.
2. Click on the "New issue" button.
3. Provide a clear and descriptive title for the issue.
4. In the description, include as much detail as possible, such as:
    - A summary of the problem or suggestion.
    - Steps to reproduce the issue, if applicable.
    - The expected behavior and the actual behavior.
    - Any error messages or logs, if available.
    - The PHP version and operating system you are using.
    - Attach any relevant screenshots or code snippets, if necessary.

When creating an issue, please keep the following recommendations in mind:

- Make sure to search the existing issues before submitting a new one, to avoid duplicates.
- Be respectful and courteous to other users and maintain a constructive discussion.
- Stay on topic and keep the conversation relevant to the issue at hand.

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository.
2. Create a new branch for your changes.
3. Make your changes.
4. Submit a pull request.

License
-------

[](#license)

This library is released under the [MIT License](LICENSE).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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 ~6 days

Total

2

Last Release

1092d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b630f04cfbef46bbd9447181858bcb5ec44703f4c3432d44940ce1255b6e488?d=identicon)[Sonichaos](/maintainers/Sonichaos)

---

Top Contributors

[![Sonichaos360](https://avatars.githubusercontent.com/u/5065011?v=4)](https://github.com/Sonichaos360 "Sonichaos360 (3 commits)")

---

Tags

aiopenaichatbotgptgpt-3.5-turbo

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sonichaos360-lugpt/health.svg)

```
[![Health](https://phpackages.com/badges/sonichaos360-lugpt/health.svg)](https://phpackages.com/packages/sonichaos360-lugpt)
```

###  Alternatives

[deepseek-php/deepseek-php-client

deepseek PHP client is a robust and community-driven PHP client library for seamless integration with the Deepseek API, offering efficient access to advanced AI and data processing capabilities.

47073.9k5](/packages/deepseek-php-deepseek-php-client)[maltekuhr/laravel-gpt

Streamlined integration of OpenAI's ChatGPT (GPT-3.5, GPT-4) into Laravel applications.

117130.9k4](/packages/maltekuhr-laravel-gpt)[claude-php/claude-php-sdk-laravel

Laravel integration for the Claude PHP SDK - Anthropic Claude API

5010.8k](/packages/claude-php-claude-php-sdk-laravel)[softcreatr/php-mistral-ai-sdk

A powerful and easy-to-use PHP SDK for the Mistral AI API, allowing seamless integration of advanced AI-powered features into your PHP projects.

1517.9k](/packages/softcreatr-php-mistral-ai-sdk)[softcreatr/php-perplexity-ai-sdk

A powerful and easy-to-use PHP SDK for the pplx (Perplexity) API, allowing seamless integration of advanced AI-powered features into your PHP projects..

149.1k](/packages/softcreatr-php-perplexity-ai-sdk)

PHPackages © 2026

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