媒体识别
POST v1beta/models/{model}:generateContent请求参数
Authorization
在 Header 添加参数 Authorization,其值为在 Bearer 之后拼接 Token。
Authorization: Bearer ******************path 参数
| 参数名 | 类型 | 必填项 | 说明 |
|---|---|---|---|
| model | string | 必需 | 模型 |
Body 参数
Content-Type: application/json
| 参数名 | 类型 | 必填项 | 说明 |
|---|---|---|---|
| contents | array[object] | 必需 | 文本内容 |
| role | string | 可选 | 角色 |
| parts | array[object] | 可选 | 部分 |
| text | string | 可选 | 内容 |
| inlineData | object | 可选 | 图片参数 |
请求示例 (JSON)
{
"contents": [
{
"role": "user",
"parts": [
{
"text": "Tell me about this instrument"
},
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "图片base64"
}
}
]
}
]
}返回响应
200 成功
Content-Type: application/json
响应参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | string | 必需 | 聊天补全对象的唯一标识符。 |
| object | string | 必需 | 对象类型,通常为 "chat.completion"。 |
| created | integer | 必需 | 补全创建时的 Unix 时间戳(秒)。 |
| choices | array [object] | 必需 | 模型生成的补全列表。 |
| └─index | integer | 可选 | 此补全在其列表中的索引。 |
| └─message | object | 可选 | 包含模型生成的响应消息的对象。 |
| └─finish_reason | string | 可选 | 模型停止生成补全的原因。可能是 "stop"、"length" 或 "tool_calls"。 |
| usage | object | 必需 | 此补全请求使用的令牌统计信息。 |
| └─prompt_tokens | integer | 必需 | 提示中使用的令牌数量。 |
| └─completion_tokens | integer | 必需 | 补全中生成的令牌数量。 |
| └─total_tokens | integer | 必需 | 使用的总令牌数(提示 + 补全)。 |
响应示例
{
"id": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"message": {
"role": "string",
"content": "string"
},
"finish_reason": "string"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}示例代码
python
import http.client
import json
conn = http.client.HTTPSConnection("nxaiapp.com")
payload = json.dumps({
"contents": [
{
"role": "user",
"parts": [
{
"text": "Tell me about this instrument"
},
{
"inlineData": {
"mimeType": "image/jpeg",
"data": "图片base64"
}
}
]
}
]
})
headers = {
'Authorization': 'Bearer <token>',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1beta/models/:generateContent", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))