切换OPENAI
This commit is contained in:
@@ -88,18 +88,13 @@ class Aiarticle extends Base
|
||||
}
|
||||
|
||||
//请求OPENAI接口
|
||||
$aParam = ['messages' => $aMessage,'model' => empty($aParam['api_model']) ? 'gpt-4.1' : $aParam['api_model']];
|
||||
$aResult = json_decode($oOpenAi->curlOpenAI($aParam),true);
|
||||
$aParam = ['messages' => $aMessage,'model' => empty($aParam['api_model']) ? 'gpt-4.1' : $aParam['api_model'],'redis_id' => $aSearch['article_id']];
|
||||
$aResult = json_decode($oOpenAi->createWechatContent($aParam),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
if($iStatus != 1){
|
||||
return json_encode($aResult);
|
||||
}
|
||||
//处理返回信息
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
if(empty($aData)){
|
||||
return json_encode(['status' => 6,'msg' => 'OPENAI returns empty content']);
|
||||
}
|
||||
return json_encode(array('status' => 1,'msg' => 'OPENAI successfully generated content','data' => $aData));
|
||||
return json_encode(array('status' => 1,'msg' => 'Content is being generated, please wait'));
|
||||
}
|
||||
|
||||
public function create($aParam = []){
|
||||
@@ -153,21 +148,6 @@ class Aiarticle extends Base
|
||||
}
|
||||
//请求OPENAI
|
||||
$aResult = json_decode($this->createForOpenAi($aArticleContent,$aAiArticle),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '生成失败' : $aResult['msg'];
|
||||
if($iStatus == 1){
|
||||
//四小时后推送上传素材并推送草稿箱
|
||||
$iDelaySeconds = 4 * 3600; // 4小时的秒数
|
||||
Queue::later($iDelaySeconds,'app\api\job\WechatMaterial@fire', ['article_id' => $iArticleId], 'WechatMaterial');
|
||||
$sMsg = '文章AI内容生成成功';
|
||||
}else{
|
||||
$iStatus = 2;
|
||||
}
|
||||
|
||||
//插入日志记录
|
||||
$oMaterial = new Material;
|
||||
$aLogInfo = ['article_id' => $iArticleId,'type' => 5,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oMaterial->addWechatLog($aLogInfo),true);
|
||||
return json_encode($aResult);
|
||||
|
||||
}
|
||||
@@ -211,26 +191,8 @@ class Aiarticle extends Base
|
||||
|
||||
//写入Redis 标识已经开始请求OPENAI处理
|
||||
$sArticleType = empty($aArticle['type']) ? 'default' : $aArticle['type'];
|
||||
$aSearch['article_id'] = $iArticleId;
|
||||
$aResult = $this->_createContentForOpenAI($aSearch,$sArticleType);
|
||||
$aResult = json_decode($aResult,true);
|
||||
if($aResult['status'] != 1){
|
||||
return json_encode($aResult);
|
||||
}
|
||||
$aContent = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
if(empty($aContent)){
|
||||
return json_encode(['status' => 4,'msg' => 'Data is empty']);
|
||||
}
|
||||
|
||||
//组装数据
|
||||
$aContent['article_id'] = $iArticleId;
|
||||
$aContent['title_english'] = $aArticle['title'];
|
||||
$aContent['journal_issn'] = empty($aJournal['issn']) ? '' : $aJournal['issn'];
|
||||
|
||||
|
||||
//更新数据库
|
||||
$aContent['ai_article_id'] = $iId;
|
||||
$aContent['author'] = empty($aJournal['publish_author']) ? 'TMR编辑部' : $aJournal['publish_author'];
|
||||
$aResult = $this->updateAiArticle($aContent);
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user