HTTP

更新时间:
说明

需要使用您的API-KEY替换示例中的 your-api-key ,代码才能正常运行。

知识库创建

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/create' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-create' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "name": "知识库名称",
            "description": "知识库描述",
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-create"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/create"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "name": "知识库名称",
    "description": "知识库描述",
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库更新

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/update' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-update' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "name": "知识库名称",
            "description": "知识库描述",
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-update"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/update"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "name": "知识库名称",
    "description": "知识库描述",
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库查询

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/search' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-search' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "pageNum": 1,
            "pageSize": 10,
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-search"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/search"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "pageNum": 1,
    "pageSize": 10,
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库删除

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/delete' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-delete' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-delete"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/delete"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库文件详情上传

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/upload' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-detail-upload' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "type": "text",
            "fileInfos": [
                {
                    "filename": "文件名.txt",
                    "fileUrl": "公网可访问地址"				
                }
            ],
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-detail-upload"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/upload"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "type": "text",
    "userProfile": [
        {
            "filename": "文件名.txt",
            "fileUrl": "公网可访问地址"
        }
    ],
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库文件详情修改

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/update' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-detail-update' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "name": "现在使用的名称",
            "newName": "新的名称",
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-detail-update"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/update"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "name": "现在使用的名称",
    "newName": "新的名称",
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库文件详情搜索

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/search' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-detail-search' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "pageNum": 1,
            "pageSize": 10,
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-detail-search"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/search"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "pageNum": 1,
    "pageSize": 10,
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))

知识库文件详情删除

shell

curl --location 'https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/delete' \
--header 'Expect;' \
--header 'accept: */*' \
--header 'Content-Type: application/json' \
--header 'x-fag-servicename: aca-kb-detail-delete' \
--header 'x-fag-appcode: aca' \
--header 'Authorization: Bearer your-api-key' \
--data '{
            "knowledgeBaseId": "知识库id",
            "name": "知识库详情名称",
            "userProfile": {
                "userId": ""
            }
        }'

python

import json

import requests

api_key = "your-api-key"
service_name = "aca-kb-detail-delete"

url = "https://nlp.aliyuncs.com/v2/api/knowledge_base/detail/delete"
headers = {
    "Content-Type": "application/json",
    "x-fag-servicename": service_name,
    "x-fag-appcode": "aca",
    "Authorization": f"Bearer {api_key}"
}
payload = {
    "knowledgeBaseId": "知识库id",
    "name": "知识库详情名称",
    "userProfile": {
        "userId": ""
    }
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(json.loads(response.text))