Code Monkey home page Code Monkey logo

open-ai's Introduction

OpenAI GPT-3 Api Client in PHP

Latest Version on Packagist Total Downloads



orhanerday-open-ai-logo




For more information, you can read laravel news blog post.

News

orhanerday/open-ai added to community libraries php section.

Installation

You can install the package via composer:

composer require orhanerday/open-ai

Usage

To get started with this package, you'll first want to be familiar with the OpenAI API documentation and examples.


Load your key from an environment variable.

According to the following code $open_ai is the base variable for all open-ai operations.

use Orhanerday\OpenAi\OpenAi;

$open_ai = new OpenAi(env('OPEN_AI_API_KEY'));

Completions

Given a prompt, the model will return one or more predicted completions, and can also return the probabilities of alternative tokens at each position.

$complete = $open_ai->complete([
   'engine' => 'davinci',
   'prompt' => 'Hello',
   'temperature' => 0.9,
   'max_tokens' => 150,
   'frequency_penalty' => 0,
   'presence_penalty' => 0.6,
]);

Searches

Given a query and a set of documents or labels, the model ranks each document based on its semantic similarity to the provided query.

$search = $open_ai->search([
    'engine' => 'ada',
    'documents' => ['White House', 'hospital', 'school'],
    'query' => 'the president',
]);

Answers

Given a question, a set of documents, and some examples, the API generates an answer to the question based on the information in the set of documents. This is useful for question-answering applications on sources of truth, like company documentation or a knowledge base.

$answer = $open_ai->answer([
  'documents' => ['Puppy A is happy.', 'Puppy B is sad.'],
  'question' => 'which puppy is happy?',
  'search_model' => 'ada',
  'model' => 'curie',
  'examples_context' => 'In 2017, U.S. life expectancy was 78.6 years.',
  'examples' => [['What is human life expectancy in the United States?', '78 years.']],
  'max_tokens' => 5,
  'stop' => ["\n", '<|endoftext|>'],
]);

Classifications

Given a query and a set of labeled examples, the model will predict the most likely label for the query. Useful as a drop-in replacement for any ML classification or text-to-label task.

$classification = $open_ai->classification([
   'examples' => [
       ['A happy moment', 'Positive'],
       ['I am sad.', 'Negative'],
       ['I am feeling awesome', 'Positive'],
   ],
   'labels' => ['Positive', 'Negative', 'Neutral'],
   'query' => 'It is a raining day =>(',
   'search_model' => 'ada',
   'model' => 'curie',
]);

List engines

Lists the currently available engines, and provides basic information about each one such as the owner and availability.

$engines = $open_ai->engines();

Retrieve engine

Retrieves an engine instance, providing basic information about the engine such as the owner and availability.

$engine = $open_ai->engine('davinci');

Printing results i.e. $search

echo $search;

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please report security vulnerabilities to [email protected]

Credits

License

The MIT License (MIT). Please see License File for more information.

Donation

Buy Me A Coffee

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.