Skip to content

演算法 (Algorithm)

建立演算法 (/create-algorithm)

使用範例

建立一個 G1 類別的演算法,呼叫API:

curl --request POST 'https://api.raas.kklab.com/create-algorithm' \
--header 'Authorization: Bearer $TOKEN' \
--header 'APIKey: $API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "project_id": "$PROJECT_ID",
    "name": "example-G1-algorithm",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}'
import json
import requests
from pprint import pprint

headers = create_headers(scopes=["/create-algorithm"])

url = "https://api.raas.kklab.com/create-algorithm"

data={
    "project_id": "$PROJECT_ID",
    "name": "example-G1-algorithm",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}

response = requests.request("POST", url, headers=headers, data=json.dumps(data))

pprint(response.json())

回傳值:

{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "example-G1-algorithm",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}

欄位說明

  • name: 演算法名稱,僅供開發者辨識使用,無其他用途。
  • algorithm_type: 演算法類別
  • algorithm_parameters: 選取演算法類別之演算法參數,依演算法同有所不同。所有演算法參數皆為非必要欄位,若不填選系統會自行調整合適的值或使用預設值。

修改演算法設定 (/update-algorithm)

使用範例

呼叫API:

curl --request PUT 'https://api.raas.kklab.com/update-algorithm' \
--header 'Authorization: Bearer $TOKEN' \
--header 'APIKey: $API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "new algorithm name"
}'
import json
import requests
from pprint import pprint

headers = create_headers(scopes=["/update-algorithm"])

url = "https://api.raas.kklab.com/update-algorithm"

data={
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "new algorithm name"
}

response = requests.request("PUT", url, headers=headers, data=json.dumps(data))

pprint(response.json())

回傳值:

{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "new algorithm name",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}

可修改欄位

  • name
  • algorithm_type
  • algorithm_parameters

取得單一演算法設定 (/get-algorithm)

使用範例

呼叫API:

curl --request GET 'https://api.raas.kklab.com/get-algorithm?project_id=$PROJECT_ID&algorithm_id=$ALGORITHM_ID' \
--header 'Authorization: Bearer $TOKEN' \
--header 'APIKey: $API_KEY'
import requests
from pprint import pprint

headers = create_headers(scopes=["/get-algorithm"])

url = "https://api.raas.kklab.com/get-algorithm"

params = {
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID"
}

response = requests.request("GET", url, headers=headers, params=params)

pprint(response.json())

回傳值:

{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "example-G1-algorithm",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}

列出所有演算法 (/list-algorithms)

使用範例

呼叫API:

curl --request GET 'https://api.raas.kklab.com/list-algorithms?project_id=$PROJECT_ID' \
--header 'Authorization: Bearer $TOKEN' \
--header 'APIKey: $API_KEY'
import requests
from pprint import pprint

headers = create_headers(scopes=["/list-algorithms"])

url = "https://api.raas.kklab.com/list-algorithms"

params = {
    "project_id": "$PROJECT_ID"
}

response = requests.request("GET", url, headers=headers, params=params)

pprint(response.json())

回傳值:

{
    "algorithms": [
        {
            "project_id": "$PROJECT_ID",
            "algorithm_id": "$ALGORITHM_ID",
            "name": "example-G1-algorithm",
            "algorithm_type": "G1",
            "algorithm_parameters": {}
        }
    ]
}

刪除演算法 (/delete-algorithm)

使用範例

呼叫API:

curl --request DELETE 'https://api.raas.kklab.com/delete-algorithm' \
--header 'Authorization: Bearer $TOKEN' \
--header 'APIKey: $API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID"
}'
import json
import requests
from pprint import pprint

headers = create_headers(scopes=["/delete-algorithm"])

url = "https://api.raas.kklab.com/delete-algorithm"

data={
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID"
}

response = requests.request("DELETE", url, headers=headers, data=json.dumps(data))

pprint(response.json())

回傳值:

{
    "project_id": "$PROJECT_ID",
    "algorithm_id": "$ALGORITHM_ID",
    "name": "example-G1-algorithm",
    "algorithm_type": "G1",
    "algorithm_parameters": {}
}

API回傳該演算法被刪除前的最後設定。