1. Go to this page and download the library: Download yandricr/gpti-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?phprequire_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yandricr / gpti-php example snippets
usegpti\...; // select model
$res = new ...();
$res->setAPI(user:"user-xxxxxxxx", secret:"nx-xxxxxxx-xxxxx-xxxxx");
usegpti\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()));
}
usegpti\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()));
}
usegpti\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));
}
}
usegpti\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()));
}
usegpti\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()));
}
usegpti\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));
}
}
usegpti\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()));
}
usegpti\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));
}
}
usegpti\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()));
}
usegpti\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));
}
}
usegpti\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()));
}
usegpti\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));
}
}
usegpti\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()));
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.