API功能说明

裁判员模型支持Python SDK(OpenAI)和HTTP两种方式调用算法服务。本文为您介绍裁判员模型的API调用方法、接口参数说明和调用示例。

Chat Completions

调用示例

  1. 请求示例

    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": "请给出\"常德德山山有德\"对应的下联",
                                "answer": "长沙沙水水无沙"
                            }
                        }
                    ]
                }
            ]
        )
        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": "请给出\"常德德山山有德\"对应的下联",
                            "answer": "长沙沙水水无沙"
                        }
                    }
                ]
            }
        ]
    }'
  2. 返回结果

    {
      "id": "73d74ed7-1a94-4eac-b67b-14b9a5e20b35",
      "object": "chat.completion",
      "created": 1633389,
      "model": "pai-judge",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "我认为该回复的综合评分为[[3]],理由如下。\n当前回复的优点:\n1. 准确性:回复正确地给出了“常德德山山有德”的下联“长沙沙水水无沙”,这显示了回复在处理对联方面具有一定的准确性。[[4]]\n2. 相关性:回复直接针对用户的问题,提供了一个简洁明了的答案,没有偏离主题。[[4]]\n\n当前回复的不足:\n1. 完整性:虽然回复给出了一个看似正确的下联,但没有提供任何关于如何得出这一下联的背景信息或解释。对于不熟悉对联知识的用户来说,缺乏解释可能会影响理解。[[3]]\n2. 清晰度和结构:回复的结构相对简单,但由于缺乏解释,其教育意义和用户理解度的提升空间有限。[[3]]\n3. 适应用户水平:回复没有考虑到用户可能对联的创作或推理过程不甚了解,未能提供足够的背景信息来帮助用户理解。[[3]]\n\n综上所述,虽然回复在准确性和相关性方面表现不错,但在完整性、清晰度和结构以及适应用户水平方面存在不足。因此,综合评分为3。\n",
            "refusal": "",
            "function_call": null,
            "tool_calls": null},
          "finish_reason": "stop",
          "logprobs": null
        }
      ],
      "usage": {
        "prompt_tokens": 790,
        "completion_tokens": 257,
        "total_tokens": 1047
      },
      "system_fingerprint": "",
      "service_tier": ""
    }

输入参数

裁判员模型的API接口与OpenAIAPI接口兼容,支持配置以下参数。更多输入参数配置说明,请参考OpenAI官网文档

说明

如果无法访问,您可能需要设置代理后再尝试重新访问。

参数

类型

是否必选

默认值

说明

model

string

模型名称,取值如下:

  • 裁判员模型-标准版(pai-judge)

  • 裁判员模型-高级版(pai-judge-plus)

关于各模型的详细介绍,请参见模型列表

messages

array

待评测的内容

temperature

float

0.2

用于控制模型回复的随机性和多样性。取值范围: [0, 2)。

top_p

float

None

生成过程中的核采样方法概率阈值。

stream

boolean

False

用于控制是否使用流式输出。

stream_options

object

None

该参数用于配置在流式输出时是否展示使用的token数目。只有当streamTrue时,该参数才会激活生效。若您需要统计流式输出模式下的token数目,可将该参数配置为stream_options={"include_usage":True}

max_tokens

integer

2048

指定模型可生成的最大token个数。

frequency_penalty

integer or null

0

-2.02.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

是否返回输出标记的对数概率。取值如下:

  • False:不返回。

  • True:返回消息内容中每个输出标记的对数概率。

top_logprobs

integer

None

020之间的整数,指定在每个标记位置返回的最可能标记的数量,每个标记都有相关的对数概率。如果使用此参数,则必须将 logprobs 设置为True

n

integer

1

为每个输入消息生成多少个聊天完成选项。

response_format

object

{"type": "text"}

指定模型必须输出的格式的对象。取值如下:

  • {"type": "text"}(默认):模型返回自然语言描述的评测回复。

  • {"type": "json_object"}:模型返回JSON格式的评测回复。例如:

    {
      "总分": "4",
      "准确性": {
        "分数": "5",
        "理由": "回复准确地给出了“常德德山山有德”的下联“长沙沙水水无沙”,符合对联的规则,展现了高度的准确性"
      },
      "相关性": {
        "分数": "3",
        "理由": "回复直接回答了用户的问题,没有包含任何不必要的信息,确保了高度的相关性"
      }
    }
    

service_tier

string

None

指定用于处理请求的延迟层。

messages字段说明

messages是裁判员模型接收的信息。示例如下:

messages=[
    {
        "role": "user",
        "content": [
            {
                "mode": "single",
                "type": "json",
                "json": {
                    "question": "请给出\"常德德山山有德\"对应的下联",
                    "answer": "长沙沙水水无沙"
                }
            }
        ]
    }
]

messages格式为数组,每个元素的形式为{"role":角色, "content": 内容}。其中,roleusercontent是模型评测的具体内容,包括:

  • 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

评测步骤。

  1. 回忆相关的智能助手回复标准,并仔细阅读、理解待评估回复。

  2. 从所有标准中识别出针对当前用户指令以及回复的关键标准,包括表现好以及不足的。

  3. 除了给定的标准外,添加您认为必要的评估当前用户指令回复的其他重要标准。

  4. 依据您最终筛选的标准,依次给该回复赋分(1~5之间),加权汇总所有小项得分后给出该回复综合评分。 仔细思考,然后给出您的结论。您返回的模板如下,注意输出需保留模板中的'[['和']]':。

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

有以下三种情况:

  • null:正在生成。

  • stop:因触发输入参数中的stop条件而结束。

  • length:因生成长度过长而结束。

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_tokensusage.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:

{
  "content": [
    {
      "type": "json", 
      "mode": "[single / pairwise]", 
      "json": {
        "question": "<question>", 
        "answer": "<answer>",
        ...
      }
    }
  ]
}

400

ResponseFormatError

Response_format should be one of [{"type": "text"}, {"type": "json_object"}]

response_format必须是以下两个值之一:

  • {"type": "text"}

  • {"type": "json_object"}

400

ModeError

Mode must be in [single, pairwise], mode: {mode}.

mode必须是以下两个值之一:

  • single

  • pairwise

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时,answer1answer2不能为空。

400

SceneError

Scene need to be specified a judge-native scece when scene_desc and metric is empty.

scene_descmetric为空时,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_descmetric不能为空。

400

SceneError

Scene_desc and metric need not to be specified when scene is empty, scene_desc: {scene_desc}, metric: {metric}.

scene为空时,scene_descmetric也必须为空。

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

元数据。