Files
fast_response/superadmin/application/admin/controller/Ai.php
Your Name dce091da91 t
2025-03-27 07:52:44 +00:00

51 lines
1.2 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* description
* authorwh
* 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
* authorwh
*
* /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));
}
}