This commit is contained in:
王金磊
2023-04-23 09:33:19 +08:00
parent 7e8f5d6612
commit 883c9a870c
4 changed files with 33 additions and 17 deletions

View File

@@ -259,23 +259,18 @@ function search_array_val($arr, $val)
}
}
function GptChar($message,$ckey,$mid="")
function GptChar($message,$ckey)
{
$url = 'https://api.openai.com/v1/chat/completions';
// OpenAI API key
$api_key = Env::get("gpt.api_key");
$mes['role'] = "user";
$mes['content'] = $message;
if($mid!=""){
$mes['name'] = $mid;
}
// Request data
$data = array(
'model' => 'gpt-3.5-turbo',
'messages' => [$mes],
'messages' => $message,
'temperature' => 0.2,
'max_tokens' => 2048,
'n' => 1,
@@ -323,7 +318,7 @@ function GptChar($message,$ckey,$mid="")
if($cache_id!=''){
Cache::set($ckey."_id",$cache_id);
}
Cache::set($ckey,$cc."[{enddata}]",3600);
Cache::set($ckey,(Cache::get($ckey)?Cache::get($ckey):'')."[{enddata}]",3600);
}