除了之前的大模型我们再看看其他厂商的大模型和社区,比如科大讯飞。
Let's 构!

1. 通过科大讯飞官网(https://www.xfyun.cn)注册账号并登录控制台。
2. 调用API之前先创建一个应用,名称、分类等都不要求。

3. 我们调用下“图片理解”服务,上传一张图片通过API响应返回出图片中的场景,通过官网文档可以找到示例代码,这次我们选用PHP版本,https://www.xfyun.cn/doc/image/scene-recg/API.html。
4. 代码略作修改,如下。
<?php
/*图片数据可以通过两种方式上传,第一种在请求头设置image_url参数,第二种将图片二进制数据写入请求体中。若同时设置,以第一种为准。
*使用二进制数据写入请求体时,不需要在header中传递image_url参数
*使用传递url参数时,请求体为空即可
*本例采用将图片二进制数据写入请求体中的方式
*具体请参考接口文档:https://doc.xfyun.cn/rest_api/
*/
class test{
function xfyun(){
$daytime=strtotime('1970-1-1T00:00:00 UTC');
$api = "http://tupapi.xfyun.cn/v1/scene";
$XAppid = "<your_app_id>";
$Apikey = "<your_api_key>";
$XCurTime =time();
$XParam ="";
$XCheckSum ="";
$image = "mumulab.png";
$Param= array(
"image_name"=>$image
);
$XParam = base64_encode(json_encode($Param));
$XCheckSum = md5($Apikey.$XCurTime.$XParam);
$headers = array();
$headers[] = 'X-CurTime:'.$XCurTime;
$headers[] = 'X-Param:'.$XParam;
$headers[] = 'X-Appid:'.$XAppid;
$headers[] = 'X-CheckSum:'.$XCheckSum;
$headers[] = 'Content-Type:application/x-www-form-urlencoded; charset=utf-8';
echo $this->http_request($api, $image, $headers, $image);
}
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function http_request($url, $post_data, $headers, $image) {
$postdata = file_get_contents($image);
$options = array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => $postdata,
'timeout' => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo $result;
return "success";
}
}
$a = new test();
$a->xfyun();
?>
5. 请求PHP文件,我们上传一张MumuLab.cn的图片,可以在API响应中可以看到label为“17”,也就是没有场景,符合预期。


6. 我们再更换一张图片,也能获得大致符合预期的结果。


7. 响应的label表示的场景在官网文档中可以找到对应解释。

8. 在控制台中可以看到使用的服务量和剩余服务量。

9. 一起尝试更多功能吧。

一起来交流吧,实践之后才能更好的掌握!
MumuLab.cn 动手实验室

2919

被折叠的 条评论
为什么被折叠?



