yandricr / gpti-php
This package simplifies your interaction with various GPT models, removing the need for tokens or other methods to access GPT
Requires
- guzzlehttp/guzzle: ^7.8
README
This package simplifies your interaction with various GPT models, eliminating the need for tokens or other methods to access GPT. It also allows you to use three artificial intelligences to generate images: DALL·E, Prodia, and more, some of which are premium while others are free, all of this without restrictions or limits.
Installation
You can install the package via Composer
composer require yandricr/gpti-php
Available Models
GPTI provides access to a variety of artificial intelligence models to meet various needs. Currently, the available models include:
Api key
If you want to access the premium models, enter your credentials. You can obtain them by clicking here.
require "./vendor/autoload.php"; use gpti\...; // select model $res = new ...(); $res->setAPI(user:"user-xxxxxxxx", secret:"nx-xxxxxxx-xxxxx-xxxxx");
Usage GPT
require "./vendor/autoload.php"; use gpti\gpt; $res = new gpt(messages:array( [ "role" => "assistant", "content" => "Hello! How are you today?" ], [ "role" => "user", "content" => "Hello, my name is Yandri." ], [ "role" => "assistant", "content" => "Hello, Yandri! How are you today?" ] ), prompt:"Can you repeat my name?", model:"GPT-4", markdown:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Models
Select one of these available models in the API to enhance your experience.
- gpt-4
- gpt-4-0613
- gpt-4-32k
- gpt-4-0314
- gpt-4-32k-0314
- gpt-3.5-turbo
- gpt-3.5-turbo-16k
- gpt-3.5-turbo-0613
- gpt-3.5-turbo-16k-0613
- gpt-3.5-turbo-0301
- text-davinci-003
- text-davinci-002
- code-davinci-002
- gpt-3
- text-curie-001
- text-babbage-001
- text-ada-001
- davinci
- curie
- babbage
- ada
- babbage-002
- davinci-002
Usage GPT v2
It's quite similar, with the difference that it has the capability to generate real-time responses via streaming using gpt-3.5-turbo.
require "./vendor/autoload.php"; use gpti\gptturbo; $res = new gptturbo(messages:array( [ "role" => "assistant", "content" => "Hello! How are you today?" ], [ "role" => "user", "content" => "Hello, my name is Yandri." ], [ "role" => "assistant", "content" => "Hello, Yandri! How are you today?" ], [ "role" => "user", "content" => "Can you repeat my name?" ] ), markdown:false, stream:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage GPT v2 Streaming
require "./vendor/autoload.php"; use gpti\gptturbo; $res = new gptturbo(messages:array( [ "role" => "assistant", "content" => "Hello! How are you today?" ], [ "role" => "user", "content" => "Hello, my name is Yandri." ], [ "role" => "assistant", "content" => "Hello, Yandri! How are you today?" ], [ "role" => "user", "content" => "Can you repeat my name?" ] ), markdown:false, stream:true); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { foreach($res->stream() as $data){ print(json_encode($data)); } }
Usage GPT Web
GPT-4 has been enhanced by me, but errors may arise due to technological complexity. It is advisable to exercise caution when relying entirely on its accuracy for online queries.
require "./vendor/autoload.php"; use gpti\gptweb; $res = new gptweb(prompt:"Are you familiar with the movie Wonka released in 2023?", markdown:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage GPT-4o
require "./vendor/autoload.php"; use gpti\gpt4o; $res = new gpt4o(messages:array( [ "role" => "assistant", "content" => "Hello! How are you today?" ], [ "role" => "user", "content" => "Hello, my name is Yandri." ], [ "role" => "assistant", "content" => "Hello, Yandri! How are you today?" ], [ "role" => "user", "content" => "Can you repeat my name?" ] ), markdown:false, stream:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage GPT-4o Streaming
require "./vendor/autoload.php"; use gpti\gpt4o; $res = new gpt4o(messages:array( [ "role" => "assistant", "content" => "Hello! How are you today?" ], [ "role" => "user", "content" => "Hello, my name is Yandri." ], [ "role" => "assistant", "content" => "Hello, Yandri! How are you today?" ], [ "role" => "user", "content" => "Can you repeat my name?" ] ), markdown:false, stream:true); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { foreach($res->stream() as $data){ print(json_encode($data)); } }
Usage Bing
require "./vendor/autoload.php"; use gpti\bing; $res = new bing(messages:array( [ "role" => "assistant", "content" => "Hello! How can I help you today? 😊" ], [ "role" => "user", "content" => "Hi, tell me the names of the movies released in 2023." ] ), conversation_style:"Balanced", markdown:false, stream:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage Bing Streaming
require "./vendor/autoload.php"; use gpti\bing; $res = new bing(messages:array( [ "role" => "assistant", "content" => "Hello! How can I help you today? 😊" ], [ "role" => "user", "content" => "Hi, tell me the names of the movies released in 2023." ] ), markdown:false, stream:true); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { foreach($res->stream() as $data){ print(json_encode($data)); } }
Parameters
Usage LLaMA 3.1
require "./vendor/autoload.php"; use gpti\llama; $res = new llama(messages:array( [ "role" => "user", "content" => "Hello, my name is Yandri." ] ), conversation_style:"Balanced", markdown:false, stream:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage LLaMA 3.1 Streaming
require "./vendor/autoload.php"; use gpti\llama; $res = new llama(messages:array( [ "role" => "user", "content" => "Hello, my name is Yandri." ] ), markdown:false, stream:true); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { foreach($res->stream() as $data){ print(json_encode($data)); } }
Usage blackbox
require "./vendor/autoload.php"; use gpti\blackbox; $res = new blackbox(messages:array( [ "role" => "user", "content" => "Hello, my name is Yandri." ] ), conversation_style:"Balanced", markdown:false, stream:false); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
Usage Blackbox Streaming
require "./vendor/autoload.php"; use gpti\blackbox; $res = new blackbox(messages:array( [ "role" => "user", "content" => "Hello, my name is Yandri." ] ), markdown:false, stream:true); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { foreach($res->stream() as $data){ print(json_encode($data)); } }
AI Images
Check the documentation here to learn how to use the different image generation models.
require "./vendor/autoload.php"; use gpti\imageai; $res = new imageai(prompt:"cat color red", model:"dalle", response:"url", data:[]); $res->execute(); if($res->error() != null){ print(json_encode($res->error())); } else { print(json_encode($res->result())); }
API Reference
Currently, some models require your credentials to access them, while others are free. For more details and examples, please refer to the complete documentation.
Code Errors
These are the error codes that will be presented in case the API fails.