5

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 Commented Sep 21, 2022 at 4:26

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.