bobbingwide / oik-ai

OIK AI - the new
GNU General Public License v3.0
0 stars 0 forks source link

Attempt to build an excerpt / meta description generator using AI #2

Open bobbingwide opened 10 months ago

bobbingwide commented 10 months ago

Having looked at several SEO plugins that offer AI solutions in the area of generating post meta descriptions, and possibly focus keyphrases, only to discover that they all required you to purchase the PRO version of the plugin, I've decided that the first thing I should attempt is to see if I can use the OpenAI API to generate excerpts and post meta descriptions.

bobbingwide commented 8 months ago

I've been doing this quite successfully for the last few weeks using the ai code in my "bw" environment.

Today I tried to generate the excerpt from the generated page. It was too much for it.

Fatal error: Uncaught OpenAI\Exceptions\ErrorException: Request too large for gpt-4 in organization org-WtxNrX1utaiRw68aDtGdj74i on tokens per min (TPM): Limit 10000, Requested 43201. The input or output tokens must be reduced in order to run successfully. Visit https://platform.openai.com/account/rate-limits to learn more.

in C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php:131

 Stack trace: #0 
C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php(57): OpenAI\Transporters\HttpTransporter->throwIfJsonError(Array, '{\n "error": ...') 
#1 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Resources\Chat.php(33): OpenAI\Transporters\HttpTransporter->requestObject(Object(OpenAI\ValueObjects\Transporter\Payload)) 
#2 C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\classes\class-Oik-AI.php(56): OpenAI\Resources\Chat->create(Array) #3 C:\apache\htdocs\bw\ai\class-ai.php(110): Oik_AI->chat('\r\n<!DOCTYPE htm...') 
#4 C:\apache\htdocs\bw\ai\class-ai.php(100): AI->get_excerpt() 
#5 C:\apache\htdocs\bw\ai\class-ai.php(62): AI->perform_get_excerpt() 
#6 C:\apache\htdocs\bw\ai\ai.php(21): AI->process_form() 
#7 {main} thrown in C:\apache\htdocs\wordpress\wp-content\plugins\oik-ai\vendor\openai-php\client\src\Transporters\HttpTransporter.php on line 131
bobbingwide commented 8 months ago

It's now nearly time to merge the code developed for https://github.com/bobbingwide/bw/issues/31 into the WordPress plugin. I want to retain the ai.php interface so that I can continue to use it without WordPress.

Prior to doing this I need to have a settings.json file that will contain the settings for the AI requests.

And some of the wrapper code provided by bw will need to be re-implemented

bobbingwide commented 8 months ago

I've written the settings.json logic. The delivered plugin will provide settings-example.json with the openai_key set to OPENAI_KEY which will cause the routine to attempt to load the key from the OPENAI_KEY environment variable.

I've reworked the ai.php logic so that it will work when run directly from a WordPress installation, so long as bw is configured with the appropriate files ( C:/apache/htdocs/bw/bobbset.inc' and whatever it loads )

The WordPress part of the plugin is disabled, unless invoked by oik-batch.

bobbingwide commented 8 months ago

v0.1.0 is now committed. See the readme for (some of the) dependencies.