---
# System prepended metadata

title: RaiAiChatBot Api

---

# RaiAiChatBot Api


## Table of Contents

[TOC]

伺服器位置：http://chatbot.intemotech.com:5000/
## 時序圖
```sequence
縣政府->管理後台:輸入題庫
管理後台->管理後台:一段時間自動訓練或手動訓練


```
## API
### 開始訓練
路由 
```
list/train
```
Method 
```
GET
```
Query String
```

```
Response
成功執行
```
{
  "status": "開始訓練"
}
```
上個訓練尚未完成
```
{
  "status": "已有任務執行中請稍候"
}
```
cURL
```
curl -X GET \
  http://127.0.1:5000/list/train 
```


### 查詢計算狀態
路由 
```
list/trainstatus
```
Method 
```
GET
```
Query String
```

```
Response
無計算中資料
```
{
  "status": "已停止"
}
```
計算進度
```
{
  "status": "training:0/20"
}
```
cURL
```
curl -X GET \
  http://127.0.1:5000/list/trainstatus
```


### 輸入分詞題庫
路由 
```
list/words
```
Method 
```
POST
```
Query String
```
{
  "1": {
    "qarray": [
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？",
      "私人土地可以設立墓碑嗎?",
      "埋葬遺體一定要在公墓裡?",
      "私人土地可以當作墳墓使用嗎?"
    ],
    "ans": [
      "私人土地問題回答改1",
      "私人土地問題回答改2"
    ],
    "relatedQarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "殯葬設施之申請設置及管理機關為何?"
    ]
  },
  "2": {
    "qarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "埋葬遺體要跟誰申請?",
      "存放骨灰要跟誰申請?",
      "變更墓地要和誰申請?"
    ],
    "relatedQarray": [
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？",
      "殯葬設施之申請設置及管理機關為何?"
    ],
    "ans": [
      "埋葬問題回答1",
      "埋葬問題回答2"
    ]
  },
  "3": {
    "qarray": [
      "殯葬設施之設置及管理機關為何?",
      "設立殯葬設施要找誰?",
      "殯葬設施建置要跟誰申請?",
      "殯葬設施的管理機關是誰?"
    ],
    "relatedQarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？"
    ],
    "ans": [
      "殯葬設施之設置問題1",
      "殯葬設施之設置問題2"
    ]
  }
}
```
Response
上傳成功
```
{
  "status": "上傳成功"
}
```
若資料少於3筆
```
{
  "status": "資料不足"
}
```
cURL
```
curl -X POST \
  http://0.0.0.0:5000/list/words \
  -H 'Accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "1": {
    "qarray": [
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？",
      "私人土地可以設立墓碑嗎?",
      "埋葬遺體一定要在公墓裡?",
      "私人土地可以當作墳墓使用嗎?"
    ],
    "ans": [
      "私人土地問題回答改1",
      "私人土地問題回答改2"
    ],
    "relatedQarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "殯葬設施之申請設置及管理機關為何?"
    ]
  },
  "2": {
    "qarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "埋葬遺體要跟誰申請?",
      "存放骨灰要跟誰申請?",
      "變更墓地要和誰申請?"
    ],
    "relatedQarray": [
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？",
      "殯葬設施之申請設置及管理機關為何?"
    ],
    "ans": [
      "埋葬問題回答1",
      "埋葬問題回答2"
    ]
  },
  "3": {
    "qarray": [
      "殯葬設施之設置及管理機關為何?",
      "設立殯葬設施要找誰?",
      "殯葬設施建置要跟誰申請?",
      "殯葬設施的管理機關是誰?"
    ],
    "relatedQarray": [
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？"
    ],
    "ans": [
      "殯葬設施之設置問題1",
      "殯葬設施之設置問題2"
    ]
  }
}'
```



