_j
7
You can see the cost per 1000 tokens, which are the encoded language that goes in and out of the AI model.
1 Like
I charged my account $10 to test it first. To begin with, I plan to produce 100,000 articles, each of which is about 700 words in the field of books.
Which model should I use that produces the quality of the text and the price is suitable?
What pattern should I give it so that it can produce complete and accurate explanations for me? (I don’t know much about patterns)
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.
1 Like
_j
10
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.
1 Like
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?
What’s your code look like?
There’s two endpoints currently…
1 Like
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
7 months ago README.md ChatGPT PHP SDK | Package Official and Reverse Engineered ChatGPT API for PHP.
I would try using one of the officially supported PHP libraries…
PHP
https://platform.openai.com/docs/libraries/community-libraries
1 Like
_j
15
You are unauthorized.
This is the use example of that library:
new \Tectalic\OpenAi\Authentication(getenv('OPENAI_API_KEY'))
It seems either you: get the key from the environment, or you don’t use getenv if you want to hard-code a string.
This would look for an environment variable named the same your key to see what’s stored inside…
getenv('sk-xxxxxxxxxxxxxxxxxx')
1 Like
Good catch.
I’d still recommend an officially sanctioned library rather than the one from /haozi-team/that hasn’t been updated in a while…
1 Like
_j
17
Plus nobody says you have to use the same environment variable as every other production AI server just waiting for remote code execution.
rand_seed1=UqRvK1GwS2XcZ3YtPmLo
rand_seed2=hA5bNf8sWnYzDjKpRtQv
1 Like
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!
You’re asking for an environmental variable named the API key as @_j mentioned.
1 Like
_j
20
Same problem shown. Solution above.
$open_ai_key = 'sk-xxxxxxx';
2 Likes
I put the following code and the problem is solved: 
require __DIR__ . '/vendor/autoload.php';
use Orhanerday\OpenAi\OpenAi;
$open_ai_key = 'sk-xxxxxxx';
$open_ai = new OpenAi($open_ai_key);
$text = $open_ai->chat([
'model' => 'gpt-3.5-turbo',
'messages' => [
[
"role" => "system",
"content" => "You are a helpful assistant."
],
[
"role" => "user",
"content" => "Who won the world series in 2020?"
],
[
"role" => "assistant",
"content" => "The Los Angeles Dodgers won the World Series in 2020."
],
[
"role" => "user",
"content" => "Where was it played?"
],
],
'temperature' => 1.0,
'max_tokens' => 1000,
'frequency_penalty' => 0,
'presence_penalty' => 0,
]);
$d = json_decode($text);
echo ($d->choices[0]->message->content);
Now I have a few questions:
1- Why are 4 messages sent here?
2- If I want to give me a complete text like an article about a book, how should I apply to him? I only have the name of the book + the author of the book + the code of the book (this information may be more or less)
3- What should I do so that the written text is at least 700 words long?
4- I want the text to be published on a site. What should I do to receive HTML tags? As: h1-h2-p-bold tags
Because you’re using the Chat completion endpoint. You can find out more on model endpoints here…You could also use the new gpt-turbo-instruct model and the old completion endpoint (where you just send one message and get a message back…)
There’s a great quickstart guide here that will walk you through all the basics now that you’ve got an example up and working.
https://platform.openai.com/docs/quickstart
Looking for more ideas? Check out the Examples gallery or the OpenAI Cookbook on GitHub.
1 Like
_j
23
All of what you describe does not need to be done through the OpenAI API. You can save your credits, and use base ChatGPT for free at chat.openai.com.
This is the format of a message, with roles:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
system: AI programing
user: previous turn <<<<<<<< from saved history
assistant: previous answer<< from saved history
user: current question
A chatbot continues in a loop, adding to the memory of previous responses.
You must manage a record in memory or database of prior conversation, and limit the size so you don’t send more than the model context length available.
If you just want to input a single question or job, you put the instructions as the final user question, and get an AI response back.
1 Like
I have to publish more than 4 million articles on my site, which is really expensive. How can I reduce this cost? Because there are many articles, I cannot write them manually. So they should be written using api and published on the site
_j
25
Yes, automated functions (such as filling a web site full of low-quality AI content) would need to use the API services for scripting batches.
You have 4 million questions to ask an AI? Beyond making the actual API calls to generate content from your input, a “how to” for programming a web site and putting information into a database or content management system is outside the scope of a forum for AI language models.
If the web integration of your AI results is not apparent, you may need to consult a developer or find resources on a forum dedicated to web site programming and data.
1 Like
Yes. I need more than 4 million articles that I want to collect…
The ChatGPT 3.5 model does not have access to resources newer than 2021. What is the solution to this problem?
He does not know about some books. Is there a way to not generate the wrong explanation if it doesn’t know about them?