|
|
@@ -2028,57 +2028,5 @@ class WorkOrder extends Api
|
|
|
->select();
|
|
|
$this->success('成功',$list);
|
|
|
}
|
|
|
-
|
|
|
- //GPT
|
|
|
- public function GPT()
|
|
|
- {
|
|
|
- // 设置 API 密钥
|
|
|
- $apiKey = 'sk-e0JuPjMntkbgi1BoMjrqyyzMKzAxILkQzyGMSy3xiMupuoWY'; // 替换为您的 API 密钥
|
|
|
-
|
|
|
-// 要发送给 GPT 的消息
|
|
|
- $messages = [
|
|
|
- [
|
|
|
- 'role' => 'user',
|
|
|
- 'content' => '你好,GPT!你能帮我写一段 PHP 代码吗?'
|
|
|
- ]
|
|
|
- ];
|
|
|
-
|
|
|
-// 创建请求数据
|
|
|
- $data = [
|
|
|
- 'model' => 'gpt-3.5-turbo', // 使用的模型
|
|
|
- 'messages' => $messages,
|
|
|
- 'max_tokens' => 100, // 设置最大 token 数
|
|
|
- ];
|
|
|
-
|
|
|
-// 初始化 cURL
|
|
|
- $ch = curl_init('https://niubi.zeabur.app/v1/chat/completions');
|
|
|
-
|
|
|
-// 设置 cURL 选项
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
|
- 'Content-Type: application/json',
|
|
|
- 'Authorization: Bearer ' . $apiKey,
|
|
|
- ]);
|
|
|
- curl_setopt($ch, CURLOPT_POST, true);
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
|
-
|
|
|
-// 执行请求
|
|
|
- $response = curl_exec($ch);
|
|
|
-
|
|
|
-// 检查错误
|
|
|
- if (curl_errno($ch)) {
|
|
|
- echo 'Error:' . curl_error($ch);
|
|
|
- }
|
|
|
-
|
|
|
-// 关闭 cURL
|
|
|
- curl_close($ch);
|
|
|
-
|
|
|
-// 解析和输出响应
|
|
|
- $responseData = json_decode($response, true);
|
|
|
- if (isset($responseData['choices'][0]['message']['content'])) {
|
|
|
- echo "GPT 回复: " . $responseData['choices'][0]['message']['content'];
|
|
|
- } else {
|
|
|
- echo "未能获取 GPT 的回复。";
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
}
|