PHP Classes

How to Use the PHP ChatGPT API to Perform Useful Actions with Text Sentences Using the Package Query Open AI: Perform several types of queries to ChatGPT API

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-10-04 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 41 This week: 3All time: 10,880 This week: 15Up
Version License PHP version Categories
queryopenai 1.0.0GNU General Publi...5PHP 5, Searching, Text processing, Ar..., G...
Description 

Author

This package can perform several types of queries to ChatGPT API.

It provides an example script that can send HTTP requests to ChatGPT API to perform queries with given texts.

Currently, it can:

- Complete a sentence using the text at the beginning of a sentence

- Perform searches for a given text

- Ask questions about a given context

- Classify the emotions expressed by a given text as positive or negative

Picture of Pierre-Henry Soria
  Performance   Level  
Name: Pierre-Henry Soria <contact>
Classes: 50 packages by
Country: United Kingdom
Age: 31
All time rank: 37216 in United Kingdom
Week rank: 3 Up1 in United Kingdom Up
Innovation award
Innovation award
Nominee: 18x

Winner: 3x

Example

<?php

namespace PH7\SearchAi;

// Set up a client with your API key.

use SiteOrigin\OpenAI\Client;
use
SiteOrigin\OpenAI\Engines;
use
Dotenv\Dotenv;

$requiredEnvFields = [
 
'OPENAI_API_KEY'
];

$env = Dotenv::createImmutable(__DIR__);
$env->load();
$env->required($requiredEnvFields)->notEmpty();

$client = new Client($_ENV['OPENAI_API_KEY']);

// Create a completion call
$c = $client->completions(Engines::BABBAGE)->complete('The meaning of life is: ', [ /* ... */]);

// List all the available engines
$e = $client->engines()->list();

// Perform a search
$r = $client->search(Engines::ADA)->search('President', [
   
"White House","hospital","school"
]);
$r = $client->search('curie')->search('President', 'the-file-id');

// Request an Answer
$documents = [
   
"Puppy named Bailey is happy.",
   
"Puppy named Bella is sad.",
];
$a = $client->answers(Engines::CURIE)->create(
   
'Which puppy is happy?',
   
$documents, // Or a file-id
   
'In 2017, U.S. life expectancy was 78.6 years.',
    [[
"What is human life expectancy in the United States?","78 years."]],
    [
"max_tokens" => 5, "stop" => ["\n", "<|endoftext|>"] ]
);

// Request a Classification
$c = $client->classifications(Engines::BABBAGE)->create(
   
'It is a raining day :(',
    [[
"A happy moment", "Positive"],["I am sad.", "Negative"],["I am feeling awesome", "Positive"]]
);
$c = $client->classifications()->create("I'm so happy to be alive", 'the-file-id');

// Classify safe/unsafe content
$f = $client->filter()->classify('ponies are fantastic!'); // 'safe'


Details

QueryOpenAI

A simple PHP project that uses queries some possibilities offered by OpenAI and GPT-3


  Files folder image Files (5)  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file .env.example Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  src  
File Role Description
  Accessible without login Plain text file Query.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:41
This week:3
All time:10,880
This week:15Up