部署详情(Expert)
基模型服务详情。
GET
https://api.alayanew.com/api/serverless-infer/v1/deployment/{serviceId}
Authorizations
Authorizations:StringHeaderRequired
用户可通过已获取Open API Key做验证,例如:plain Credential=[YOUR_AK],Signature=[YOUR_SK]。
Path Parameters
serviceId:StringRequired
服务ID。
Response
状态码:application/json
200
code:Int
code是一种常见的返回值形式,表示查询操作的执行结果。
0
-1
0是成功标识,表示操作成功完成。
data:Object
msg:String
code返回值为-1时,返回异常信息。
cURL
Python
JavaScript
Go
Java
curl --location --request GET 'https://api.alayanew.com/api/serverless-infer/v1/deployment/38fbfc3d-6a88-4c35-b8b6-9efc83949d47'
--header 'Authorization:plain Credential=YOUR_AK,Signature=YOUR_SK'
--header 'Content-Type: application/json'
200
400
401
403
404
500
{
"code": 0,
"data": {
"serviceId":"",
"serviceUrl":"string",
"apikey":"String",
"status":"string, 状态",
"instance": [{
"instanceId": "0",
"loraModels": ["lora1","lora2"],
"baseModelReady": true
}],
"vksId": "",
"namespace": "",
"name": "",
"modelId": "String, 模型ID",
"mode":"expert",
"expert":{
"headConfig": {
"image": "required, string,",
"imagePullSecret": {
"registry": "",
"username": "",
"password": ""
},
"labels": {},
"env": {},
"cmd": [],
"args": [],
"resource": {
"cpu": "required,int",
"mem": "required,int",
"gpu": {
"gpuType": "required, string, gpu type name",
"count": "required, int, number of gpu to be use"
}
},
"pvcMounts": [
{
"pvcName": "",
"subPath": "optionl",
"containerPath": "",
"readOnly": ""
}
]
},
"workerConfig": {
"image": "required, string,",
"imagePullSecret": {
"registry": "",
"username": "",
"password": ""
},
"workers":"int , worker nums"
"labels": {},
"env": {},
"cmd": [],
"args": [ ],
"resource": {
"cpu": "required,int",
"mem": "required,int",
"gpu": {
"gpuType": "required, string, gpu type name",
"count": "required, int, number of gpu to be use"
}
},
"pvcMounts": [
{
"pvcName": "",
"subPath": "optionl",
"containerPath": "",
"readOnly": ""
}
]
}
},
"quickStart":null
}
}
服务状态
服务状态(status)流转详情如下图所示。
服务调用
用户在部署模型服务后,可通过指定模型的参数来调用该服务。调用服务的代码示例如下所示。
- cURL
- Python
- JavaScript
- Go
- Java
curl --location --request POST '[serviceUrl]/v1/chat/completions' \
--header 'apiKey: [apiKey]' \
--data-raw `{ "stream":false,
"messages": [{"role":"user", "content":"你是谁,能干嘛"}],
"model":"[servedName]"}`
import requests
url = "[serviceUrl]/v1/chat/completions"
headers = {
"apiKey": "[apiKey]"
}
data = {
"stream": False,
"messages": [
{
"role": "user",
"content": "你是谁,能干嘛"
}
],
"model": "[servedName]"
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
const axios = require('axios');
const url = '[serviceUrl]/v1/chat/completions';
const headers = {
'apiKey': '[apiKey]'
};
const data = {
stream: false,
messages: [
{
role: 'user',
content: '你是谁,能干嘛'
}
],
model: '[servedName]'
};
axios.post(url, data, { headers })
.then(response => {
console.log(response);
})
.catch(error => {
console.error('请求失败:', error);
});
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
url := "[serviceUrl]/v1/chat/completions"
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
}
type RequestBody struct {
Stream bool `json:"stream"`
Messages []Message `json:"messages"`
Model string `json:"model"`
}
body := RequestBody{
Stream: false,
Messages: []Message{
{Role: "user", Content: "你是谁,能干嘛"},
},
Model: "[servedName]",
}
jsonData, _ := json.Marshal(body)
req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
req.Header.Set("apiKey", "[apiKey]")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Println(result)
}
import okhttp3.*;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
public class Test {
public static void main(String[] args) {
String OPENAI_API_KEY = "[apiKey]";
String OPENAI_API_BASE = "[serviceUrl]/v1/chat/completions";
String model = "[servedName]";
OkHttpClient client = new OkHttpClient().newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.MINUTES)
.writeTimeout(10, TimeUnit.MINUTES)
.build();
String jsonInputString = "{"
+ "\"stream\":false,"
+ "\"messages\":[{\"role\":\"user\",\"content\":\"你是谁,能干嘛\"}],"
+ "\"model\":\"" + model + "\""
+ "}";
System.out.println(jsonInputString);
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, jsonInputString);
Request request = new Request.Builder()
.url(OPENAI_API_BASE)
.method("POST", body)
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.addHeader("apiKey", OPENAI_API_KEY)
.build();
try {
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
} catch (IOException e) {
e.printStackTrace();
}
}
}