{"id":6832,"date":"2023-12-04T18:03:31","date_gmt":"2023-12-04T10:03:31","guid":{"rendered":"https:\/\/cn.letianpai.com\/?p=6832"},"modified":"2024-12-18T14:08:34","modified_gmt":"2024-12-18T06:08:34","slug":"%e7%a7%81%e6%9c%89%e5%8c%96%e5%a4%a7%e6%a8%a1%e5%9e%8b%e9%85%8d%e7%bd%ae%e8%af%b4%e6%98%8e%e5%8f%8a%e6%8e%a5%e5%8f%a3%e7%ba%a6%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/cn.letianpai.com\/?p=6832","title":{"rendered":"\u4e50\u5929\u6d3e\u673a\u5668\u4eba\u79c1\u6709\u5316AI\u5927\u6a21\u578bGPT\u914d\u7f6e\u8bf4\u660e\u53ca\u63a5\u53e3\u7ea6\u5b9a"},"content":{"rendered":"\n<p>\u4e50\u5929\u6d3e\u684c\u9762\u673a\u5668\u4eba\u652f\u6301\u63a5\u5165\u4efb\u610f\u7b2c\u4e09\u65b9AI\u5927\u6a21\u578b\uff0c\u6216\u8005\u63a5\u5165\u4efb\u610f\u79c1\u6709\u5316AI\u5927\u6a21\u578b\uff0c\u7528\u6237\u9700\u8981\u642d\u5efa\u4e00\u4e2a\u81ea\u5df1\u7684\u4e91\u7aef\u670d\u52a1\u5668\uff0c\u901a\u8fc7\u4e50\u5929\u6d3e\u673a\u5668\u4eba\u63a5\u5165\u4e91\uff0c\u5373\u53ef\u5b8c\u6210\u3002\u901a\u8fc7\u79c1\u6709\u4e91\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u7528\u6237\u79c1\u6709\u7684AI\u5927\u6a21\u578b\u7684\u63a5\u5165\uff0c\u6216\u8005\u5c06\u4e91\u518d\u63a5\u5165\u5176\u4ed6\u7b2c\u4e09\u65b9AI\u5927\u6a21\u578b\uff0c\u5b9e\u73b0\u66f4\u591aAI\u5927\u6a21\u578b\u7684\u63a5\u5165\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e50\u5929\u6d3e\u673a\u5668\u4eba\u624b\u673aAPP\u7aef\u914d\u7f6e\u65b9\u5f0f\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/h3>\n\n\n\n<p>\u5f53\u4f60\u5efa\u7acb\u4e86\u79c1\u6709\u4e91\u540e\uff0c\u9700\u8981\u8fdb\u5165\u5230 \u4e50\u5929\u6d3eApp\uff0c\u8bbe\u5907- AI\u8bed\u97f3\u5f15\u64ce &#8211; \u7b2c\u4e09\u65b9\uff0c\u8fdb\u5165\u914d\u7f6e\u79c1\u6709\u4e91\u7684\u5927\u6a21\u578b\u4fe1\u606f\uff0c\u5c06 \u201c\u8bbe\u7f6e\u4e3a\u8bed\u97f3\u5f15\u64ce\u201d \u52fe\u9009\u4e0a\uff0c\u8bed\u97f3\u8ddf\u673a\u5668\u4eba\u5bf9\u8bdd\u65f6\uff0c\u9664\u4e86\u673a\u5668\u4eba\u57fa\u7840\u63a7\u5236\u8bed\u53e5\uff0c\u5176\u4ed6\u8bed\u97f3\u5c06\u4f1a\u9ed8\u8ba4\u8fdb\u5165\u7b2c\u4e09\u65b9\u79c1\u6709\u5316\u5927\u6a21\u578b\u63a5\u53e3\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1042\" height=\"1346\" src=\"https:\/\/cn.letianpai.com\/wp-content\/uploads\/2023\/12\/101.png\" alt=\"\" class=\"wp-image-6833\" srcset=\"https:\/\/cn.letianpai.com\/wp-content\/uploads\/2023\/12\/101.png 1042w, https:\/\/cn.letianpai.com\/wp-content\/uploads\/2023\/12\/101-464x600.png 464w, https:\/\/cn.letianpai.com\/wp-content\/uploads\/2023\/12\/101-768x992.png 768w\" sizes=\"auto, (max-width: 1042px) 100vw, 1042px\" \/><\/figure>\n\n\n\n<p>\u6ce8\uff1a\u56fe\u4e2dBaseUrl\uff08\u79c1\u6709\u5316\u5927\u6a21\u578b\u63a5\u53e3\u5730\u5740\uff09\u9700\u8981\u652f\u6301\u516c\u7f51\u53ef\u8bbf\u95ee<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e0b\u9762\u8bf4\u660e\u4e0b\u79c1\u6709\u5316\u5927\u6a21\u578b\u63a5\u53e3\u7684\u8c03\u7528\u7ea6\u5b9a\uff1a<\/h2>\n\n\n\n<p>\u6ce8\uff1a\u63a5\u53e3\u91c7\u7528SSE(Server-Sent Events) \u7684\u6d41\u5f0f\u8bf7\u6c42<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u8bf7\u6c42\u65b9\u6cd5<\/h3>\n\n\n\n<p>POST<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8bf7\u6c42content-Type<\/h3>\n\n\n\n<p>application\/json<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u8bf7\u6c42body\u4e3ajson\u683c\u5f0f\uff0c\u53c2\u6570\u5982\u4e0b<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>\u53c2\u6570\u540d<\/strong><\/td><td><strong>\u7c7b\u578b<\/strong><\/td><td><strong>\u63cf\u8ff0<\/strong><\/td><\/tr><tr><td>app_id<\/td><td>string<\/td><td>App\u4e2d\u914d\u7f6e\u7684app_id<\/td><\/tr><tr><td>api_key<\/td><td>string<\/td><td>App\u4e2d\u914d\u7f6e\u7684api_key<\/td><\/tr><tr><td>api_secret<\/td><td>string<\/td><td>App\u4e2d\u914d\u7f6e\u7684api_secret<\/td><\/tr><tr><td>content<\/td><td>string<\/td><td>\u8bf7\u6c42\u7684\u95ee\u9898\u5185\u5bb9<\/td><\/tr><tr><td>sn<\/td><td>string<\/td><td>\u5f53\u524d\u8bbe\u5907\u7684\u552f\u4e00\u6807\u8bb0sn<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8bf7\u6c42body\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n    \"app_id\":\"123\",\n    \"api_key\":\"236\",\n    \"api_secret\":\"234\",\n    \"content\":\"\u5982\u4f55\u6210\u4e3a\u4e00\u4e2a\u4ea7\u54c1\u7ecf\u7406\",\n    \"sn\":\"20010136U0100\"\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u8fd4\u56de\u6570\u636e\u683c\u5f0f\u7ea6\u5b9a\uff1a<\/h3>\n\n\n\n<p>event \u4e3a\u56fa\u5b9a\u7684 message<\/p>\n\n\n\n<p>data \u4e3ajson\u683c\u5f0f\u5b57\u7b26\u4e32<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">data\u4e2d\u7684json\u683c\u5f0f\u5982\u4e0b\uff1a<\/h4>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>\u5b57\u6bb5\u540d<\/strong><\/td><td><strong>\u7c7b\u578b<\/strong><\/td><td><strong>\u63cf\u8ff0<\/strong><\/td><\/tr><tr><td>code<\/td><td>int<\/td><td>\u8fd4\u56decode\u7801\uff0c0\u4ee3\u8868\u6b63\u5e38\uff0c\u5176\u4ed6\u975e0\u503c\u5747\u4ee3\u8868\u5931\u8d25<\/td><\/tr><tr><td>msg<\/td><td>string<\/td><td>\u8bf7\u6c42\u8fd4\u56de\u4fe1\u606f\uff0c\u8fd4\u56de\u5931\u8d25\u65f6\u5c06\u62a5\u9519\u4fe1\u606f\u653e\u5230msg\u91cc\u9762\uff0c\u673a\u5668\u4eba\u4f1a\u5c06\u6b64\u9519\u8bef\u64ad\u62a5\u51fa\u6765<\/td><\/tr><tr><td>data<\/td><td>object<\/td><td>\u5b9e\u4f53\u5185\u5bb9, \u89c1\u4e0b\u65b9\u8868\u683c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>json\u4e2d\u7684data \u5b9e\u4f53\u5185\u5bb9\u7684\u7ed3\u6784\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>\u5b57\u6bb5\u540d<\/strong><\/td><td><strong>\u7c7b\u578b<\/strong><\/td><td><strong>\u63cf\u8ff0<\/strong><\/td><\/tr><tr><td>content<\/td><td>string<\/td><td>\u79c1\u6709\u5927\u6a21\u578b\u8fd4\u56de\u7684\u56de\u7b54\u6587\u672c\uff0c\u53ef\u80fd\u662f\u4e00\u90e8\u5206<\/td><\/tr><tr><td>is_end<\/td><td>bool<\/td><td>false \u4ee3\u8868\u672a\u7ed3\u675f\uff0ctrue \u4ee3\u8868\u7ed3\u675f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8fd4\u56de\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>event: message\ndata: {\"code\":0,\"msg\":\"success\",\"data\":{\"content\":\"\u6211\u662f\",\"is_end\":false}}\n\nevent: message\ndata: {\"code\":0,\"msg\":\"success\",\"data\":{\"content\":\"\u4e50\u5929\u6d3e\u516c\u53f8\",\"is_end\":false}}\n\nevent: message\ndata: {\"code\":0,\"msg\":\"success\",\"data\":{\"content\":\"\u7814\u53d1\u7684\",\"is_end\":false}}\n\nevent: message\ndata: {\"code\":0,\"msg\":\"success\",\"data\":{\"content\":\"\u79c1\u6709\u5316\",\"is_end\":false}}\n\nevent: message\ndata: {\"code\":0,\"msg\":\"success\",\"data\":{\"content\":\"\u5927\u6a21\u578b\",\"is_end\":true}}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. demo sdk\u5982\u4e0b\uff1a<\/h3>\n\n\n\n<p>\u76ee\u524d\u53ea\u63d0\u4f9b\u4e86golang\u7684\u7248\u672c\uff0c\u5176\u4ed6\u7248\u672c\u7a0d\u540e\u63d0\u4f9b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>package main\n\nimport (\n\t\"encoding\/json\"\n\t\"fmt\"\n\t\"io\"\n\t\"io\/ioutil\"\n\t\"net\/http\"\n\t\"strings\"\n\t\"time\"\n)\n\ntype Req struct {\n\tAppId     string `json:\"app_id\"`     \/\/ \u914d\u7f6e\u7684appid\n\tApiKey    string `json:\"api_key\"`    \/\/ \u914d\u7f6e\u7684apikey\n\tApiSecret string `json:\"api_secret\"` \/\/ \u914d\u7f6e\u7684apisecret\n\tContent   string `json:\"content\"`    \/\/ \u8bf7\u6c42\u5927\u6a21\u578b\u7684\u6587\u5b57\n\tSn        string `json:\"sn\"`         \/\/ \u673a\u5668\u552f\u4e00\u7801\n}\n\ntype Data struct {\n\tContent string `json:\"content\"` \/\/ \u8fd4\u56de\u6587\u5b57\u5185\u5bb9\n\tIsEnd   bool   `json:\"is_end\"`  \/\/ \u662f\u5426\u7ed3\u675f\n}\n\ntype RespData struct {\n\tCode int    `json:\"code\"` \/\/ \u72b6\u6001\u7801\n\tMsg  string `json:\"msg\"`  \/\/ \u8fd4\u56de\u63d0\u793a\u4fe1\u606f\n\tData *Data  `json:\"data\"` \/\/ \u8fd4\u56de\u7684\u7ed3\u6784\u6570\u636e\n}\n\nfunc getSendMsg(code int, msg, content string, isEnd bool) (string, error) {\n\td := &amp;Data{\n\t\tContent: content,\n\t\tIsEnd:   isEnd,\n\t}\n\trespD := &amp;RespData{\n\t\tCode: code,\n\t\tMsg:  msg,\n\t\tData: d,\n\t}\n\trespB, err := json.Marshal(respD)\n\treturn string(respB), err\n}\n\nvar answerListAll = &#91;]&#91;]string{\n\t&#91;]string{\n\t\t\"\u6211\u662f\",\n\t\t\"\u4e50\u5929\u6d3e\u516c\u53f8\",\n\t\t\"\u7814\u53d1\u7684\",\n\t\t\"\u79c1\u6709\u5316\",\n\t\t\"\u5927\u6a21\u578b\",\n\t},\n\t&#91;]string{\n\t\t\"\u6211\u4e0d\u77e5\u9053\",\n\t\t\"\u4f60\u8bf4\u7684\",\n\t\t\"\u662f\u4ec0\u4e48\uff0c\",\n\t\t\"\u6211\u53ea\u662f\u4e00\u4e2a\",\n\t\t\"\u79c1\u6709\u5316\u5927\u6a21\u578b\",\n\t},\n\t&#91;]string{\n\t\t\"\u6c81\u56ed\u6625\u00b7\u96ea\",\n\t\t\"\u3010\u4f5c\u8005\u3011\u6bdb\u6cfd\u4e1c \",\n\t\t\"\u5317\u56fd\u98ce\u5149\uff0c\u5343\u91cc\u51b0\u5c01\uff0c\u4e07\u91cc\u96ea\u98d8\u3002\",\n\t\t\"\u671b\u957f\u57ce\u5185\u5916\uff0c\u60df\u4f59\u83bd\u83bd\uff1b\u5927\u6cb3\u4e0a\u4e0b\uff0c\u987f\u5931\u6ed4\u6ed4\u3002\",\n\t\t\"\u5c71\u821e\u94f6\u86c7\uff0c\u539f\u9a70\u8721\u8c61\uff0c\u6b32\u4e0e\u5929\u516c\u8bd5\u6bd4\u9ad8\u3002\",\n\t\t\"\u987b\u6674\u65e5\uff0c\u770b\u7ea2\u88c5\u7d20\u88f9\uff0c\u5206\u5916\u5996\u5a06\u3002\",\n\t\t\"\u6c5f\u5c71\u5982\u6b64\u591a\u5a07\uff0c\u5f15\u65e0\u6570\u82f1\u96c4\u7ade\u6298\u8170\u3002\",\n\t\t\"\u60dc\u79e6\u7687\u6c49\u6b66\uff0c\u7565\u8f93\u6587\u91c7\uff1b\u5510\u5b97\u5b8b\u7956\uff0c\u7a0d\u900a\u98ce\u9a9a\u3002\",\n\t\t\"\u4e00\u4ee3\u5929\u9a84\uff0c\u6210\u5409\u601d\u6c57\uff0c\u53ea\u8bc6\u5f2f\u5f13\u5c04\u5927\u96d5\u3002\",\n\t\t\"\u4ff1\u5f80\u77e3\uff0c\u6570\u98ce\u6d41\u4eba\u7269\uff0c\u8fd8\u770b\u4eca\u671d\u3002\",\n\t},\n\t&#91;]string{\n\t\t\"\u8981\u6210\u4e3a\u4e00\u4e2a\u4f18\u79c0\u7684\u4ea7\u54c1\u7ecf\u7406\uff0c\u5fc5\u987b\u5728\u5fc3\u91cc\u8981\u6709\u4e00\u4e2a\u201c\u5927\u6211\u201d\u548c\u4e00\u4e2a\u201c\u5c0f\u6211\u201d\uff0c\u53ef\u80fd\u4f60\u8981\u7ecf\u5386\u8fd9\u4e24\u4e2a\u8fc7\u7a0b\u7684\u78e8\u7ec3\uff0c\u624d\u80fd\u627e\u5230\u539f\u56e0\u80cc\u540e\u7684\u539f\u56e0\u3002\",\n\t\t\"\u4ec0\u4e48\u662f\u201c\u5927\u6211\u201d\uff1f\u6211\u7684\u610f\u601d\u662f\uff0c\u4e00\u4e2a\u4ea7\u54c1\u7ecf\u7406\u8981\u628a\u81ea\u5df1\u5f53\u6210CEO\u3002\u5728\u300a\u5144\u5f1f\u8fde\u300b\u91cc\u9762\u7684\u8fde\u957f\u7684\u7ef0\u53f7\u5c31\u662fCEO\u3002\",\n\t\t\"\u4ea7\u54c1\u7ecf\u7406\u8981\u5bf9\u4e00\u4e2a\u4ea7\u54c1\u8d1f\u8d23\uff0c\u867d\u7136\u6302\u7684\u662f\u7ecf\u7406\u7684\u5934\u8854\uff0c\u4f46\u884c\u9a76\u7684\u662f\u603b\u7ecf\u7406\u7684\u804c\u8d23\u3002\",\n\t\t\"\u56e0\u4e3a\u8981\u5bf9\u4ea7\u54c1\u8d1f\u8d23\uff0c\u4ea7\u54c1\u7ecf\u7406\u8fd8\u8981\u7ecf\u5e38\u53bb\u534f\u8c03\u5f88\u591a\u90e8\u95e8\uff0c\u8981\u53bb\u63a8\u52a8\u5f88\u591a\u4e0d\u5f52\u4ed6\u7ba1\u7684\u4eba\u548c\u4e8b\uff0c\u6bd4\u5982\u8981\u8ddf\u8bbe\u8ba1\u6253\u4ea4\u9053\uff0c\u8981\u8ddf\u6280\u672f\u6253\u4ea4\u9053\uff0c\u8981\u8ddf\u6d4b\u8bd5\u6253\u4ea4\u9053\uff0c\u8fd8\u8981\u53bb\u4e86\u89e3\u7528\u6237\u7684\u60f3\u6cd5\uff0c\u8fd8\u8981\u53bb\u8ddf\u5e02\u573a\u8c08\u652f\u6301\u3002\",\n\t\t\"\u4ea7\u54c1\u7ecf\u7406\u8981\u64cd\u7684\u5fc3\uff0c\u4e00\u70b9\u4e5f\u4e0d\u6bd4\u4e00\u4e2a\u603b\u7ecf\u7406\u5c11\u3002\u6240\u4ee5\uff0c\u6211\u8bf4\u4e00\u4e2a\u4f18\u79c0\u7684\u4ea7\u54c1\u7ecf\u7406\u9996\u5148\u8981\u628a\u81ea\u5df1\u5f53\u6210\u4e00\u4e2aCEO\uff0c\u65e2\u8981\u8d1f\u8d23\u6267\u884c\u3001\u63a8\u52a8\uff08Executive\uff09\uff0c\u4e5f\u8981\u8d1f\u8d23\u7528\u6237\u4f53\u9a8c\uff08Experience\uff09\u3002\u53ef\u80fd\u522b\u4eba\u4e0d\u62ff\",\n\t\t\"\u4f60\u5f53\u56de\u4e8b\uff0c\u4f46\u4f60\u81ea\u5df1\u5fc3\u91cc\u7684\u6709\u4e00\u4e2a\u201c\u5927\u6211\u201d\u3002\u4f60\u5bf9\u4e00\u4e2a\u4ea7\u54c1\u8d1f\u8d23\uff0c\u4f60\u7684title\u4e0d\u91cd\u8981\uff0c\u4f46\u662f\u4f60\u4e00\u5b9a\u8981\u628a\u8fd9\u4e2a\u8d23\u4efb\u62c5\u8d1f\u8d77\u6765\u3002\",\n\t\t\"\u6240\u4ee5\uff0c\u4f18\u79c0\u7684\u4ea7\u54c1\u7ecf\u7406\u4e0d\u5fc5\u5728\u610f\u4eca\u5929\u7ba1\u4e86\u591a\u5c11\u4eba\uff0c\u4e0d\u5fc5\u5728\u610f\u81ea\u5df1\u7684\u5934\u8854\u662f\u9ad8\u662f\u4f4e\uff0c\u5173\u952e\u6700\u662f\u4f60\u80fd\u4e0d\u80fd\u5229\u7528\u516c\u53f8\u91cc\u7684\u8d44\u6e90\uff0c\u4e0d\u7ba1\u91c7\u7528\u4ec0\u4e48\u624b\u6bb5\uff0c\u6700\u540e\u505a\u51fa\u6765\u4e00\u4e2a\u597d\u4ea7\u54c1\u3002\",\n\t\t\"\u4e0a\u4ebf\u7684\u7528\u6237\u9009\u62e9\u4f7f\u7528\u4f60\u505a\u51fa\u6765\u7684\u4ea7\u54c1\uff0c\u5c31\u662f\u5bf9\u4ea7\u54c1\u7ecf\u7406\u6700\u5927\u7684\u8ba4\u53ef\u3002\",\n\t\t\"\u5728\u5176\u4ed6\u76f8\u540c\u7684\u6761\u4ef6\u4e0b\uff0c\u4f60\u505a\u7684\u4ea7\u54c1\u6709\u4e0a\u4ebf\u7528\u6237\u7528\uff0c\u4ed6\u505a\u7684\u4ea7\u54c1\u53ea\u6709\u51e0\u767e\u4e07\u4eba\u7528\uff0c\u90a3\u4e48\u4f60\u5c31\u6bd4\u4ed6\u8981\u4f18\u79c0\u3002\",\n\t\t\"\u53ef\u80fd\u4f60\u4f1a\u8bf4\uff0c\u6211\u662f\u60f3\u505a\u4e00\u4e2a\u4f18\u79c0\u7684\u4ea7\u54c1\u7ecf\u7406\uff0c\u4f46\u6211\u592a\u5e74\u8f7b\uff0c\u6ca1\u4ec0\u4e48\u8d44\u5386\u3002\u6211\u89c9\u5f97\uff0c\u4ea7\u54c1\u7ecf\u7406\u8981\u975e\u5e38\u81ea\u4fe1\uff0c\u4f60\u8981\u6709\u8fd9\u79cd\u6c14\u52bf\u3002\",\n\t\t\"\u4e00\u4e2a\u4f18\u79c0\u7684\u4ea7\u54c1\u7ecf\u7406\u5fc3\u4e2d\u6709\u201c\u5927\u6211\u201d\uff0c\u4f46\u540c\u65f6\u8fd8\u5f97\u4e0d\u65ad\u5730\u201c\u5c0f\u6211\u201d\uff0c\u751a\u81f3\u8981\u201c\u5fd8\u6211\u201d\u3002\u8fd9\u5c31\u662f\u8bf4\uff0c\",\n\t\t\"\u4ea7\u54c1\u7ecf\u7406\u8981\u5fd8\u6389\u81ea\u5df1\u3002\u6839\u636e\u6211\u7684\u7ecf\u9a8c\uff0c\u4ea7\u54c1\u7ecf\u7406\u6700\u5bb9\u6613\u72af\u7684\u51e0\u4e2a\u9519\u8bef\uff0c\u5305\u62ec\u4eca\u5929\u6211\u90fd\u8fd8\u5728\u72af\uff0c\u5c31\u662f\u4ea7\u54c1\u505a\u7740\u505a\u7740\uff0c\u5c31\u4e0d\u662f\u7ed9\u7528\u6237\u505a\u4ea7\u54c1\uff0c\u800c\u662f\u7ed9\u81ea\u5df1\u505a\u4ea7\u54c1\uff0c\u7ed9\u540c\u4e8b\u505a\u4ea7\u54c1\uff0c\u7ed9\u9886\u5bfc\u505a\u4ea7\u54c1\u4e86\u3002\",\n\t\t\"\u6240\u4ee5\uff0c\u4ea7\u54c1\u7ecf\u7406\u5fc3\u4e2d\u8981\u505a\u5230\u201c\u5c0f\u6211\u201d\uff0c\u751a\u81f3\u201c\u5fd8\u6211\u201d\uff0c\u5c31\u662f\u4ea7\u54c1\u7ecf\u7406\u5fc5\u987b\u8eab\u4e34\u5176\u5883\uff0c\u628a\u81ea\u5df1\u5f53\u6210\u4e00\u4e2a\u5178\u578b\u7528\u6237\uff0c\u8ba9\u81ea\u5df1\u7cbe\u795e\u5206\u88c2\uff0c\u8fd9\u6837\u624d\u80fd\u4f53\u4f1a\u7528\u6237\u5fc3\u4e2d\u771f\u6b63\u7684\u60f3\u6cd5\u548c\u9700\u6c42\u3002\",\n\t},\n}\n\nfunc handleSSE(w http.ResponseWriter, r *http.Request) {\n\t\/\/ \u8bbe\u7f6e\u54cd\u5e94\u5934\uff0c\u6307\u5b9aSSE\u7684Content-Type\n\tw.Header().Set(\"Content-Type\", \"text\/event-stream\")\n\tw.Header().Set(\"Cache-Control\", \"no-cache\")\n\tw.Header().Set(\"Connection\", \"keep-alive\")\n\n\t\/\/ \u8bfb\u53d6body\n\tbody, err := ioutil.ReadAll(r.Body)\n\tif err != nil {\n\t\thttp.Error(w, \"Error reading request body\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\t\/\/ \u5904\u7406body\n\tfmt.Printf(\"\u6536\u5230\u8bf7\u6c42\u7684body\u6570\u636e\uff1a%s\\n\", body)\n\tvar reqB Req\n\terr = json.Unmarshal(body, &amp;reqB)\n\tfmt.Println(\"reqB:\", reqB)\n\tanswerList := answerListAll&#91;0]\n\tcontent := reqB.Content\n\n\tfmt.Println(\"content:\", content)\n\n\t\/\/ \u6a21\u62df\u5927\u6a21\u578b\u5339\u914d\u7b54\u6848\n\tif strings.Contains(content, \"\u662f\u8c01\") || strings.Contains(content, \"\u5927\u6a21\u578b\") {\n\t\tanswerList = answerListAll&#91;0]\n\t} else if strings.Contains(content, \"\u56ed\u6625\") {\n\t\tanswerList = answerListAll&#91;2]\n\t} else if strings.Contains(content, \"\u4ea7\u54c1\u7ecf\u7406\") {\n\t\tanswerList = answerListAll&#91;3]\n\t} else {\n\t\tanswerList = answerListAll&#91;1]\n\t}\n\n\t\/\/ \u6a21\u62df\u5b9e\u65f6\u6570\u636e\u63a8\u9001\n\tfor idx, partAnswer := range answerList {\n\t\tisEnd := false\n\t\tif idx == len(answerList)-1 {\n\t\t\tisEnd = true\n\t\t}\n\t\trespStr, err := getSendMsg(0, \"success\", partAnswer, isEnd)\n\t\tif err != nil {\n\t\t\trespStr, _ = getSendMsg(1, \"\u83b7\u53d6\u8fd4\u56de\u4fe1\u606f\u51fa\u9519\", \"\", true)\n\t\t}\n\n\t\tSendEventMessage(w, \"message\", respStr)\n\t\t\/\/ \u6a21\u62df\u52a0\u7684\u5ef6\u65f6\uff0c\u771f\u5b9e\u8c03\u7528\u8981\u53bb\u6389\n\t\ttime.Sleep(500 * time.Millisecond)\n\t}\n}\n\n\/\/ \u53d1\u9001\u4e8b\u4ef6\u6d88\u606f\nfunc SendEventMessage(w http.ResponseWriter, eventType, eventData string) {\n\t\/\/ \u6784\u9020 Event Source \u683c\u5f0f\u7684\u6d88\u606f\n\tmessage := \"event: \" + eventType + \"\\n\"\n\tmessage += \"data: \" + eventData + \"\\n\\n\"\n\tfmt.Println(message)\n\t\/\/ \u5c06\u6d88\u606f\u5199\u5165\u54cd\u5e94\u4e3b\u4f53\n\t_, err := io.WriteString(w, message)\n\tif err != nil {\n\t\t\/\/ \u53d1\u751f\u9519\u8bef\uff0c\u505c\u6b62\u53d1\u9001\u6d88\u606f\n\t\treturn\n\t}\n\n\t\/\/ \u5237\u65b0\u54cd\u5e94\u4e3b\u4f53\uff0c\u786e\u4fdd\u6570\u636e\u88ab\u53d1\u9001\n\tflusher, ok := w.(http.Flusher)\n\tif ok {\n\t\tflusher.Flush()\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"\/sse\", handleSSE)\n\n\t\/\/ \u542f\u52a8Web\u670d\u52a1\uff0c\u76d1\u542c\u5728 localhost:8012\n\tfmt.Println(\"\u670d\u52a1\u6b63\u5728\u76d1\u542c: http:\/\/127.0.0.1:8012\")\n\tif err := http.ListenAndServe(\":8012\", nil); err != nil {\n\t\tfmt.Println(\"Error starting server:\", err)\n\t}\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e50\u5929\u6d3e\u684c\u9762\u673a\u5668\u4eba\u652f\u6301\u63a5\u5165\u4efb\u610f\u7b2c\u4e09\u65b9AI\u5927\u6a21\u578b\uff0c\u6216\u8005\u63a5\u5165\u4efb\u610f\u79c1\u6709\u5316AI\u5927\u6a21\u578b\uff0c\u7528\u6237\u9700\u8981\u642d\u5efa\u4e00\u4e2a\u81ea\u5df1\u7684\u4e91\u7aef\u670d\u52a1\u5668\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9423,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[],"class_list":["post-6832","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-robot_tips-zh"],"_links":{"self":[{"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/posts\/6832","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6832"}],"version-history":[{"count":8,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/posts\/6832\/revisions"}],"predecessor-version":[{"id":10425,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/posts\/6832\/revisions\/10425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=\/wp\/v2\/media\/9423"}],"wp:attachment":[{"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.letianpai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}