4

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-**********************************************

1
  • What you call “vague instructions” are just PHP namespaces. From the link you provided, the key is passed to the constructor which is omitted in your example
    – Chris Haas
    Sep 21, 2022 at 4:26

2 Answers 2

7

You should define the $open_ai variable as an OpenAI object by passing your private KEY value, like; new OpenAi('Your-OPENAI-KEY');

An Example;

<?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 add the Quick Start Part to orhanerday/OpenAI readme.

0

First you have you include thé 'autoload'file. 'use' doesn't mean that you have to create a file yourself.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Jan 14 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.