
9 個用于英國、歐盟和全球驗證的增值稅 API
點擊跳轉 騰訊混元 官網,點擊“騰訊元器”,輸入手機號碼并通過驗證嗎登錄。
登錄成功后,點擊“創建智能體”
輸入要創建智能體的名稱、簡介、頭像(可以AI生成)、詳細設定等相關信息~
還可以添加豐富的插件、知識庫、工作流等~
每一項表單的編輯后,右邊會自動更新智能體的配置(預計有3-5s左右延遲),我們就可以即時查看智能體在配置更新后的效果~
調試沒有問題后就可以發布智能體,并等待審核成功~
如果使用API調用的方式,不需要選擇發布平臺
審核通過后,到我的創建中找到創建的智能體
在彈窗中復制自己的智能體ID和Token(注意不要泄露,泄露后要及時重置)
參數名 | 類型 | 是否必選 | 說明 |
assistant_id | string | 是 | 助手ID |
version | number | 否 | 助手版本 (僅對內部開放) |
user_id | string | 是 | 用戶ID,調用者業務側的用戶ID,會影響智能體的數據統計,建議按實際情況填寫 |
stream | bool | 否 | 是否以流式接口的形式返回數據,默認false |
chat_type | string | 否 | 默認為published,傳preview時,表示使用草稿態智能體 (僅對內部開放) |
messages | list | 是 | 會話內容, 長度最多為40, 按對話時間從舊到新在數組中排列 |
messages[n].role | string | 是 | 角色, ‘user’或者’assistant’, 在message中必須是user與assistant交替(一問一答) |
messages[n].content | list | 是 | 可以傳入多種類型的內容,如圖片、文件或文本 |
messages[n].content[m].type | string | 否 | 內容的類型,可選參數為’text’或’file_url’ |
messages[n].content[m].text | string | 否 | 當type為text時使用,表示具體的文本內容 |
messages[n].content[m].file_url | object | 否 | 當type為file_url時使用,表示具體的文件內容 |
messages[n].content[m].file_url.type | string | 否 | 文件的類型,例如image/video/audio/pdf/doc/txt等 |
messages[n].content[m].file_url.url | string | 否 | 文件的url |
返回格式application/json,body參數如下:
參數名 | 類型 | 說明 |
id | string | 此次請求的id |
created | number | unix時間戳 |
choices | list | 返回的回復, 當前僅有一個 |
choices[n].index | number | 第幾個回復 |
choices[n].finish_reason | string | “stop”表示正常結束,”sensitive”表示審核不通過”tool_fail”表示調用工具失敗 |
choices[n].message | json | 返回的內容 |
choices[n].message.role | string | 角色名稱 |
choices[n].message.content | string | 內容詳情 |
choices[n].message.steps | list | 助手的執行步驟 |
choices[n].message.steps[m].role | string | 執行步驟中的角色名稱,assistant表示模型,tool表示工具調用 |
choices[n].message.steps[m].content | string | 執行步驟的結果,當角色為assistant時表示模型的輸出內容,當角色為tool時表示工具的輸出內容 |
choices[n].message.steps[m].tool_call_id | string | 角色為tool時有效,內容為模型生成的工具調用中的唯一ID |
choices[n].message.steps[m].tool_calls | list | 模型生成的工具調用 |
choices[n].message.steps[m].tool_calls[i].id | string | 工具調用的唯一ID |
choices[n].message.steps[m].tool_calls[i].type | string | 調用的工具類型,當前只支持function |
choices[n].message.steps[m].tool_calls[i].function | object | 具體調用的function |
choices[n].message.steps[m].tool_calls[i].function.name | string | function名稱 |
choices[n].message.steps[m].tool_calls[i].function.desc | string | function描述 |
choices[n].message.steps[m].tool_calls[i].function.type | string | function類型,當前支持tool/knowledge/workflow |
choices[n].message.steps[m].tool_calls[i].function.arguments | string | 調用function的參數,JSON格式 |
choices[n].message.steps[m].usage | object | 當前執行步驟的token使用量 |
choices[n].message.steps[m].usage.prompt_tokens | number | 問題token使用量 |
choices[n].message.steps[m].usage.completion_tokens | number | 回答token使用量 |
choices[n].message.steps[m].usage.total_tokens | number | token總使用量 |
choices[n].message.steps[m].time_cost | number | 當前執行步驟的耗時 |
choices[n].delta | json | 返回的內容(流式返回) |
choices[n].delta.role | string | 角色名稱,assistant表示模型,tool表示工具調用(流式返回) |
choices[n].delta.content | string | 內容詳情,當角色為assistant時表示模型的輸出內容,當角色為tool時表示工具的輸出內容(流式返回) |
choices[n].delta.tool_call_id | string | 角色為tool時有效,內容為模型生成的工具調用中對應的tool_call ID (流式返回) |
choices[n].delta.tool_calls | list | 模型生成的工具調用(流式返回) |
choices[n].delta.tool_calls[m].id | string | 工具調用的唯一id(流式返回) |
choices[n].delta.tool_calls[m].type | string | 調用的工具類型,當前只支持function(流式返回) |
choices[n].delta.tool_calls[m].function | object | 具體調用的function(流式返回) |
choices[n].delta.tool_calls[m].function.name | string | function名稱(流式返回) |
choices[n].delta.tool_calls[m].function.desc | string | function描述(流式返回) |
choices[n].delta.tool_calls[m].function.type | string | function類型,當前支持tool/knowledge/workflow(流式返回) |
choices[n].delta.tool_calls[m].function.arguments | string | 調用function的參數,JSON格式(流式返回) |
choices[n].delta.time_cost | number | 當前執行步驟的耗時(流式返回) |
assistant_id | string | 實際使用的助手id |
usage | object | token使用量 |
usage.prompt_tokens | number | 問題token使用量 |
usage.completion_tokens | number | 回答token使用量 |
usage.total_tokens | number | token總使用量 |
import requests
import json
# 定義 API 的 URL
url = 'https://open.hunyuan.tencent.com/openapi/v1/agent/chat/completions'
# 定義請求頭
headers = {
'X-Source': 'openapi',
'Content-Type': 'application/json',
'Authorization': 'Bearer <元器用戶的token>'
}
# 定義請求體
data = {
"assistant_id": "I4aVQTHpsJro",
"user_id": "username",
"stream": False,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "生成去張家口旅行的計劃"
}
]
}
]
}
# 將請求體轉換為 JSON 格式的字符串
json_data = json.dumps(data)
# 發送 POST 請求
response = requests.post(url, headers=headers, json=data) # 使用 json 參數自動設置正確的 Content-Type
# 打印響應內容
print(response.text)
調用成功:
序號 | 錯誤碼 | 解釋 |
1 | 400 | 請求參數錯誤 |
待補充… |
當前每個元器用戶有100w的token體驗使用額度,額度用完后,將無法調用。我們會盡快上線API付費能力,付費后,可以支持更多次調用。
如果你想找到更多的大模型,歡迎到 冪簡集成 找找看,找到自己中意的大模型。