API 文档
1. API 地址
为了使您能够正确地调用此API,您需要知道两个关键部分的地址:Gateway地址和API的具体地址。
1.1. Gateway地址
此地址为API的前端网关地址,您可以在后台管理的API Portal中找到。所有的API调用都会先经过此网关地址。
<img src="./API 文档配置文档.assets/image-20230730173307391.png" alt="image-20230730173307391" style="zoom:50%;" />
示例:
https://small-gw-gateway-cp4i.apps.cluster0523.elwk.p1.openshiftapps.com/
1.2. API具体地址
这是您要访问的具体API的地址,此地址需要接在Gateway地址后面。
<img src="./API 文档配置文档.assets/image-20230730173750391.png" alt="image-20230730173750391" style="zoom:50%;" />
示例:
ai-api/platform/chat-with-pdf
1.3. 完整API调用地址
将Gateway地址和API地址组合起来,您就得到了完整的API调用地址。使用此地址,您就可以进行API调用。
示例:
https://small-gw-gateway-cp4i.apps.cluster0523.elwk.p1.openshiftapps.com/ai-api/platform/chat-with-pdf
2. 请求格式
请求头
参数名 | 描述 | 示例 |
---|---|---|
X-IBM-Client-Id | API Portal 提供的Client ID | Your_Client_ID |
Accept | 指定期望的响应数据格式 | application/json |
Content-Type | 发送的数据格式,通常为 JSON | application/json |
X-IBM-Clinet-Id可以在后台得到
<img src="./API 文档配置文档.assets/image-20230730174115601.png" alt="image-20230730174115601" style="zoom:50%;" />
请求体
parameters:请求的特定参数。
<img src="./API 文档配置文档.assets/image-20230730174341996.png" alt="image-20230730174341996" style="zoom:50%;" />
contextMessages:历史消息数组,包括系统、用户和助手消息。
latestMessage:用户的最新消息或查询。
attachments:附带的文件或其他类型的内容。
<img src="./API 文档配置文档.assets/image-20230730174438979.png" alt="image-20230730174438979" style="zoom:50%;" />
示例:
{
"contextMessages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"},
{"role": "assistant", "content": "Thank you for the compliment!"}
],
"latestMessage": {
"role": "user",
"content": "Tell me more about the weather today."
},
"parameters": {
"template": "specific_template_name",
"maxTokens": 150,
"n": 1
},
"attachments": [
{"fileType": "image", "fileURL": "https://yourdomain.com/path/to/file1.jpg"},
{"fileType": "doc", "fileURL": "https://yourdomain.com/path/to/file2.doc"}
]
}
3. 响应格式
正常响应
包含状态、代码、消息、助手的响应和可能的附件。
<img src="./API 文档配置文档.assets/image-20230730174614309.png" alt="image-20230730174614309" style="zoom:50%;" />
示例:
{
"status": "success",
"code": 200,
"message": "Processed successfully",
"responses": [
{"role": "assistant", "content": "The weather today is sunny with a high of 25°C."}
],
"attachments": [
{"fileType": "image", "fileURL": "https://yourdomain.com/path/to/response_image.jpg"}
]
}
错误处理
当API遇到错误时的响应格式。
示例:
{
"status": "error",
"code": 400,
"message": "Invalid file type",
"errorDetails": "The provided file type is not supported."
}
网友评论