I have a site where I want to use the AI API to give the AI a book’s information and write a full description of that book for me (like a small article to publish on the site).
Is it free to use chatgpt API to do this?
Where should I buy an AI API key? How do I buy it? Which AI model should I use to write the best articles for my site?
If you visit platform.openai.com you will be able to create an account there, you can use the AI for free if your usage is low, otherwise you can add a payment card to your account and increase your usage limits. A prepay credit account will grant access to GPT-3.5 and GPT-4 models for you to experiment with.
I have created an account. I connected the api key to a php code, which I put the code source below. https://github.com/Radulepy/PHP-ChatGPT/blob/main/index.php
But when running the code, I get this error: array(1) { ["error"]=> array(4) { ["message"]=> string(76) "You exceeded your current quota, please check your plan and billing details." ["type"]=> string(18) "insufficient_quota" ["param"]=> NULL ["code"]=> string(18) "insufficient_quota" } }
I never managed to generate a text using the API, and I received a 401 error using other packages as well. https://github.com/tectalichq/public-openai-client-php/discussions/37
Give gpt-3.5-turbo a try, you’ll need to experiment with 3.5 and 4 to decide which one you like the result from more, GPT-4 is more expensive but often has better quality results.
Let’s see how well your very language can be used to tell gpt-3.5-turbo what you want.
API programming:
system role message:
You are a writing assistant.
user role message
I have a site where I want to use the AI API to give the AI a book’s information and write a full description of that book for me (like a small article to publish on the site).
Write this book description.
-–
Book: Publication Manual of the APA (7th Edition)
Summary: The Publication Manual of the APA is one of the most recognized style manuals for writers, editors, scholars, and students. The book is user-friendly, and that’s why our customers love the book! It’s no wonder why it’s one of the top selling textbooks.
Textbook’s ISBN: 9781433832161
By American Psychological Association – APA
AI response output:
Introducing the Publication Manual of the APA (7th Edition), a highly esteemed style manual that has become a staple for writers, editors, scholars, and students alike. With its user-friendly approach, this book has garnered immense popularity among our customers, making it a top-selling textbook in its field.
The Publication Manual of the APA serves as an indispensable guide, offering comprehensive instructions on writing, formatting, and citing sources in accordance with the American Psychological Association’s guidelines. Whether you are a seasoned writer or a novice, this manual provides the necessary tools to enhance your writing skills and ensure adherence to the highest standards of academic integrity.
This seventh edition of the manual builds upon its predecessors, incorporating the latest updates and advancements in the field of academic writing. It equips readers with the knowledge to effectively communicate their ideas, present research findings, and craft scholarly papers that meet the rigorous requirements of the APA style.
With its clear and concise explanations, the Publication Manual of the APA empowers users to navigate the complexities of citation and referencing effortlessly. It offers invaluable insights into proper citation formats, enabling writers to avoid plagiarism and give credit where it is due. This meticulous attention to detail is what sets this manual apart and makes it an indispensable resource for anyone engaged in scholarly writing.
The textbook’s ISBN…
(temperature=0.5)
The AI may know the book and simply be able to use its own knowledge to write the description.
If not, it may fill in the description with plausible but not quite true things.
I want to write a PHP code that sends a text to gpt-3.5-turbo and gets the result. For example, send the information of a book and receive explanations about that book
I used the following package: https://packagist.org/packages/haozi-team/chatgpt-php?query=chatgpt
But after running it displays this error: Fatal error: Uncaught Tectalic\OpenAi\ClientException: Unsuccessful response. HTTP status code: 401 (Unauthorized). in /private/var/www/chatgpt/vendor/tectalic/openai/src/Handlers/ChatCompletions.php:150 Stack trace: #0 /private/var/www/chatgpt/index.php(21): Tectalic\OpenAi\Handlers\ChatCompletions->toModel() #1 {main} thrown in /private/var/www/chatgpt/vendor/tectalic/openai/src/Handlers/ChatCompletions.php on line 150
Is there a solution to my problem? Or can you introduce me another way to do this?
require 'vendor/autoload.php';
$openaiClient = \Tectalic\OpenAi\Manager::build(
new \GuzzleHttp\Client(),
new \Tectalic\OpenAi\Authentication(getenv('sk-xxxxxxxxxxxxxxxxxx'))
);
/** @var \Tectalic\OpenAi\Models\ChatCompletions\CreateResponse $response */
$response = $openaiClient->chatCompletions()->create(
new \Tectalic\OpenAi\Models\ChatCompletions\CreateRequest([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
'role' => 'user',
'content' => 'Give me a complete explanation about the book Clean Code written by Robert Martin'
],
],
])
)->toModel();
echo $response->choices[0]->message->content;
My api key is absolutely correct and I already tested it on several platforms and it works correctly
Now I need a code that can send a text or pattern to AI and get a full description like an article
I used the following library: https://packagist.org/packages/orhanerday/open-ai
I ran the following code:
require __DIR__ . '/vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
$open_ai_key = getenv('sk-xxxxxxx');
$open_ai = new OpenAi($open_ai_key);
$text = $open_ai->chat([
'model' => 'gpt-3.5-turbo',
'prompt' => 'Give me a complete explanation about the book Clean Code written by Robert Martin',
'temperature' => 1.0,
'max_tokens' => 1000,
'frequency_penalty' => 0,
'presence_penalty' => 0,
]);
$response = json_decode($text, true);
var_dump($response);
But I got the following error: array(1) { ["error"]=> array(4) { ["message"]=> string(363) "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys." ["type"]=> string(21) "invalid_request_error" ["param"]=> NULL ["code"]=> NULL } }
While I have entered the API correctly! I have charged my account and I have 10 dollars credit!