fixed
This commit is contained in:
51
superadmin/application/admin/controller/Ai.php
Normal file
51
superadmin/application/admin/controller/Ai.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2025/3/24} {11:06}
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use think\Controller;
|
||||
use wanghua\general_utility_tools_php\gpt\chat\ChatGPT;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class Ai extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
*
|
||||
* /ai/talk_skill
|
||||
*/
|
||||
public function talk_skill()
|
||||
{
|
||||
$txt = input('txt');
|
||||
|
||||
$txt = $txt?:'示例话术';
|
||||
$ai_config = config('ai_config');
|
||||
$talk_skill = $ai_config['talk_skill'];
|
||||
|
||||
$obj = new ChatGPT();
|
||||
$obj->url = $talk_skill['base_url'];
|
||||
$obj->apiKey = $talk_skill['api_key'];
|
||||
|
||||
$answer_json_arr = [];
|
||||
Tools::log_to_write_txt(['示例话术请求gpt,入参'=>input()]);
|
||||
$obj->returnAnswer($txt,['stream' => false],$answer_json_arr);
|
||||
Tools::log_to_write_txt(['示例话术请求gpt,出参'=>$answer_json_arr]);
|
||||
$json_arr = json_decode($answer_json_arr[0],true);
|
||||
|
||||
if(empty($json_arr['choices'][0]['message']['content'])){
|
||||
$msg = '处理失败';
|
||||
}else{
|
||||
$msg = $json_arr['choices'][0]['message']['content'];
|
||||
}
|
||||
return json(Tools::set_ok('ok',$msg));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user