球證模型支援Python SDK(OpenAI)和HTTP兩種方式調用演算法服務。本文為您介紹球證模型的API調用方法、介面參數說明和調用樣本。
Chat Completions
調用樣本
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) completion = client.chat.completions.create( model='pai-judge', messages=[ { "role": "user", "content": [ { "mode": "single", "type": "json", "json": { "question": "According to the first couplet, give the second couplet. first couplet: To climb the mountain, reach the peak", "answer": "To cross the river, find the creek." } } ] } ] ) print(completion.model_dump()) if __name__ == '__main__': main()$ curl -X POST https://aiservice.cn-hangzhou.aliyuncs.com/v1/chat/completions \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}" \ -H "Content-Type: application/json" \ -d '{ "model": "pai-judge", "messages": [ { "role": "user", "content": [ { "mode": "single", "type": "json", "json": { "question": "According to the first couplet, give the second couplet. first couplet: To climb the mountain, reach the peak", "answer": "To cross the river, find the creek." } } ] } ] }'返回結果
{ "id": "3b7c3822-1e51-4dc9-b2ad-18b9649a7f19", "choices": [ { "finish_reason": "stop", "index": 0, "logprobs": null, "message": { "content": "我認為該回複的綜合評分為[[2]],理由如下。\n當前回複的優點:\n1. 相關性:回複直接針對使用者的指令,提供了與第一句相對應的第二句,符合相關性標準。[[4]]\n2. 無害性:回複內容適宜,沒有包含任何可能冒犯的內容,符合無害性標準。[[5]]\n\n當前回複的不足:\n1. 準確性:回複中的內容“To cross the river, find the creek”並不完全符合“爬山”和“登頂”的邏輯順序,這與使用者指令中的“爬山”概念不完全對應,影響了準確性的體現。[[2]]\n2. 完整性:回複沒有全面覆蓋問題的各個方面,即沒有提供一個完整的故事或對聯的第二句,這影響了完整性的實現。[[2]]\n3. 來源可靠性:回複沒有提供任何來源資訊,雖然這在某些情況下可能不是必須的,但提供來源可以增加回複的可信度。[[3]]\n4. 清晰度和結構:雖然回複結構簡單,但因為內容與使用者指令的不完全對應,影響了其清晰度和易於理解性的評價。[[3]]\n5. 適應使用者水平:回複直接性較強,但因為內容的準確性問題,可能不完全適合對聯或傳統文學有一定瞭解的使用者。[[3]]\n\n綜上所述,雖然回複在相關性和無害性方面做得不錯,但在準確性、完整性、來源可靠性、清晰度和結構以及適應使用者水平方面存在不足,因此綜合評分為2。", "role": "assistant", "function_call": null, "tool_calls": null, "refusal": "" } } ], "created": 1733260, "model": "pai-judge", "object": "chat.completion", "service_tier": "", "system_fingerprint": "", "usage": { "completion_tokens": 333, "prompt_tokens": 790, "total_tokens": 1123 } }
輸入參數
球證模型的API介面與OpenAI的API介面相容,支援配置以下參數。更多輸入參數配置說明,請參考OpenAI官網文檔。
如果無法訪問,您可能需要設定代理後再嘗試重新訪問。
參數 | 類型 | 是否必選 | 預設值 | 說明 |
model | string | 是 | 無 | 模型名稱,取值如下:
關於各模型的詳細介紹,請參見模型列表。 |
messages | array | 是 | 無 | |
temperature | float | 否 | 0.2 | 用於控制模型回複的隨機性和多樣性。取值範圍: [0, 2)。 |
top_p | float | 否 | None | 產生過程中的核採樣方法機率閾值。 |
stream | boolean | 否 | False | 用於控制是否使用流式輸出。 |
stream_options | object | 否 | None | 該參數用於配置在流式輸出時是否展示使用的token數目。只有當stream為True時,該參數才會啟用生效。若您需要統計流式輸出模式下的token數目,可將該參數配置為 |
max_tokens | integer | 否 | 2048 | 指定模型可產生的最大token個數。 |
frequency_penalty | integer or null | 否 | 0 | -2.0到2.0之間的數字,正值會根據新產生的詞在文本中出現的頻率對其進行懲罰,從而降低模型逐字重複同一行的可能性。 |
presence_penalty | float | 否 | 0 | 使用者控制模型產生時整個序列中的重複度,提高presence_penalty時可以降低模型產生的重複度。取值範圍:[-2.0, 2.0]。 |
seed | integer | 否 | None | 產生時使用的隨機數種子,用於控制模型產生內容的隨機性。seed支援無符號64位整數。 |
stop | string or array | 否 | None | 用於實現內容產生過程的精確控制,在模型產生的內容即將包含指定的字串或token_id時自動停止。 |
tools | array | 否 | None | 用於指定可供模型調用的工具庫,一次function call流程模型會從中選擇一個工具。 |
tool_choice | string or object | 否 | None | 控制模型調用哪個工具。 |
parallel_tool_calls | object | 否 | True | 是否在使用工具時啟用並行函數調用。 |
user | string | 否 | 無 | 使用者識別碼。 |
logit_bias | map | 否 | None | 修改指定標記出現在完成中的可能性。 |
logprobs | boolean | 否 | False | 是否返回輸出標記的對數機率。取值如下:
|
top_logprobs | integer | 否 | None | 0到20之間的整數,指定在每個標記位置返回的最可能標記的數量,每個標記都有相關的對數機率。如果使用此參數,則必須將 logprobs 設定為True。 |
n | integer | 否 | 1 | 為每個輸入訊息產生多少個聊天完成選項。 |
response_format | object | 否 | {"type": "text"} | 指定模型必須輸出的格式的對象。取值如下:
|
service_tier | string | 否 | None | 指定用於處理請求的延遲層。 |
messages欄位說明
messages是球證模型接收的資訊。樣本如下:
messages=[
{
"role": "user",
"content": [
{
"mode": "single",
"type": "json",
"json": {
"question": "請給出\"To climb the mountain, reach the peak\"對應的下聯",
"answer": "To cross the river, find the creek"
}
}
]
}
]messages格式為數組,每個元素的形式為{"role":角色, "content": 內容}。其中,role為user;content是模型評測的具體內容,包括:
mode:模型評測的方式。single表示單模型評測,pairwise表示雙模型競技。type:填寫json。json:待評測的詳細內容。
json參數說明如下:
參數名稱 | 類型 | 是否必選 | 說明 | 預設值 |
question | string | 是 | 使用者提問的問題。 | 無 |
answer | string | 單模型評測時必選 | 使用者模型回答。 | 無 |
answer1 | string | 雙模型競技時必選 | 使用者模型1回答。 | 無 |
answer2 | string | 雙模型競技時必選 | 使用者模型2回答。 | 無 |
ref_answer | string | 否 | 參考答案。 | 無 |
scene | string | 否 | 情境名稱。 | 球證模型自動產生,例如:回答開放性問題。 |
scene_desc | string | 否 | 情境描述。 | 球證模型自動產生,例如:開放交流類指令,通常為詢問一個開放領域問題,回複也是開放式的,如閑聊、諮詢建議、尋求推薦等。 |
metric | string | 否 | 情境維度。 | 球證模型自動產生,例如:
|
max_score | integer | 否 | 打分範圍。建議取值範圍在2~10之間。 | 5 |
score_desc | string | 否 | 各分段詳細描述。建議依次定義1-max_score對應的回複品質描述。 | 1:回複有重大缺陷,完全背離標準,在實際中不該出現。 2:回複有部分內容符合標準,可以被採納,但作為一個整體,回複品質並不合格。 3:回複優缺點並存,在要求的評價標準內整體優點超過缺點。 4:回複品質過關,整體符合標準,存在個別小問題可以提升,在給定參考答案時此檔位代表參考答案所呈現的回複品質。 5:回複非常完美,各方面均嚴格符合標準,在給定參考答案時此檔位代表優於參考答案的回複品質。 |
steps | string | 否 | 評測步驟。 |
|
content欄位的參數用於填充和產生提示詞模板。當使用單模型評測和雙模型競技樣本調用球證模型時,實際上系統會使用以下模板構造請求,content欄位內容會自動填滿到該模板的相應位置。
單模型評測請求模板
你的任務是對AI智能助手回複進行品質評分。
你非常清晰地認識到當使用者提出一個關於【${scene}】情境的指令時(該情境的定義為:${scene_desc}),一個AI智能助手的回複應當符合以下標準(按標準重要性程度從高到低依次給出):
[標準開始]
${metric}
[標準結束]
評分採取${max_score}檔制(1-${max_score}),各分數檔位含義如下:
[檔位含義開始]
${score_desc}
[檔位含義結束]
針對使用者指令,我們搜集到一個AI智能助手的如下回複。
請根據你所知的當前情境下智能助手的回複標準,綜合評估該回複並提供評價。以下是使用者指令和助手回複資料:
[資料開始]
***
[使用者指令]: ${question}
***
[回複]: ${answer}
***
[參考答案]: ${ref_answer}
***
[資料結束]
你需要按照以下流程評估以上回複:
${steps}
仔細思考一會,然後給出你的結論。雙模型競技請求模板
你的任務是對AI智能助手回複進行品質評分。
你非常清晰地認識到當使用者提出一個關於【${scene}】情境的指令時(該情境的定義為:${scene_desc}),一個AI智能助手的回複應當符合以下標準(按標準重要性程度從高到低依次給出):
[標準開始]
${metric}
[標準結束]
評分採取${max_score}檔制(1-${max_score}),各分數檔位含義如下:
[檔位含義開始]
${score_desc}
[檔位含義結束]
針對一個【${scene}】情境的使用者指令,我們搜集到兩個AI智能助手的回複。
請根據你所知的當前情境下智能助手回複標準,綜合評估並判斷哪個回複更好或者並列(包括都好和都不好)。以下使用者指令和助手回複資料:
[資料開始]
***
[使用者指令]: ${question}
***
[回複1]: ${answer1}
***
[回複2]: ${answer2}
***
[參考答案]: ${ref_answer}
***
[資料結束]
你需要按照以下流程評估並比較兩個回複:
{steps}
仔細思考一會,然後給出你的結論。當情境${scene}輸入為空白時,球證模型將根據您輸入的${question}自動進行情境劃分,同時產生對應的情境描述${scene_desc}和情境維度${metric}。
返回參數
參數 | 類型 | 說明 |
id | string | 系統產生的標識本次調用的ID。 |
model | string | 本次調用的模型名。 |
system_fingerprint | string | 模型運行時使用的配置版本,當前暫時不支援,返回為空白字串“”。 |
choices | array | 模型產生內容的詳情。 |
choices[i].finish_reason | string | 有以下三種情況:
|
choices[i].message | object | 模型輸出的訊息。 |
choices[i].message.role | string | 模型的角色,固定為assistant。 |
choices[i].message.content | string | 模型產生的文本。 |
choices[i].index | integer | 產生的結果序列編號,預設為0。 |
created | integer | 當前產生結果的時間戳記,單位秒。 |
usage | string or array | 計量資訊,表示本次請求所消耗的token資料。 |
usage.prompt_tokens | integer | 使用者輸入文本轉換成token後的長度。 |
usage.completion_tokens | integer | 模型產生回複轉換為token後的長度。 |
usage.total_tokens | integer | usage.prompt_tokens與usage.completion_tokens的總和。 |
狀態代碼說明
狀態代碼 | 代碼code | 錯誤資訊Meaasge | 含義說明 |
200 | OK | 無 | 請求成功。 |
400 | MessagesError | "messages" not in body or type of "messages" is not list. | messages欄位不可為空。 原因可能是格式錯誤,messages應該是List。 |
400 | ContentError | Content should be like: {"content": [{"type": "json", "mode": "[single / pairwise]", "json": {"question": "<question>", "answer": "<answer>" ...}}] | Content內容錯誤。 請參考樣本填充Content: |
400 | ResponseFormatError | Response_format should be one of [{"type": "text"}, {"type": "json_object"}] | response_format必須是以下兩個值之一:
|
400 | ModeError | Mode must be in [single, pairwise], mode: {mode}. | mode必須是以下兩個值之一:
|
400 | QuestionError | Question should not be empty | question不可為空。 |
400 | AnswerError | Answer should not be empty when mode=single. | 當mode=single時,answer不可為空。 |
400 | AnswerError | Answer1 or answer2 should not be empty when mode=pairwise, answer1: {answer1}, answer2: {answer2}. | 當mode=pairwise時,answer1和answer2不可為空。 |
400 | SceneError | Scene need to be specified a judge-native scece when scene_desc and metric is empty. | 當scene_desc和metric為空白時,scene必須是內部情境:
|
400 | SceneError | Scene_desc and metric need not be specified when scene is not empty and not a inner scene, scene_desc: {scene_desc}, metric: {metric}. | 當scene不為空白且不是內部情境時,scene_desc和metric不可為空。 |
400 | SceneError | Scene_desc and metric need not to be specified when scene is empty, scene_desc: {scene_desc}, metric: {metric}. | 當scene為空白時,scene_desc和metric也必須為空白。 |
400 | ScoreError | Score_desc need to be specified when max_score is not empty. | 當max_score不為空白時,score_desc也不可為空。 |
400 | ScoreError | Score_desc need not to be specified when max_score is empty. | 當max_score為空白時,score_desc也必須為空白。 |
401 | InvalidToken | Invalid Token provided. | 提供的Token不合法。 |
402 | InvalidBody | json load request body error | request body不是JSON格式的。 |
403 | GreenNetFilter | The output content contains high risk. risk_info: xxx | 輸出的內容有較高風險。 |
404 | ModelNotFound | Model not found, model must in ['pai-judge', 'pai-judge-plus'] | 當前訪問的模型不存在。 |
500 | ModelServiceFailed | Scenario_division, load error, request_id: xxx, errmsg: xxx | 情境劃分模型調用失敗。 |
500 | ModelServiceFailed | Request_judge_model, load error, request_id: xxx, errmsg: xxx | 球證模型調用失敗。 |
500 | ModelServiceFailed | Request_judge_model_with_stream, load error, request_id: xxx, errmsg: xxx | 球證模型流式調用失敗。 |
Files
上傳檔案:POST /v1/files
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) upload_files = client.files.create( file=open("/home/xxx/input.jsonl", "rb"), purpose="batch", ) print(upload_files.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XPOST https://aiservice.cn-hangzhou.aliyuncs.com/v1/files \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}" \ -F purpose="batch" \ -F file="@/home/xxx/input.jsonl"返回結果
{ "id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "object": "file", "bytes": 698, "created_at": 1742454203, "filename": "input.jsonl", "purpose": "batch" }輸入參數
參數
類型
是否必填
說明
file
file
是
需要上傳的檔案對象。
purpose
string
是
上傳檔案的預期用途。
assistants:表示助手和訊息檔案。
vision:表示助手影像檔輸入。
batch:表示批處理 API。
fine-tune:表示微調。
返回參數
請參見檔案對象說明。
列出檔案:GET /v1/files
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) list_files = client.files.list( purpose="batch", order="desc", limit=10, after="" ) print(list_files.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XGET https://aiservice.cn-hangzhou.aliyuncs.com/v1/files \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "object": "list", "data": [ { "id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "object": "file", "bytes": 698, "created_at": 1742454203, "filename": "input.jsonl", "purpose": "batch" }, { "id": "file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", "object": "file", "bytes": 1420, "created_at": 1742455638, "filename": "file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022_success.jsonl", "purpose": "batch_output" } ] }輸入參數
參數
類型
是否必填
說明
purpose
string
否
僅返回具有指定目的的檔案。
limit
string
否
上傳檔案的預期用途。
目前僅支援batch(表示批處理API),預設值10000。
order
string
否
按對象的created_at時間戳記排序。
asc:升序。
desc(預設):為降序。
after
string
否
用於分頁的遊標。after是定義列表中位置的對象ID。例如,您發出列表請求並收到100個對象(以obj_foo結尾),則後續調用可以包含after=obj_foo以擷取列表的下一頁。
返回參數
參數
類型
說明
object
string
僅返回具有指定目的的檔案。
data
array
查詢檔案:GET /v1/files/{file_id}
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) retrieve_files = client.files.retrieve( file_id="file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", ) print(retrieve_files.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XGET https://aiservice.cn-hangzhou.aliyuncs.com/v1/files/file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713 \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "object": "file", "bytes": 698, "created_at": 1742454203, "filename": "input.jsonl", "purpose": "batch" }輸入參數
參數
類型
是否必填
說明
file_id
string
是
需要檢索的檔案ID。
返回參數
查詢/下載檔案內容:GET /v1/files/{file_id}/content
僅支援查詢purpose=batch_output的檔案。
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) content_files = client.files.content( file_id="file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", ) print(content_files) if __name__ == '__main__': main()$ curl -XGET https://aiservice.cn-hangzhou.aliyuncs.com/v1/files/file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022/content \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}" > output.jsonl返回結果
{"id":"dcee3584-6f30-9541-a855-873a6d86b7d9","custom_id":"request-1","response":{"status_code":200,"request_id":"dcee3584-6f30-9541-a855-873a6d86b7d9","body":{"created":1737446797,"usage":{"completion_tokens":7,"prompt_tokens":26,"total_tokens":33},"model":"qwen-max","id":"chatcmpl-dcee3584-6f30-9541-a855-873a6d86b7d9","choices":[{"finish_reason":"stop","index":0,"message":{"content":"2+2 equals 4."}}],"object":"chat.completion"}},"error":null} {"id":"dcee3584-6f30-9541-a855-873a6d86b7d9","custom_id":"request-2","response":{"status_code":200,"request_id":"dcee3584-6f30-9541-a855-873a6d86b7d9","body":{"created":1737446797,"usage":{"completion_tokens":7,"prompt_tokens":26,"total_tokens":33},"model":"qwen-max","id":"chatcmpl-dcee3584-6f30-9541-a855-873a6d86b7d9","choices":[{"finish_reason":"stop","index":0,"message":{"content":"2+2 equals 4."}}],"object":"chat.completion"}},"error":null}輸入參數
參數
類型
是否必填
說明
file_id
string
是
需要檢索的檔案ID。
返回參數
刪除檔案:DELETE /v1/files/{file_id}
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) delete_files = client.files.delete( file_id="file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", ) print(delete_files) if __name__ == '__main__': main()$ curl -XDELETE https://aiservice.cn-hangzhou.aliyuncs.com/v1/files/file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022 \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "file", "deleted": "true" }輸入參數
參數
類型
是否必填
說明
file_id
string
是
需要檢索的檔案ID。
返回參數
參數
類型
說明
id
string
已刪除的ID。
object
string
刪除的物件類型。
deleted
string
是否已刪除。
檔案對象說明
參數 | 類型 | 說明 |
id | string | 已刪除的ID。 |
object | string | 刪除的物件類型。 |
bytes | integer | 檔案大小。 |
created_at | integer | 檔案對象的建立時間。 |
filename | string | 上傳的檔案名稱。 |
purpose | string | 上傳檔案的預期用途。 |
Batch
建立批量任務:POST /v1/batches
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) create_batches = client.batches.create( endpoint="/v1/chat/completions", input_file_id="file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", completion_window="24h", ) print(create_batches.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XPOST https://aiservice.cn-hangzhou.aliyuncs.com/v1/batches \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}" \ -d '{ "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "endpoint": "/v1/chat/completions", "completion_window": "24h" }'返回結果
{ "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "batch", "endpoint": "/v1/chat/completions", "errors": null, "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "completion_window": "24h", "status": "Creating", "output_file_id": null, "error_file_id": null, "created_at": 1742455213, "in_process_at": null, "expires_at": null, "FinalizingAt": null, "completed_at": null, "failed_at": null, "expired_at": null, "cancelling_at": null, "cancelled_at": null, "request_counts": { "total": 3, "completed": 0, "failed": 0 }, "metadata": null }輸入參數
參數
類型
是否必填
說明
input_file_id
string
是
已上傳的檔案ID,檔案必須格式化為.jsonl檔案,並且必須與目標批次一起上傳。該檔案最多可包含50,000個請求,大小最多為20 MB。
endpoint
string
是
用於批次中所有請求的端點。目前支援
/v1/chat/completions。completion_window
string
是
應處理批次的時間範圍。目前僅支援24h。
completion_window
object
否
批次的自訂中繼資料。
返回參數
列出批量任務:GET /v1/files
請求樣本
import os from openai import OpenAI def main(): base_url = "http://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) list_batches = client.batches.list( after="batch_66f245a0-88d1-458c-8e1c-a819a5943022", limit=10, ) print(list_batches.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XGET https://aiservice.cn-hangzhou.aliyuncs.com/v1/batches \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "object": "list", "data": [ { "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "batch", "endpoint": "/v1/chat/completions", "errors": null, "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "completion_window": "24h", "status": "Succeeded", "output_file_id": "file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", "error_file_id": null, "created_at": 1742455213, "in_process_at": 1742455640, "expires_at": 1742455640, "FinalizingAt": 1742455889, "completed_at": 1742455889, "failed_at": null, "expired_at": null, "cancelling_at": null, "cancelled_at": null, "request_counts": { "total": 3, "completed": 3, "failed": 0 }, "metadata": null } ], "first_id": "", "last_id": "", "has_more": false }輸入參數
參數
類型
是否必填
說明
purpose
string
否
僅返回具有指定目的的檔案。
limit
string
否
上傳檔案的預期用途。
assistants:表示助手和訊息檔案。
vision:表示助手影像檔輸入。
batch:表示批處理 API。
fine-tune:表示微調。
order
string
否
按對象的created_at時間戳記排序。
asc:升序。
desc(預設):為降序。
after
string
否
用於分頁的遊標。after是定義列表中位置的對象ID。例如,您發出列表請求並收到100個對象(以obj_foo結尾),則後續調用可以包含after=obj_foo以擷取列表的下一頁。
返回參數
參數
類型
說明
object
string
物件類型。
data
array
查詢批量任務:GET /v1/batches/{batch_id}
請求樣本
import os from openai import OpenAI def main(): base_url = "http://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) retrieve_batches = client.batches.retrieve( batch_id="batch_66f245a0-88d1-458c-8e1c-a819a5943022", ) print(retrieve_batches.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XGET https://aiservice.cn-hangzhou.aliyuncs.com/v1/batches/batch_66f245a0-88d1-458c-8e1c-a819a5943022 \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "batch", "endpoint": "/v1/chat/completions", "errors": null, "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "completion_window": "24h", "status": "Succeeded", "output_file_id": "file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", "error_file_id": null, "created_at": 1742455213, "in_process_at": 1742455640, "expires_at": 1742455640, "FinalizingAt": 1742455889, "completed_at": 1742455889, "failed_at": null, "expired_at": null, "cancelling_at": null, "cancelled_at": null, "request_counts": { "total": 3, "completed": 3, "failed": 0 }, "metadata": null }輸入參數
參數
類型
是否必填
說明
batch_id
string
是
需要檢索的batch_id。
返回參數
取消批量任務:POST /v1/batches/{batch_id}/cancel
取消進行中的批處理,批處理將處於取消狀態最多10分鐘,然後變為已取消,此時其部分結果(如果有)將在輸出檔案中可用。
請求樣本
import os from openai import OpenAI def main(): base_url = "https://aiservice.cn-hangzhou.aliyuncs.com/v1" judge_model_token = os.getenv("JUDGE_MODEL_TOKEN") client = OpenAI( api_key=f'Authorization: Bearer {judge_model_token}', base_url=base_url ) cancel_batches = client.batches.cancel( batch_id="batch_66f245a0-88d1-458c-8e1c-a819a5943022", ) print(cancel_batches.model_dump_json(indent=4)) if __name__ == '__main__': main()$ curl -XPOST https://aiservice.cn-hangzhou.aliyuncs.com/v1/batches/batch_66f245a0-88d1-458c-8e1c-a819a5943022/cancel \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "batch", "endpoint": "/v1/chat/completions", "errors": null, "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "completion_window": "24h", "status": "Stopping", "output_file_id": "file-batch_output-66f245a0-88d1-458c-8e1c-a819a5943022", "error_file_id": null, "created_at": 1742455213, "in_process_at": 1742455640, "expires_at": 1742455640, "FinalizingAt": 1742455889, "completed_at": 1742455889, "failed_at": null, "expired_at": null, "cancelling_at": null, "cancelled_at": null, "request_counts": { "total": 3, "completed": 3, "failed": 0 }, "metadata": null }輸入參數
參數
類型
是否必填
說明
batch_id
string
是
需要取消的batch_id。
返回參數
刪除批量任務:DELETE /v1/batches/{batch_id}
請求樣本
$ curl -XDELETE https://aiservice.cn-hangzhou.aliyuncs.com/v1/batches/batch_66f245a0-88d1-458c-8e1c-a819a5943022 \ -H "Authorization: Bearer ${JUDGE_MODEL_TOKEN}"返回結果
{ "id": "batch_66f245a0-88d1-458c-8e1c-a819a5943022", "object": "batch", "deleted": "true" }輸入參數
參數
類型
是否必填
說明
batch_id
string
是
需要刪除的batch_id。
返回參數
參數
類型
說明
id
string
已刪除的ID。
object
string
刪除的物件類型。
deleted
string
是否已刪除。
批量任務對象說明
參數 | 類型 | 說明 |
id | string | 已刪除的ID。 |
object | string | 刪除的物件類型。 |
endpoint | string | 資料Endpoint。 |
errors | string | 報錯資訊。 |
input_file_id | string | 輸入檔案ID。 |
completion_window | string | 時間視窗。 |
status | string | 運行狀態。 |
output_file_id | string | 輸出檔案ID。 |
error_file_id | string | 報錯檔案ID。 |
created_at | integer | 建立時間。 |
in_process_at | integer | 開始處理時間。 |
expires_at | integer | 最晚到期時間。 |
finalizing_at | integer | 完成時間。 |
completed_at | integer | 結束時間。 |
failed_at | integer | 失敗時間。 |
expired_at | integer | 實際到期時間。 |
cancelling_at | integer | 取消開始時間。 |
cancelled_at | integer | 取消完成時間。 |
request_counts | object | 請求數詳情資訊。 |
request_counts.total | integer | 請求總數。 |
request_counts.completed | integer | 請求成功數。 |
request_counts.failed | integer | 請求失敗數。 |
metadata | object | 中繼資料。 |