1
This commit is contained in:
41
application/api/controller/Aigpt.php
Normal file
41
application/api/controller/Aigpt.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Think\Env;
|
||||
|
||||
/**
|
||||
* @title 公共管理相关
|
||||
* @description 公共管理相关
|
||||
*/
|
||||
class Aigpt extends Base {
|
||||
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
parent::__construct($request);
|
||||
}
|
||||
|
||||
public function myTestGpt(){
|
||||
$apiKey = Env::get("gpt.api_key");//"你的API密钥"; // 请替换为你的 OpenAI API Key
|
||||
$url = "https://api.openai.com/v1/chat/completions";
|
||||
|
||||
$client = new Client();
|
||||
$response = $client->post($url, [
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
'Authorization' => 'Bearer ' . $apiKey
|
||||
],
|
||||
'json' => [
|
||||
'model' => 'gpt-3.5-turbo',
|
||||
'messages' => [['role' => 'user', 'content' => 'Say this is a test!']],
|
||||
'temperature' => 0.7
|
||||
]
|
||||
]);
|
||||
|
||||
return json($response->getBody()->getContents());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user