### 取得答案推論結果
路由 
```
questionnaire
```
Method 
```
POST
```
Query String
```
q:辦理身分證注意事項
```
Response
判斷結果
```
{
  "fuzzywuzzyarray": [
    [
      "0.91",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬遺體一定要在公墓裡?",
      "埋 葬 遺 體 一 定 要 在 公 墓 裡"
    ],
    [
      "0.62",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬遺體要跟誰申請?",
      "埋 葬 遺 體 要 跟 誰 申 請"
    ],
    [
      "0.52",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "殯葬設施建置要跟誰申請?",
      "殯 葬 設 施 建 置 要 跟 誰 申 請"
    ]
  ],
  "siameseLstm": [
    [
      "0.99273294",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬遺體一定要在公墓裡?",
      "埋 葬 遺 體 一 定 要 在 公 墓 裡"
    ],
    [
      "0.80715936",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "私人土地可以設立墓碑嗎?",
      "私 人 土 地 可 以 設 立 墓 碑 嗎"
    ],
    [
      "0.7999788",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
      "埋 葬 及 起 掘 屍 體 或 骨 灰 骸 需 向 何 機 關 申 請"
    ]
  ],
  "subArr": [
    [
      "0.9513664710521699",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬遺體一定要在公墓裡?",
      "埋 葬 遺 體 一 定 要 在 公 墓 裡"
    ],
    [
      "0.696695683002472",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "埋葬遺體要跟誰申請?",
      "埋 葬 遺 體 要 跟 誰 申 請"
    ],
    [
      "0.6438355541229248",
      "申 請 埋 葬 遺 體 一 定 要 在 公 墓 裡",
      "殯葬設施建置要跟誰申請?",
      "殯 葬 設 施 建 置 要 跟 誰 申 請"
    ]
  ]
}
```

cURL
```
curl -X POST \
  http://0.0.0.0:5000/questionnaire \
  -F 'q=辦理身分證注意事項'
```


### 取得答案
路由 
```
questionnairetoans
```
Method 
```
POST
```
Query String
```
q:辦理身分證注意事項
```
Response
判斷結果
回答答案
```
{
  "credibility": 1.0,
  "data": "私人土地問題回答改1",
  "type": 0,
  "ori_ques":"辦理身分證注意事項"
}
```
回答可能的問題
```
{
  "credibility": 0.6897028589248657,
  "data": [
    "私人土地可以設立墓碑嗎?",
    "私人土地可以當作墳墓使用嗎?",
    "埋葬遺體一定要在公墓裡?",
    "殯葬設施建置要跟誰申請?",
    "埋葬及起掘屍體或骨灰(骸)，需向何機關申請？",
    "殯葬設施之設置及管理機關為何?",
    "埋葬遺體要跟誰申請?",
    "存放骨灰要跟誰申請?",
    "變更墓地要和誰申請?",
    "殯葬設施的管理機關是誰?",
    "私人土地得否施設墳墓埋葬屍體或骨灰(骸)？",
    "設立殯葬設施要找誰?"
  ],
  "type": 1
}
```
無法回答狀況
```
{
  "credibility": 0.07081429772078991,
  "type": 2
}
```

cURL
```
curl -X POST \
  http://0.0.0.0:5000/questionnairetoans \
  -F 'q=辦理身分證注意事項'
```
## 英文版
### 輸入分詞題庫
路由 
```
setQA
```
Method 
```
POST
```
Query String
```
{
"searchKey":"en",
  "Question": [
          "How can we get ferry tickets for Sun Moon Lake?",
          "How do I book the ticket for the Sun Moon Lake cruise?",
  ],
  "Answer": [
  "Currently we have diesel boats and electric boats at Sun Moon Lake. Buying tickets on-site and reservation for charter are both available depending on your needs. Every yacht fleet has a ticket booth at Shuishe Pier and Ita Thao Pier. You may also contact Nantou Yacht Association at 049-2856428 for ticket information about touring on a yacht.===7jf89d8kd4ed8934890m0s9e2dk9054===",
        "Currently we have diesel boats and electric boats at Sun Moon Lake. Buying tickets on-site and reservation for charter are both available depending on your needs. Every yacht fleet has a ticket booth at Shuishe Pier and Ita Thao Pier. You may also contact Nantou Yacht Association at 049-2856428 for ticket information about touring on a yacht.===7jf89d8kd4ed8934890m0s9e2dk9054===",
  ],
}
```
Response
上傳成功
```
{
    "qaCount": 4,
    "searchKey": "abcde"
}
```




