PHPackages                             sabioweb/api-chatgpt - 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. sabioweb/api-chatgpt

ActiveLibrary[API Development](/categories/api)

sabioweb/api-chatgpt
====================

A pure PHP OOP multi-model ChatGPT integration package supporting OCR, Mathematics, Programming, Chat Bot, and Speech models

v1.0.0(5mo ago)03GPL-3.0-or-laterPHPPHP ^8.1

Since Dec 9Pushed 5mo agoCompare

[ Source](https://github.com/sabioweb/Api-Chatgpt)[ Packagist](https://packagist.org/packages/sabioweb/api-chatgpt)[ RSS](/packages/sabioweb-api-chatgpt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

ChatGPT Multi-Model Package
===========================

[](#chatgpt-multi-model-package)

A pure PHP OOP multi-model ChatGPT integration package supporting OCR, Mathematics, Programming, Chat Bot, and Speech models. This package is framework-agnostic, Composer-installable, and can be used in both standalone PHP projects and Laravel applications.

> **📖 [Read in Persian / خواندن به فارسی](README-FA.md)**

Features
--------

[](#features)

- **OCR Model**: Extract text from images using ChatGPT Vision API
- **Mathematics Model**: Solve mathematical problems and equations
- **Programming Model**: Code generation, analysis, and debugging assistance
- **Chat Bot Model**: Conversational AI interactions
- **Speech Model**: Speech-to-Text (audio transcription) and Text-to-Speech (audio synthesis)
- **Framework-agnostic**: Works in Laravel, Symfony, or standalone PHP
- **Composer-installable**: PSR-4 autoloading support
- **Comprehensive error handling**: Custom exceptions for different error scenarios

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer
- ChatGPT API key

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

[](#installation)

```
composer require sabioweb/api-chatgpt
```

Or add to your `composer.json`:

```
{
    "require": {
        "sabioweb/api-chatgpt": "^1.0"
    }
}
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

```
use SBAO\Factory\ServiceFactory;

$factory = new ServiceFactory('your-api-key-here');
```

### OCR Model

[](#ocr-model)

Extract text from images:

```
// Using factory with default configuration
$ocrService = $factory->createOcrService();

// Extract from image file
$text = $ocrService->extractFromFile('/path/to/image.jpg');

// Extract from base64-encoded string
$base64Image = 'data:image/jpeg;base64,/9j/4AAQSkZJRg...';
$text = $ocrService->extractFromBase64($base64Image);

// Using custom configuration
use SBAO\Ocr\OcrConfig;

$config = new OcrConfig(
    model: 'gpt-4-vision-preview',
    quality: 'high',
    maxTokens: 500
);
$ocrService = $factory->createOcrService($config);
```

### Mathematics Model

[](#mathematics-model)

Solve mathematical problems:

```
// Using factory with default configuration
$mathService = $factory->createMathematicsService();

// Solve an equation
$solution = $mathService->solve('Solve for x: 2x + 5 = 15');

// Solve a word problem
$solution = $mathService->solve('If a train travels 120 km in 2 hours, what is its average speed?');

// Using custom configuration
use SBAO\Mathematics\MathematicsConfig;

$config = new MathematicsConfig(
    model: 'gpt-4',
    temperature: 0.3,
    maxTokens: 1000
);
$mathService = $factory->createMathematicsService($config);
```

### Programming Model

[](#programming-model)

Generate, analyze, and debug code:

```
// Using factory with default configuration
$programmingService = $factory->createProgrammingService();

// Generate code
$code = $programmingService->generateCode(
    'Create a PHP function to calculate factorial',
    'php'
);

// Analyze code
$analysis = $programmingService->analyzeCode(
    '
