Hongmu Notes
Home Language Notes Using ChatGPT with the official API to generate articles – PHP Tutorial
Language Notes PHP

Using ChatGPT with the official API to generate articles – PHP Tutorial

Using ChatGPT with the official API to generate articles – PHP Tutorial

I heard this tool is really popular and awesome – many webmasters have started using it to generate articles and build websites.

So, I wrote a simple PHP script to interact with the official API – it's quite straightforward: just use `composer` to install the required package and then simply make the API call.

I tested it out – a single key can generate 900 articles, and the quality is quite good.

Call Tutorial

ad1a1b7183204823

Find a PHP package at this location.

After looking at several options, I chose this one:openai-php/client

Then, download; Command:composer require openai-php/client

ad1a1b7183205022

Of course, you need to switch to your own project directory!

After installation is complete, simply invoke the function:

require __DIR__ . '/vendor/autoload.php';

$client = OpenAI::client('key');

$result = $client->completions()->create([
    'model' => 'text-davinci-003',
    'prompt' => $_GET['text'],
    'max_tokens' => 1500,
    'temperature' => 0.2,
    'top_p' => 1,
    'n' => 1,
    'presence_penalty' => 0.6,
    'frequency_penalty' => 0,
    'stream' => false,
    'logprobs' => null,
    'stop' => '\n'
]);

echo '<h1>问题</h1>'.$_GET['text'].'<h1>回答</h1><pre><code>'. $result['choices'][0]['text'];

Just load the reference.

Call Effect:

ad1a1b7183204248

Feels pretty good – selling a few keys!

If you have any needs, feel free to get in touch with me!

We also include the source code for the generated article.

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

PHP ob function record

PHP ob function record Language Notes PHP

Usage of the following three functions ob_get_contents(); ob_end_clean(); ob_start(); You can use these functions to buffer local files and execute local script code. Use ob_start() to save the output code into the buffer, and the page will not be displayed; then use ob_get_contents to get the data in the buffer. o…
👁 141
PHP preg

PHP preg Language Notes PHP

The preg_match_all function is used to perform a global regular expression match. preg_match_all() Syntax int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG…
👁 169
Detailed explanation of PHP ternary operator and if

Detailed explanation of PHP ternary operator and if Language Notes PHP

Ternary operator condition ? Result 1 : Result 2 Explanation: The position in front of the question mark is the condition for judgment. If the condition is met, the result is 1, and if it is not met, the result is 2. This article compares and explains the ternary operator and if...else... in detail. I hope it will be helpful to everyone. Today when I was revising my paper online, I encountered a statement that I couldn’t understand: $if_summary = $row['IF_SUMMARY']=…
👁 189
PHP cast type

PHP cast type Language Notes PHP PHP collection PHP and mysql

Get the data type 1. If you want to check the value and type of an expression, use var_dump(). 2. If you just want to get an easy-to-read type expression for debugging, use gettype(). 3. To check a certain type, do not use gettype(), but use the is_type() function. Converting Strings to Numbers When a string is evaluated as a number, the result is determined according to the following rules...
👁 232

Recommended reading

(PC+WAP) Bilingual (Chinese/English) Outdoor Products PbootCMS Website Template – Download Universal Website Source Code for the Outdoor Tent Equipment Industry – 0528

(PC+WAP) Bilingual (Chinese/English) Outdoor Products PbootCMS Website Template – Download Universal Website Source Code for the Outdoor Tent Equipment Industry – 0528 Practical Collection pbootcms Template

A PbootCMS website template designed for the outdoor gear and tent equipment industry, supporting both PC and WAP devices. Featuring an international, minimalist design, this template meets the brand showcase requirements of foreign trade enterprises. It enables outdoor equipment companies to effortlessly create corporate websites tailored for the global market and expand their international business operations. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password:...
👁 59
Construction real estate engineering enterprise website template 0528

Construction real estate engineering enterprise website template 0528 Practical Collection Yiyou template

An eyoucms website template for construction, real estate and engineering companies. The design style is grand and steady, and can display construction engineering cases, real estate projects, corporate strength and brand image. It helps construction and real estate companies establish their brand image online and attract customers. Template display Installation instructions Website backend: /login.php Account: admin Password: admin Related articles Summary of common problems in Yiyou CMS installation Yiyou C...
👁 50
(Adaptive mobile version) Responsive bilingual (Chinese/English) lighting fixture website – PBootCMS template; Download source code for LED lighting fixture website – 0529

(Adaptive mobile version) Responsive bilingual (Chinese/English) lighting fixture website – PBootCMS template; Download source code for LED lighting fixture website – 0529 Practical Collection pbootcms Template

A responsive bilingual (Chinese/English) lighting fixture website template designed for international trade, compatible with both PC and WAP devices. Its international, modern design is ideal for lighting fixture manufacturers to showcase their products on global markets. The multilingual support enables lighting companies to efficiently acquire customers across international markets. Template Preview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 48
How to develop a WordPress plugin?

How to develop a WordPress plugin? Program Notes wordpress

To develop a WordPress plugin, follow these steps: First, create a new folder within the `wp-content/plugins` directory located in your WordPress installation directory to store your plugin code. Then, create a new PHP file in this folder; the file name should be the same as your plugin's name. For example, if your plugin's name is `MyPlugin`, then the file name should be...
👁 188
Furniture custom company enterprise website template 0529

Furniture custom company enterprise website template 0529 Practical Collection Yiyou template

This EyouCMS template is ideal for custom furniture companies, featuring a high-end, modern design style perfect for showcasing custom furniture products, design projects, brand stories, and service processes. It helps custom furniture brands attract homeowners online and enhance their brand image. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | EyouCMS (E...
👁 29