刚刚看到新闻发布的Welm - 微信AI产品,夏柔迫不及待的搜索了一下关于welm的域名,值得高兴的是还有很多后缀没注册,所以现在的welm.cc属于夏柔的~
当然这一好消息必须先通知群友们,所以很多welm的域名都归我们群友啦~
废话不多说,上代码:
<?php function query_api($prompt, $model, $max_tokens, $temperature, $top_p, $top_k, $n, $echo, $stop, $token) { /** * Welm 微信AI * Author:夏柔 */ $url = "https://welm.weixin.qq.com/v1/completions"; $data = array( "prompt" => $prompt, "model" => $model, "max_tokens" => $max_tokens, "temperature" => $temperature, "top_p" => $top_p, "top_k" => $top_k, "n" => $n, "echo" => $echo, "stop" => $stop ); $data = json_encode($data); $headers = array( "Content-Type: application/json", "Authorization: Bearer " . $token ); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => $data, CURLOPT_HTTPHEADER => $headers, )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "请求失败: " . $err; return null; } else { $result = json_decode($response, true); return $result; } } if (isset($_POST["submit"])) { $prompt = "测试"; $model = "xl"; $max_tokens = 16; $temperature = 0.0; $top_p = 0.0; $top_k = 10; $n = 1; $echo = false; $stop = ",,.。"; $token = "你的token"; $result = query_api($prompt, $model, $max_tokens, $temperature, $top_p, $top_k, $n, $echo, $stop, $token); if ($result) { echo "<pre>"; print_r($result); echo "</pre>"; } } ?> <form method="post"> <input type="submit" name="submit" value="获取结果"> </form>
第45行换成你们在welm官网申请的key