平台模型Api接入教程说明
2023-09-15
平台模型Api接入说明。
一、任务创建
apiurl: /module.php?m=aiapi_text2text&a=create
$data=array( "appId"=>"appId", "appToken"=>"appToken", "notify_url"=>"/module.php?m=apitest_text2text&a=notify",//通知地址 "action"=>"text2text",//任务类型 "aimodel"=>"chatglm",//具体模型 "prompt"=>$prompt,//提示词 "history"=>[]//历史 ); $rs=curl_post($apiurl,$data);
二、平台通知app:notify_url
//notify数据是以post方式传送的
$task=$_POST;
//需要验证权限 siteToken
if($task["appId"]!=$this->app["appId"] || $task["siteToken"]!=$this->app["siteToken"]){
return false;
}
//开始具体业务三、任务完成通知平台
url:/module.php?m=aiapi_text2text&a=finish_app
$apiurl="/module.php?m=aiapi_text2text&a=finish_app"; $data=array( "appId"=>$this->app["appId"], "appToken"=>$this->app["appToken"], "taskid"=>$task["taskid"], ); $res=curl_post($apiurl,$data);
以text2text模型为例子
<?php
class apitest_text2textControl extends skymvc{
public $app=array(
"appId"=>"",
"appToken"=>"asdasd",
"siteToken"=>"qeds"
);
public function onDefault(){
$this->smarty->display("apitest_text2text/index.html");
}
public function onSave(){
$apiurl=HTTP_HOST."/module.php?m=aiapi_text2text&a=create";
$prompt=$_POST["prompt"];
if(empty($prompt)){
$this->goAll("请填写提示词",1);
}
$data=array(
"appId"=>$this->app["appId"],
"appToken"=>$this->app["appToken"],
"notify_url"=>"/module.php?m=apitest_text2text&a=notify",
"action"=>"text2text",
"aimodel"=>"chatglm",
"prompt"=>$prompt,
"history"=>[]
);
$rs=curl_post($apiurl,$data);
$res=json_decode($rs,true);
if($res["error"]==1){
$this->goAll("任务提交失败",1);
}else{
$this->goAll("任务提交成功",0,array(
"taskid"=>$res["data"]["taskid"],
"taskTime"=>$res["data"]["taskTime"]
));
}
}
public function onCheck(){
$taskid=get_post("taskid","i");
$apiurl=HTTP_HOST."/module.php?m=aiapi_text2text&a=check";
$data=array(
"appId"=>$this->app["appId"],
"appToken"=>$this->app["appToken"],
"taskid"=>$taskid,
);
$rs=curl_post($apiurl,$data);
$res=json_decode($rs,true);
if($res["error"]==0){
$this->goAll("success",0,array(
"content"=>$res["data"]["content"]
));
}else{
$this->goAll("error",1);
}
}
public function onNotify(){
$task=$_POST;
file_put_contents("temp/apitest.txt",serialize($_POST)."\r\n");
$title=post("title","h");
$description=post("description","h");
$content=post("content","x");
switch($task["action"]){
default:
//更新任务
$apiurl=HTTP_HOST."/module.php?m=aiapi_text2text&a=finish_app";
$data=array(
"appId"=>$this->app["appId"],
"appToken"=>$this->app["appToken"],
"taskid"=>$task["taskid"],
);
skyLog("notify.txt","平台通知成功");
$res=curl_post($apiurl,$data);
break;
}
}
}评论列表
写跟帖
{{item.nickname}}
{{item.ip_city}}
{{item.timeago}}
{{item.content}}
加载更多