hstanleycrow / easyphpopenai
Free PHP Library to use OpenAI API into any PHP project
dev-main
2023-05-01 00:59 UTC
Requires
- php: ^8.0
- hstanleycrow/easyphpcurlrequest: ^1.0
- vlucas/phpdotenv: ^5.5
This package is auto-updated.
Last update: 2024-12-30 02:28:35 UTC
README
Easy PHP OpenAI
Free PHP Library to use OpenAI API into any PHP project
How To Use • Download • License
How To Use
# Clone this repository $ git clone https://github.com/hstanleycrow/EasyPHPOpenAI/ # install libraries $ composer update
or
# Install using composer $ composer require hstanleycrow/easyphpopenai ### Using Examples You can adjdust the parameters like temperature, stop, max_tokens, see full list of parameters on the methods. ```php $openAIAPI = new OpenAIAPI($OPENAI_API_KEY); # Get Model lists var_dump($openAIAPI->models()); # Completion Example /* $prompt = "Por favor, genera un solo meta título basado en los título de los resultados de búsqueda de Google que proporciono basados en las keywords para las que quiero posicionar. Analiza lo mas relevante, trata de apegartea a la longitud de los titulos de muestra. Estos son los titulos de muestra:###\n1- Zapatos azules baratos\n2- Mejores Zapatos azules\n3- Zapatos Azules duraderos\n4- Zapatos deportivos azules baratos\n\n###"; if ($response = $openAIAPI->complete($prompt)) : echo "Titulo: $response"; else : echo $openAIAPI->errorMessage(); endif; # Edit Example $input = "What day of the wek is it?"; $instruction = "Fix the spelling mistakes"; $openAIAPI->setModel("text-davinci-edit-001"); if ($response = $openAIAPI->edit($input, $instruction)) : echo "Respuesta: $response"; else : echo $openAIAPI->errorMessage(); endif;
Download
You can download the latest version here.
PHP Versions
I have tested this class only in this PHP versions. So, if you have an older version and do not work, let me know.
Support
License
MIT
www.hablemosdeseo.net · GitHub @hstanleycrow · Twitter @harold_crow