PHPackages                             parentyazilim/openaci-chatbot - 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. parentyazilim/openaci-chatbot

ActiveLibrary[API Development](/categories/api)

parentyazilim/openaci-chatbot
=============================

This is a PHP class for interacting with OpenAI's API, specifically for their chatbot, search, and text-generation functionalities, as well as for creating and fine-tuning machine learning models using their API.

00PHP

Since Feb 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/parentyazilim/openai-chatbot)[ Packagist](https://packagist.org/packages/parentyazilim/openaci-chatbot)[ RSS](/packages/parentyazilim-openaci-chatbot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

OpenAI Chatbot
==============

[](#openai-chatbot)

This is a PHP class for interacting with OpenAI's API, specifically for their chatbot, search, and text-generation functionalities, as well as for creating and fine-tuning machine learning models using their API.

The class has the following public methods:

- `__construct($apiKey, $engineId = 'davinci')`: Constructor that takes an API key and an optional engine ID (default is 'davinci').
- `ask($question)`: Method for asking the chatbot a question and getting a response.
- `search($documents, $query, $maxRerank = 200)`: Method for searching for relevant documents using the OpenAI search API.
- `generateText($prompt, $length = 50, $temperature = 0.7)`: Method for generating text using the OpenAI text API.
- `createFineTuningSession($model, $description = '')`: Method for creating a new fine-tuning session using the OpenAI API.
- `uploadTrainingData($sessionId, $data)`: Method for uploading training data to a fine-tuning session using the OpenAI API.
- `startFineTuning($sessionId, $trainingConfig)`: Method for starting training a fine-tuning session using the OpenAI API.
- `checkFineTuningStatus($sessionId)`: Method for checking the status of a fine-tuning session using the OpenAI API.
- `getFineTunedModel($sessionId)`: Method for getting the fine-tuned model from a fine-tuning session using the OpenAI API.

Each of these methods interacts with the OpenAI API using HTTP requests, and returns the relevant response as a PHP object. The `ask()` and `generateText()` methods take a question or prompt as a string and return a string with the corresponding response or generated text. The `search()` method takes an array of documents to search through, a search query, and an optional maximum number of results to rerank, and returns an array of search results. The `createFineTuningSession()` method creates a new fine-tuning session and returns its ID. The `uploadTrainingData()` method uploads training data to an existing fine-tuning session and returns true on success or false on failure. The `startFineTuning()` method starts training a fine-tuning session with the given configuration options and returns true on success or false on failure. The `checkFineTuningStatus()` method checks the status of an existing fine-tuning session and returns its status as a string. The `getFineTunedModel()` method gets the fine-tuned model from an existing fine-tuning session and returns its ID as a string.

OpenAI Chatbot PHP Class
========================

[](#openai-chatbot-php-class)

The `OpenAIChatbot` class is a PHP wrapper for the [OpenAI API](https://beta.openai.com/docs/api-reference/introduction). It allows you to easily use the OpenAI API to generate text, answer questions, search through documents, and perform fine-tuning on models.

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

[](#requirements)

To use the `OpenAIChatbot` class, you will need:

- PHP 7.3 or later
- The `json` and `openssl` extensions enabled
- An OpenAI API key

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

[](#installation)

You can install the `OpenAIChatbot` class using Composer:

```
composer require parentyazilim/openai-chatbot
```

Usage
-----

[](#usage)

To use the `OpenAIChatbot` class, you need to first create an instance of the class and provide your OpenAI API key. You can optionally specify a default engine ID (the default is `davinci`):

```