### 取得答案推論結果
路由 
```
getQA
```
Method 
```
POST
```
Query String
```
searchKey:en
Question:Where can I find local Taiwanese cuisines
```
Response
判斷結果
```
{
    "data": [
        {
            "Probability": 0.9894354939460754,
            "Question": "Where can I find local Taiwanese cuisines?",
            "Answer": "There are unique cuisines everywhere in Nantou. You can visit markets, night markets or even the food court on the second floor of Carrefour, for all kinds of local food.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9575924873352051,
            "Question": "Where can I get some traditional Taiwanese Xiaochi?",
            "Answer": "There are unique cuisines everywhere in Nantou. You can visit markets, night markets or even the food court on the second floor of Carrefour, for all kinds of local food.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.946019172668457,
            "Question": "Where can I find legal hotels and guesthouses?",
            "Answer": "You can visit <a href='https://taiwanstay.net.tw/' target='_blank'>https://taiwanstay.net.tw/</a>. All legally registered accommodations are listed on the website. If a place isn’t listed, it means it has not yet acquired the legal registration certificate.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9444514513015747,
            "Question": "Where can I find more information about Nantou City?",
            "Answer": "Well, you can get information online on www.nantou.gov.tw. There is English version online, which you will easily gain the information you need.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9396638870239258,
            "Question": "Where can I taste some of the local food?",
            "Answer": "There are unique cuisines everywhere in Nantou. You can visit markets, night markets or even the food court on the second floor of Carrefour, for all kinds of local food.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9391597509384155,
            "Question": "Where can I search for registered inns and B&Bs?",
            "Answer": "You can visit <a href='https://taiwanstay.net.tw/' target='_blank'>https://taiwanstay.net.tw/</a>. All legally registered accommodations are listed on the website. If a place isn’t listed, it means it has not yet acquired the legal registration certificate.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9390460848808289,
            "Question": "Where can I get information on available buses?",
            "Answer": "Highway Bus Information System\n<a href='https://www.taiwanbus.tw/' target='_blank'>https://www.taiwanbus.tw/</a>\n===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9379763007164001,
            "Question": "How can I get other information about Nantou County?",
            "Answer": "Well, you can get information online on www.nantou.gov.tw. There is English version online, which you will easily gain the information you need.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9379558563232422,
            "Question": "How can I obtain more info on Nantou County?",
            "Answer": "Well, you can get information online on www.nantou.gov.tw. There is English version online, which you will easily gain the information you need.===7jf89d8kd4ed8934890m0s9e2dk9054==="
        },
        {
            "Probability": 0.9376698136329651,
            "Question": "Where can I find a visitor center in Nantou?",
            "Answer": "Xiangshang Visitor Center\nAddress: No. 599, Zhongshan Rd., Shuishe Village, Yuchi Township, Nantou County\nTEL: 049-2341256\n\nChecheng Visitor Center\nAddress: No. 111, Minquan Lane, Checheng Village, Shuili Township, Nantou County\nTEL: 049-2774981\n\nIta Thao Visitor Center\nAddress: No. 127, Wenhua St., Riyue Village, Yuchi Township, Nantou County\nTEL: 049-2850289\n\nPuli Visitor Center\nAddress: No. 191, Section 4, Zhongshan Rd., Puli Township, Nantou County\nTEL: 049-2916060\n\nSongboling Visitor Center\nAddress: No. 181, Section 2, Mingsong Rd., Mingjian Township, Nantou County\nTEL: 049-2580525 ext. 0\n\nJhushan Visitor Center\nAddress: No. 1220, Section 3, Jishan Rd., Zhushan Township, Nantou County\nTEL: 049-2657668\n\nLugu Travel Service Center\nAddress: No. 128, Section 1, Zhongzheng Rd., Lugu Township, Nantou County\nTEL: 049-2755623\n1. Chinese, English and Japanese services: available 24/7/365. \n2. Vietnamese, Indonesian, Thai and Cambodian services: 9:00 to 17:00 Monday to Friday (unavailable on weekends, national holidays and other days off).\n===7jf89d8kd4ed8934890m0s9e2dk9054==="
        }
    ],
    "searchKey": "abcd",
    "type": 0
}
```
### 取出目前所有問題
路由 
```
getAllQ
```
Method 
```
POST
```
Query String
```
searchKey:en
```
Response
判斷結果
```
{
    "classes": [
        "Sun Moon Lake Albert, what’s your new roommate like?qqqqq",
        "He’s quite a character!",
        "How so",
        "aaa&bbb=ccc"
    ],
    "ansData": [
        "Albert, what’s your new roommate like?A",
        "He’s quite a character!Ans",
        "How soAns",
        "aaa&bbb=cccAns"
    ],
    "searchKey": "abcde"
}
```