Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TheTNB/ChatGPT-PHP
Official and Reverse Engineered ChatGPT PHP SDK (Not GPT-3)
https://github.com/TheTNB/ChatGPT-PHP
chatgpt chatgpt-api openai openai-api php
Last synced: 2 months ago
JSON representation
Official and Reverse Engineered ChatGPT PHP SDK (Not GPT-3)
- Host: GitHub
- URL: https://github.com/TheTNB/ChatGPT-PHP
- Owner: TheTNB
- License: mit
- Archived: true
- Created: 2023-02-27T11:26:13.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T07:41:19.000Z (over 1 year ago)
- Last Synced: 2024-10-24T17:53:02.776Z (3 months ago)
- Topics: chatgpt, chatgpt-api, openai, openai-api, php
- Language: PHP
- Homepage:
- Size: 103 KB
- Stars: 113
- Watchers: 3
- Forks: 27
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ChatGPT PHP SDK | [Package](https://packagist.org/packages/haozi-team/chatgpt-php)
[![Total Downloads](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/d/total.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)
[![Latest Stable Version](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/v/stable.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)
[![License](https://poser.pugx.org/HaoZi-Team/ChatGPT-PHP/license.svg)](https://packagist.org/packages/haozi-team/chatgpt-php)Official and Reverse Engineered ChatGPT API for PHP.
Reconstruct from @acheong08's [ChatGPT](https://github.com/acheong08/ChatGPT)
# Installation
`composer require haozi-team/chatgpt-php`
# V1 Web ChatGPT
> Uses `chat.openai.com`
> - Free
> - Rate limited
> - Needs Bypassing Cloudflare> Default api endpoint is `https://ai.fakeopen.com/api/` by @pengzhile
>
> OpenAI rate limit: 50 requests per hour on free accounts. You can get around it with multi-account cycling
>
> Plus accounts has around 150 requests per hour rate limit
>
> Arkose Token: Recently, OpenAI began to require Arkose Token while bypassing Cloudflare request conversation API, usually the SDK can get it automatically through @pengzhile's API## Configuration
1. Create account on [OpenAI's ChatGPT](https://chat.openai.com/)
2. Save your email and password### Authentication
#### - Access token
Login OpenAI account and go to [https://chat.openai.com/api/auth/session](https://chat.openai.com/api/auth/session)
to get your access_token.```json
{
"access_token": ""
}
```The access_token is valid for 30 days.
## Developer API
### Basic example
```php
addAccount('');$answers = $chatGPT->ask('Hello, how are you?');
foreach ($answers as $item) {
print_r($item);
}
//Array(
// 'answer' => 'I am fine, thank you.',
// 'conversation_id' => '',
// 'parent_id' => '',
// 'model' => 'text-davinci-002-render-sha',
// 'account' => '0',
//)
```### Advanced example
You can pass "baseUrl" to the first parameter to set a custom API endpoint.
```php
Recently released by OpenAI
> - Costs moneyGet API key from https://platform.openai.com/account/api-keys
## Developer API
### Basic example
```php
');
$chatGPT->addMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');$answers = $chatGPT->ask('Hello, how are you?');
foreach ($answers as $item) {
print_r($item);
}
```### Advanced example
You can pass "baseUrl" to the second parameter to set a custom API endpoint.
```php
', 'https://api.openai.com/');
```You can use `addMessage` to add messages to the conversation.
```php
');
$chatGPT->addMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');
$chatGPT->addMessage('Hello, how are you?', 'user');
$chatGPT->addMessage('I am fine, thank you.', 'assistant');$answers = $chatGPT->ask('What did I ask you before?');
foreach ($answers as $item) {
print_r($item);
}
//Array(
// 'answer' => 'Hello, how are you?',
// 'id' => 'cmpl-xxxxx',
// 'model' => 'gpt-3.5-turbo',
// 'usage' => [
// "prompt_tokens": 9,
// "completion_tokens": 12,
// "total_tokens": 21,
// ],
//)
```You can set the `stream` parameter to `true` to get a stream for output answers as they are generated.
```php
');
$chatGPT->addMessage('You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.', 'system');$answers = $chatGPT->ask('Hello, how are you?', null, true);// A Generator
foreach ($answers as $item) {
print_r($item);
}
```# Disclaimers
This is not an official OpenAI product. This is a personal project and is not affiliated with OpenAI in any way. Don't
sue me.# Credits
- [acheong08](https://github.com/acheong08) - Python ChatGPT API