2023-09-16 18:17:16 +08:00

48 lines
2.1 KiB
PHP

<?php
namespace app\extend\ChatGLM;
use yzh52521\EasyHttp\Response;
use yzh52521\EasyHttp\RequestException;
use yzh52521\EasyHttp\Http;
class Core{
private $api_key = '4d652f8ccdd6d091abdf7ea7e41e4cf5.tcenocrd9uxG0lKU';
public function getUrl(){
$user = [
'id' => 'tcenocrd9uxG0lKU', // 这里必须是一个全局抽象唯一id
'api_key' =>'4d652f8ccdd6d091abdf7ea7e41e4cf5',
'exp' => (time()*1000)+3600*1000,
'timestamp'=>time()*1000
];
$token=(new Utils())->setToken($user);
$body=[
'prompt'=>[['role'=>'user','content'=>'你好']],
'meta'=>[
'user_info'=>'我是,里海。我是一名农业专家',
'bot_info'=>'身为农业专家的我,我能为你解决病虫害,种养殖等问题',
'bot_name'=>'里海',
'user_name'=>'小明'
]
];
var_dump(json_encode($body,true));
$token='eyJhbGciOiJIUzI1NiIsInNpZ25fdHlwZSI6IlNJR04ifQ.eyJhcGlfa2V5IjoiNGQ2NTJmOGNjZGQ2ZDA5MWFiZGY3ZWE3ZTQxZTRjZjUiLCJleHAiOiIxNjk0ODU5NjEwMDAwIiwidGltZXN0YW1wIjoxNjk0ODU2MDEwMDAwfQ.n9GTlswJDEhk73FeZrFYnOvDV_eoscbHNb6soRiKnEA';
// $promise = Http::withToken($token)
// ->withHeaders([
// 'accept' => 'text/event-stream'
// ])
// ->post('https://open.bigmodel.cn/api/paas/v3/model-api/characterglm/sse-invoke',$body);
// var_dump($promise->array());
// $promise = Http::withToken($token)
// ->withHeaders([
// 'accept' => 'text/event-stream'
// ])
// ->postAsync('https://open.bigmodel.cn/api/paas/v3/model-api/characterglm/async-invoke', $body, function (Response $response) {
// echo '异步请求成功,响应内容:' . $response->array() . PHP_EOL;
// }, function (RequestException $e) {
// echo '异步请求异常,错误码:' . $e->getCode() . ',错误信息:' . $e->getMessage() . PHP_EOL;
// });
// $promise->wait();
// echo json_encode(['code' => 200, 'msg' => '请求成功'], JSON_UNESCAPED_UNICODE) . PHP_EOL;
}
}