Reputation: 51
I need help understanding the vague instructions on https://packagist.org/packages/orhanerday/open-ai
I downloaded the package from https://github.com/orhanerday/open-ai
I installed the package by running "composer require orhanerday/open-ai" in my Command Prompt
Instructions stop making sense from there.....
What does the "use Orhanerday\OpenAi\OpenAi;" code mean and where is it applied? Am I to create a php file say index.php with content:
<?php
use Orhanerday\OpenAi\OpenAi;
$complete = $open_ai->complete([
'engine' => 'davinci',
'prompt' => 'Hello',
'temperature' => 0.9,
'max_tokens' => 150,
'frequency_penalty' => 0,
'presence_penalty' => 0.6,
]
?>
how and where do I add my api key? Do I create a file Orhanerday\OpenAi\OpenAi.php and enter my api key there?
i.e. OPENAI_API_KEY=sk-**********************************************
Upvotes: 5
Views: 12880
Reputation: 1076
You should define the $open_ai
variable as an OpenAI object by passing your private KEY
value.
for example; new OpenAi('Your-OPENAI-KEY');
Complete code;
<?php
use Orhanerday\OpenAi\OpenAi;
$open_ai = new OpenAi('OPEN-AI-KEY');// <- define the variable.
$complete = $open_ai->complete([
'engine' => 'davinci',
'prompt' => 'Hello',
'temperature' => 0.9,
'max_tokens' => 150,
'frequency_penalty' => 0,
'presence_penalty' => 0.6,
]);
I also added the Quick Start Part to orhanerday/OpenAI readme.
Upvotes: 9
Reputation: 11
First you have you include thé 'autoload'file. 'use' doesn't mean that you have to create a file yourself.
Upvotes: 0