1 line
26 KiB
JSON
1 line
26 KiB
JSON
{"repo": "1111031026/0308", "files": {"php/article_analyzer.php": {"b8cf7e5060b950d9e3749a5aaac4837bdf3214d4": {"t": 1785746178.694397, "n": 4582, "h": "bdfc396d53770a9a", "c": "<?php\n$api_key = \"sk-9483cae29d5644318c39537d786410f7\";\n\nfunction extractContent($html) {\n $prompt = \"請幫我分析並重點整理以下文章內容。請注意以下格式要求:\n1. 使用純文字格式輸出,完全不要使用任何特殊符號(包括但不限於:*、#、-、>、<、=、+、~、`、@、\\$、%、^、&、|、\\\\、/、[、]、{、}等)\n2. 使用數字編號(1、2、3...)和縮排來組織內容\n3. 每個重點請以'重點X:'開頭(X為數字)\n4. 內容請分段呈現,段落之間用空行分隔\n5. 請務必使用繁體中文回答,不要使用英文或簡體中文\n6. 不要使用任何標記語言或格式化符號\n7. 不要使用任何表情符號或特殊字元\n\n請根據以上要求分析以下內容:\\n\\n\" . $html;\n \n global $api_key;\n $maxRetries = 3;\n $retryDelay = 2;\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n \n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n \n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n \n if (!$err && $httpCode === 200) {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() === JSON_ERROR_NONE) {\n return $decodedResponse['choices'][0]['message']['content'];\n }\n }\n \n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n }\n \n return $html; // 如果提取失敗,返回原始HTML\n}\n\nfunction analyzeArticle($content) {\n global $api_key;\n \n $maxRetries = 3;\n $retryDelay = 2; // seconds\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $prompt = \"請幫我分析並重點整理以下文章內容。請注意以下格式要求:\n1. 使用純文字格式輸出,完全不要使用任何特殊符號(包括但不限於:*、#、-、>、<、=、+、~、`、@、\\$、%、^、&、|、\\\\、/、[、]、{、}等)\n2. 使用數字編號(1、2、3...)和縮排來組織內容\n3. 每個重點請以'重點X:'開頭(X為數字)\n4. 內容請分段呈現,段落之間用空行分隔\n5. 請務必使用繁體中文回答,不要使用英文或簡體中文\n6. 不要使用任何標記語言或格式化符號\n7. 不要使用任何表情符號或特殊字元\n\n請根據以上要求分析以下內容:\\n\\n\" . $content;\n\n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n\n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n\n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n\n if ($err || $httpCode !== 200) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n $errorMessage = $err ? \"API 請求失敗 (嘗試 $attempt 次): \" . $err : \"API 響應錯誤,狀態碼: \" . $httpCode . \", 響應內容: \" . $response;\n return [\"error\" => $errorMessage];\n }\n\n try {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() !== JSON_ERROR_NONE) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"JSON 解析錯誤 (嘗試 $attempt 次): \" . json_last_error_msg()];\n }\n return $decodedResponse;\n } catch (Exception $e) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"響應處理錯誤 (嘗試 $attempt 次): \" . $e->getMessage()];\n }\n }\n \n return [\"error\" => \"所有重試都失敗了,請稍後再試\"];\n}\n?>"}, "353a19c8f16bee0287a8bf8617a90337aa67e299": {"t": 1785760339.2430685, "n": 4582, "h": "bdfc396d53770a9a", "c": "<?php\n$api_key = \"sk-9483cae29d5644318c39537d786410f7\";\n\nfunction extractContent($html) {\n $prompt = \"請幫我分析並重點整理以下文章內容。請注意以下格式要求:\n1. 使用純文字格式輸出,完全不要使用任何特殊符號(包括但不限於:*、#、-、>、<、=、+、~、`、@、\\$、%、^、&、|、\\\\、/、[、]、{、}等)\n2. 使用數字編號(1、2、3...)和縮排來組織內容\n3. 每個重點請以'重點X:'開頭(X為數字)\n4. 內容請分段呈現,段落之間用空行分隔\n5. 請務必使用繁體中文回答,不要使用英文或簡體中文\n6. 不要使用任何標記語言或格式化符號\n7. 不要使用任何表情符號或特殊字元\n\n請根據以上要求分析以下內容:\\n\\n\" . $html;\n \n global $api_key;\n $maxRetries = 3;\n $retryDelay = 2;\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n \n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n \n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n \n if (!$err && $httpCode === 200) {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() === JSON_ERROR_NONE) {\n return $decodedResponse['choices'][0]['message']['content'];\n }\n }\n \n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n }\n \n return $html; // 如果提取失敗,返回原始HTML\n}\n\nfunction analyzeArticle($content) {\n global $api_key;\n \n $maxRetries = 3;\n $retryDelay = 2; // seconds\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $prompt = \"請幫我分析並重點整理以下文章內容。請注意以下格式要求:\n1. 使用純文字格式輸出,完全不要使用任何特殊符號(包括但不限於:*、#、-、>、<、=、+、~、`、@、\\$、%、^、&、|、\\\\、/、[、]、{、}等)\n2. 使用數字編號(1、2、3...)和縮排來組織內容\n3. 每個重點請以'重點X:'開頭(X為數字)\n4. 內容請分段呈現,段落之間用空行分隔\n5. 請務必使用繁體中文回答,不要使用英文或簡體中文\n6. 不要使用任何標記語言或格式化符號\n7. 不要使用任何表情符號或特殊字元\n\n請根據以上要求分析以下內容:\\n\\n\" . $content;\n\n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n\n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n\n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n\n if ($err || $httpCode !== 200) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n $errorMessage = $err ? \"API 請求失敗 (嘗試 $attempt 次): \" . $err : \"API 響應錯誤,狀態碼: \" . $httpCode . \", 響應內容: \" . $response;\n return [\"error\" => $errorMessage];\n }\n\n try {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() !== JSON_ERROR_NONE) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"JSON 解析錯誤 (嘗試 $attempt 次): \" . json_last_error_msg()];\n }\n return $decodedResponse;\n } catch (Exception $e) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"響應處理錯誤 (嘗試 $attempt 次): \" . $e->getMessage()];\n }\n }\n \n return [\"error\" => \"所有重試都失敗了,請稍後再試\"];\n}\n?>"}, "bfab03b65e84acea776a7dabf9cdb8a2a858a66c": {"t": 1785760340.6982193, "n": 4284, "h": "17df1eb6d7c0586b", "c": "<?php\n$api_key = \"sk-9483cae29d5644318c39537d786410f7\";\n\nfunction extractContent($html) {\n $prompt = \"請幫我分析並重點整理以下文章內容。請以純文字格式輸出,使用數字編號和縮排來組織內容,不要使用任何特殊符號(如#、*等)或標記語言。每個重點請以'重點X:'開頭,內容請分段呈現。請務必使用繁體中文回答,不要使用英文或簡體中文:\\n\\n\" . $html;\n \n global $api_key;\n $maxRetries = 3;\n $retryDelay = 2;\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n \n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n \n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n \n if (!$err && $httpCode === 200) {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() === JSON_ERROR_NONE) {\n return $decodedResponse['choices'][0]['message']['content'];\n }\n }\n \n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n }\n \n return $html; // 如果提取失敗,返回原始HTML\n}\n\nfunction analyzeArticle($content) {\n global $api_key;\n \n $maxRetries = 3;\n $retryDelay = 2; // seconds\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $prompt = \"請幫我分析並重點整理以下文章內容。請以純文字格式輸出,使用數字編號和縮排來組織內容,不要使用任何特殊符號(如#、*等)或標記語言。每個重點請以'重點X:'開頭,內容請分段呈現。請務必使用繁體中文回答,不要使用英文或簡體中文:\\n\\n\" . $content;\n\n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n\n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n\n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n\n if ($err || $httpCode !== 200) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n $errorMessage = $err ? \"API 請求失敗 (嘗試 $attempt 次): \" . $err : \"API 響應錯誤,狀態碼: \" . $httpCode . \", 響應內容: \" . $response;\n return [\"error\" => $errorMessage];\n }\n\n try {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() !== JSON_ERROR_NONE) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"JSON 解析錯誤 (嘗試 $attempt 次): \" . json_last_error_msg()];\n }\n return $decodedResponse;\n } catch (Exception $e) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"響應處理錯誤 (嘗試 $attempt 次): \" . $e->getMessage()];\n }\n }\n \n return [\"error\" => \"所有重試都失敗了,請稍後再試\"];\n}\n?>"}, "e9f8b14c69764e6bbb96cbd6b2e1d758e64285de": {"t": 1785760342.1441765, "n": 4231, "h": "326121de187dae29", "c": "<?php\n$api_key = \"sk-9483cae29d5644318c39537d786410f7\";\n\nfunction extractContent($html) {\n $prompt = \"請從以下HTML內容中提取主要文章內容和圖片,去除廣告、導航欄等無關內容。請以純文字格式輸出文章的主體部分,不要使用任何特殊符號(如#、*等)或標記語言來格式化文字:\\n\\n\" . $html;\n \n global $api_key;\n $maxRetries = 3;\n $retryDelay = 2;\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n \n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n \n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n \n if (!$err && $httpCode === 200) {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() === JSON_ERROR_NONE) {\n return $decodedResponse['choices'][0]['message']['content'];\n }\n }\n \n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n }\n \n return $html; // 如果提取失敗,返回原始HTML\n}\n\nfunction analyzeArticle($content) {\n global $api_key;\n \n $maxRetries = 3;\n $retryDelay = 2; // seconds\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $prompt = \"請幫我分析並重點整理以下文章內容。請以純文字格式輸出,使用數字編號和縮排來組織內容,不要使用任何特殊符號(如#、*等)或標記語言。每個重點請以'重點X:'開頭,內容請分段呈現:\\n\\n\" . $content;\n\n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n\n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n\n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n\n if ($err || $httpCode !== 200) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n $errorMessage = $err ? \"API 請求失敗 (嘗試 $attempt 次): \" . $err : \"API 響應錯誤,狀態碼: \" . $httpCode . \", 響應內容: \" . $response;\n return [\"error\" => $errorMessage];\n }\n\n try {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() !== JSON_ERROR_NONE) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"JSON 解析錯誤 (嘗試 $attempt 次): \" . json_last_error_msg()];\n }\n return $decodedResponse;\n } catch (Exception $e) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"響應處理錯誤 (嘗試 $attempt 次): \" . $e->getMessage()];\n }\n }\n \n return [\"error\" => \"所有重試都失敗了,請稍後再試\"];\n}\n?>"}, "f8910013374e5a8bc9ad976682497ddcf2ad1acb": {"t": 1785760343.649772, "n": 4138, "h": "886a5d7dbd6a01a5", "c": "<?php\n$api_key = \"sk-9483cae29d5644318c39537d786410f7\";\n\nfunction extractContent($html) {\n $prompt = \"請從以下HTML內容中提取主要文章內容和圖片,去除廣告、導航欄等無關內容。只返回文章的主體部分:\\n\\n\" . $html;\n \n global $api_key;\n $maxRetries = 3;\n $retryDelay = 2;\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n \n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n \n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n \n if (!$err && $httpCode === 200) {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() === JSON_ERROR_NONE) {\n return $decodedResponse['choices'][0]['message']['content'];\n }\n }\n \n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n }\n \n return $html; // 如果提取失敗,返回原始HTML\n}\n\nfunction analyzeArticle($content) {\n global $api_key;\n \n $maxRetries = 3;\n $retryDelay = 2; // seconds\n \n for ($attempt = 1; $attempt <= $maxRetries; $attempt++) {\n $curl = curl_init();\n \n $prompt = \"請幫我分析並重點整理以下文章內容,以清晰易讀的方式呈現重點:\\n\\n\" . $content;\n\n $postData = [\n \"model\" => \"deepseek-chat\",\n \"messages\" => [\n [\n \"role\" => \"user\",\n \"content\" => $prompt\n ]\n ]\n ];\n\n curl_setopt_array($curl, [\n CURLOPT_URL => \"https://api.deepseek.com/v1/chat/completions\",\n CURLOPT_RETURNTRANSFER => true,\n CURLOPT_ENCODING => \"\",\n CURLOPT_MAXREDIRS => 10,\n CURLOPT_TIMEOUT => 60,\n CURLOPT_CONNECTTIMEOUT => 30,\n CURLOPT_SSL_VERIFYPEER => false,\n CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\n CURLOPT_CUSTOMREQUEST => \"POST\",\n CURLOPT_POSTFIELDS => json_encode($postData),\n CURLOPT_HTTPHEADER => [\n \"Authorization: Bearer \" . $api_key,\n \"Content-Type: application/json\",\n \"Accept: application/json\"\n ],\n ]);\n\n $response = curl_exec($curl);\n $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);\n $err = curl_error($curl);\n \n curl_close($curl);\n\n if ($err || $httpCode !== 200) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n $errorMessage = $err ? \"API 請求失敗 (嘗試 $attempt 次): \" . $err : \"API 響應錯誤,狀態碼: \" . $httpCode . \", 響應內容: \" . $response;\n return [\"error\" => $errorMessage];\n }\n\n try {\n $decodedResponse = json_decode($response, true);\n if (json_last_error() !== JSON_ERROR_NONE) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"JSON 解析錯誤 (嘗試 $attempt 次): \" . json_last_error_msg()];\n }\n return $decodedResponse;\n } catch (Exception $e) {\n if ($attempt < $maxRetries) {\n sleep($retryDelay);\n continue;\n }\n return [\"error\" => \"響應處理錯誤 (嘗試 $attempt 次): \" . $e->getMessage()];\n }\n }\n \n return [\"error\" => \"所有重試都失敗了,請稍後再試\"];\n}\n?>"}}}} |