豆包听说不错!- public static function postdoubao($message_data) {$apikey = "3668ada1-ddd7-42f9-8a6d-09634418b9a3";$model = "ep-20241215230414-l9zv8";$context = json_decode(RepPostStr($message_data['context'])?: "[]")?: [];$url = 'https://ark.cn-beijing.volces.com/api/v3/chat/completions'; $headers = ["Authorization: Bearer ". $apikey,"Content-Type: application/json"];// 构建 AI 提问数据$postData = ["model" => $model];if (!empty($context)) {$context = array_slice($context, -5);foreach ($context as $message) {$postData['messages'][] = ['role' => 'user', 'content' => str_replace("\n", "\\n", $message[0])];$postData['messages'][] = ['role' => 'system', 'content' => str_replace("\n", "\\n", $message[1])];$question = RepPostStr($message[0]);}} else {$question = RepPostStr($message_data['message']);$postData['messages'][] = ['role' => 'user',"content" => RepPostStr($message_data['message']? $message_data['message'] : '这是哪里')];}$data = self::curlRequest($url, 'POST', json_encode($postData), $headers);return $data;}
复制代码 |