Skip to content

lysowc/gpt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Request GPT

Installation

You can install the package via composer:

composer require lysowc/gpt

Quick Start ⚡

Create your index.php file and paste the following code part into the file.

<?php

require __DIR__ . '/vendor/autoload.php'; // remove this line if you use a PHP Framework.

//use aliyun gpt
use Lysowc\Gpt\Repositories\AliGpt\RequestAliGpt;
use GuzzleHttp\Exception\RequestException;

$apikey = "YOUR_API_KEY";
$gpt = new RequestAliGpt($apikey);
//json response
//see https://help.aliyun.com/zh/dashscope/developer-reference/api-details
$params = [
    'model' => 'qwen-turbo',
    'input' => [
        'prompt' => "your question",
    ],
];
try {
    $result = $gpt->json($params)->send();
} catch (RequestException $e) {
    $result = $e->getResponse()->getBody()->getContents();
} catch (Exception $e) {
    $result = $e->getMessage();
}
$result = json_encode($result,true);
var_dump($result);

different requests

//json request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$gpt->json($params)->send();


//form request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$gpt->form($params)->send();


//query request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$gpt->query($params)->send();


//body request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$gpt->body($params)->send();


//multipart request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$result = $gpt->multipart($params)->send();


//multipart request
$gpt = new RequestAliGpt($apikey);
$params = [];//your parameters
$result = $gpt->json/form/query/body/multipart($params)->concurrency(10,5);
//10  => Total concurrency
//5   => The number of requests per request
//$result = [
//    'success' => [
//        [
//            index => index response
//        ]
//        ...
//    ],
//    'error' => [
//        [
//            index => error response
//        ]
//        ...
//    ]
//];

Base URL

You can specify Origin URL with setDomain() method;

$gpt = new RequestAliGpt($apikey);
$gpt->setDomain('https://example.com');

uri

You can specify Origin URL with setUri() method;

$gpt = new RequestAliGpt($apikey);
$gpt->setUri('/api/v1/chat/test');

Set apikey

$gpt->setApiKey("YOUR_API_KEY");

Set header

$gpt->setHeaders(["Connection"=>"keep-alive"]);

About

request gpt

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages