判定モデルを使用すると、Python 用 OpenAI SDK と HTTP を使用してアルゴリズムサービスを呼び出すことができます。このトピックでは、判定モデルの API の呼び出し方法、API パラメーター、およびサンプルコードについて説明します。
チャット補完
サンプルコード
リクエスト例
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": "I think the overall score of the answer is [[2]] due to the following reasons:\n Advantages of the answer:\n1. Relevance: The answer directly addresses the user's question, providing a second couplet that corresponds to the first couplet. ThiS meets the relevance criteria.[[4]]\n2. Harmlessness: The answer does not contain offensive content. This meets the harmlessness criteria.[[5]]\n\n Disadvantages of the answer: \n1. Accuracy: The content \"To cross the river, find the creek\" does not fully align with the logical sequence of \"climbing\" and \"reaching the peak\" in the user's question, which affects the accuracy of the answer.[[2]]\n2. Completeness: The answer does not fully address all aspects of the question because the answer does not provide a complete story or completely align with the question. This affects the completeness of the answer.[[2]]\n3. Source reliability: The answer does not provide source information. Although the source information may not be necessary in some scenarios, the information can enhance the credibility of the answer.[[3]]\n4. Clarity and structure: Although the answer is simple in structure, its clarity and comprehensibility are affected because the answer does not fully correspond to the question.[[3]]\n5. Adaptability to the user level: Although the answer directly addresses the question, the answer may not be completely suitable for users who have a certain understanding of couplets or traditional literature due to inaccuracy.[[3]]\n\n In summary, although the answer performs well in relevance and harmlessness, the answer shows shortcomings in accuracy, completeness, source reliability, clarity and structure, and adaptability to the user level, which results in an overall rating of 2.", // 回答の全体的なスコアは、以下の理由により[[2]]だと思います。\n回答の長所:\n1. 関連性:回答はユーザーの質問に直接答え、最初の対句に対応する2番目の対句を提供しています。これは関連性の基準を満たしています。[[4]]\n2. 無害性:回答には不快な内容は含まれていません。これは無害性の基準を満たしています。[[5]]\n\n回答の短所:\n1. 正確性:「川を渡り、小川を見つける」という内容は、ユーザーの質問の「登る」と「頂上に到達する」という論理的シーケンスと完全には一致しておらず、回答の正確性に影響を与えています。[[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 と互換性があります。次の表に示すパラメーターを構成できます。
Web ページにアクセスできない場合は、プロキシを構成してから再試行する必要がある場合があります。
パラメーター | タイプ | 必須 | デフォルト値 | 説明 |
model | string | はい | なし | モデルの名前。有効な値:
モデルの詳細については、「サポートされている判定モデル」をご参照ください。 |
messages | array | はい | なし | |
temperature | float | いいえ | 0.2 | モデルが提供する回答のランダム性と多様性を制御します。有効な値:[0, 2)。 |
top_p | float | いいえ | なし | 生成プロセスで使用される核サンプリング法の確率しきい値。 |
stream | boolean | いいえ | False | ストリーミング出力モードを有効にするかどうかを指定します。 |
stream_options | object | いいえ | なし | ストリーミング出力モードで使用されたトークン数を表示するかどうかを指定します。このパラメーターは、stream パラメーターが True に設定されている場合にのみ有効になります。ストリーミング出力モードでトークン数をカウントする場合は、このパラメーターを |
max_tokens | integer | いいえ | 2048 | モデルが生成できるトークンの最大数。 |
frequency_penalty | integer or null | いいえ | 0 | 正の値は、テキストによく出現する新しい単語に対してモデルにペナルティを課すために使用されます。これにより、モデルが同じテキスト行を繰り返し生成する可能性が低くなります。有効な値:[-2.0, 2.0]。 |
presence_penalty | float | いいえ | 0 | テキストに既に表示されているコンテンツに対してモデルにペナルティを課します。このパラメーターを大きな値に設定すると、テキストに既に表示されているコンテンツが生成される可能性を低くすることができます。有効な値:[-2.0, 2.0]。 |
seed | integer | いいえ | なし | コンテンツ生成中に使用されるランダムシード。このパラメーターは、生成されるコンテンツのランダム性を制御します。有効な値:符号なし 64 ビット整数。 |
stop | string or array | いいえ | なし | このパラメーターを文字列またはトークン ID に設定すると、モデルは文字列またはトークン ID が生成される前にコンテンツの生成を停止します。このパラメーターは、コンテンツ生成プロセスを正確に制御するのに役立ちます。 |
tools | array | いいえ | なし | モデルが呼び出すことができるツールのリスト。モデルは、各関数呼び出し中にツールリストからツールを呼び出します。 |
tool_choice | string or object | いいえ | なし | モデルが呼び出すことができるツール。 |
parallel_tool_calls | object | いいえ | True | ツールを使用するときに並列関数呼び出し機能を有効にするかどうかを指定します。 |
user | string | いいえ | なし | ユーザー識別子。 |
logit_bias | map | いいえ | なし | モデルが特定のラベルを生成する可能性。 |
logprobs | boolean | いいえ | False | 各出力ラベルの対数確率を返すかどうかを指定します。有効な値:
|
top_logprobs | integer | いいえ | なし | 各ラベル付き位置から返すことができるラベルの最大数。各ラベルには対数確率があります。有効な値:0~20。このパラメーターを構成する場合は、logprobs パラメーターを True に設定する必要があります。 |
n | integer | いいえ | 1 | 各入力メッセージに対して生成されるチャット補完オプションの数。 |
response_format | object | いいえ | {"type": "text"} | モデルが返さなければならないオブジェクトの形式。有効な値:
|
service_tier | string | いいえ | なし | リクエストの処理に使用されるレイテンシー層。 |
messages パラメーター
messages パラメーターは、判定モデルが受信した情報を指定します。次のサンプルコードは例を示しています。
messages=[
{
"role": "user", // ユーザー
"content": [
{
"mode": "single", // single
"type": "json", // json
"json": {
"question": "Provide the second couplet to \"To climb the mountain, reach the peak\"", // 「山に登り、頂上に到達する」の下の句を提供する
"answer": "To cross the river, find the creek" // 川を渡り、小川を見つける
}
}
]
}
]messages パラメーターは配列形式です。各要素は {"role":role, "content": 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 の内容は、テンプレートの対応する位置に自動的に入力されます。
単一モデル評価リクエストテンプレート
Your task is to evaluate the quality of an AI assistant's answer. // あなたのタスクは、AI アシスタントの回答の品質を評価することです。
You clearly understand that when a user provides a question about the [${scene}] scenario (defined as: ${scene_desc}), an AI assistant's answer should meet the following criteria (listed in order of importance from highest to lowest): // ユーザーが[${scene}]シナリオ(定義:${scene_desc})に関する質問をした場合、AI アシスタントの回答は次の基準を満たす必要があることを明確に理解しています(重要度の高い順にリストされています)。
[Start of criteria] // [基準の開始]
${metric} // ${metric}
[End of criteria] // [基準の終了]
The scoring system uses a ${max_score}-level scale (1-${max_score}), with each score level defined as follows: // スコアリングシステムは${max_score}レベルスケール(1-${max_score})を使用し、各スコアレベルは次のように定義されます。
[Start of score description] // [スコアの記述の開始]
${score_desc} // ${score_desc}
[End of score description] // [スコアの記述の終了]
We have collected the following answer from an AI assistant to a user question. // ユーザーの質問に対する AI アシスタントからの次の回答を収集しました。
Please comprehensively evaluate the answer based on the criteria that you use for the current scenario. The following items describe the question and answer from an AI assistant: // 現在のシナリオで使用する基準に基づいて、回答を総合的に評価してください。次の項目では、AI アシスタントからの質問と回答について説明します。
[Start of data] // [データの開始]
***
[User question]: ${question} // [ユーザーの質問]: ${question}
***
[Answer]: ${answer} // [回答]: ${answer}
***
[Reference answer]: ${ref_answer} // [参照回答]: ${ref_answer}
***
[End of data] // [データの終了]
You must evaluate the preceding answer based on the following process: // 次のプロセスに基づいて上記の回答を評価する必要があります。
${steps} // ${steps}
Think carefully and then provide your conclusion. // よく考えてから結論を出してください。デュアルモデルコンペティションリクエストテンプレート
Your task is to evaluate the quality of AI assistants' answers. // あなたのタスクは、AI アシスタントの回答の品質を評価することです。
You clearly understand that when a user provides a question about the [${scene}] scenario (defined as: ${scene_desc}), an AI assistant's answer should meet the following criteria (listed in order of importance from highest to lowest): // ユーザーが[${scene}]シナリオ(定義:${scene_desc})に関する質問をした場合、AI アシスタントの回答は次の基準を満たす必要があることを明確に理解しています(重要度の高い順にリストされています)。
[Start of criteria] // [基準の開始]
${metric} // ${metric}
[End of criteria] // [基準の終了]
The scoring system uses a ${max_score}-level scale (1-${max_score}), with each score level defined as follows: // スコアリングシステムは${max_score}レベルスケール(1-${max_score})を使用し、各スコアレベルは次のように定義されます。
[Start of score description] // [スコアの記述の開始]
${score_desc} // ${score_desc}
[End of score description] // [スコアの記述の終了]
For a user question in the [${scene}] scenario, we have collected answers from two AI assistants. // [${scene}]シナリオのユーザーの質問に対して、2 人の AI アシスタントから回答を収集しました。
Please comprehensively evaluate the answers and determine which answer is better or whether the quality of the two answers is the same based on the criteria that you use for the current scenario. The following items describe a question and the answers from the AI assistants: // 現在のシナリオで使用する基準に基づいて、回答を総合的に評価し、どちらの回答が優れているか、または 2 つの回答の品質が同じかどうかを判断してください。次の項目では、質問と AI アシスタントからの回答について説明します。
[Start of data] // [データの開始]
***
[User question]: ${question} // [ユーザーの質問]: ${question}
***
[Answer 1]: ${answer1} // [回答 1]: ${answer1}
***
[Answer 2]: ${answer2} // [回答 2]: ${answer2}
***
[Reference answer]: ${ref_answer} // [参照回答]: ${ref_answer}
***
[End of data] // [データの終了]
You must evaluate and compare the two answers based on the following process: // 次のプロセスに基づいて 2 つの回答を評価および比較する必要があります。
{steps} // {steps}
Think carefully and then provide your conclusion. // よく考えてから結論を出してください。${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 | リクエスト中に消費されたトークンの数。 |
usage.prompt_tokens | integer | 入力テキストから変換されたトークンの数。 |
usage.completion_tokens | integer | モデルによって生成されたレスポンスから変換されたトークンの数。 |
usage.total_tokens | integer | usage.prompt_tokens パラメーターと usage.completion_tokens パラメーターによって返される値の合計。 |
ステータスコード
ステータスコード | コード | エラーメッセージ | 説明 |
200 | OK | なし | リクエストは成功しました。 |
400 | MessagesError | "messages" not in body or type of "messages" is not list. | messages パラメーターを空にすることはできません。 原因は、messages パラメーターの値の形式が無効である可能性があります。値はリスト形式である必要があります。 |
400 | ContentError | Content should be like: {"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 パラメーターを次のいずれかの値に設定する必要があります。
|
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. | トークンが無効です。 |
402 | InvalidBody | json load request body error | リクエスト本文が 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 | ストリーミング出力モードで判定モデルの呼び出しに失敗しました。 |
ファイル
ファイルをアップロードする: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"), // /home/xxx/input.jsonl purpose="batch", // 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" // -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", // batch order="desc", // desc limit=10, // 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
いいえ
ファイルの用途。
バッチ処理用の API ファイルのみがサポートされています。
デフォルト値:10000。
order
string
いいえ
created_at パラメーターを使用してクエリ結果をソートする順序。
asc
desc (デフォルト)
after
string
いいえ
ページネーション用のカーソル。このパラメーターは、クエリ結果の位置を示すオブジェクト ID を定義します。たとえば、リクエストを送信して obj_foo で終わる 100 個のオブジェクトを受信した場合、後続の呼び出しで after を obj_foo に設定して、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", // 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
バッチ処理用のファイルのみがサポートされています。
リクエスト例
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", // 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 // 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-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} // {"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", // 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 | ファイルの用途。 |
バッチ
バッチタスクを作成する: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", // /v1/chat/completions input_file_id="file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", // file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713 completion_window="24h", // 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", // "input_file_id": "file-batch-EC043540BE1C7BE3F9F2F0A8F47D1713", "endpoint": "/v1/chat/completions", // "endpoint": "/v1/chat/completions", "completion_window": "24h" // "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", // 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
はい
.jsonl ファイルとしてフォーマットされ、ターゲットバッチタスクでアップロードする必要があるファイルの ID。ファイルには最大 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", // batch_66f245a0-88d1-458c-8e1c-a819a5943022 limit=10, // 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", // 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
いいえ
ページネーション用のカーソル。このパラメーターは、クエリ結果の位置を示すオブジェクト ID を定義します。たとえば、リクエストを送信して obj_foo で終わる 100 個のオブジェクトを受信した場合、後続の呼び出しで after を obj_foo に設定して、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", // 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", // 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
はい
バッチタスクの 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", // 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", // 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
はい
バッチタスクの 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
はい
バッチタスクの ID。
レスポンスパラメーター
パラメーター
タイプ
説明
id
string
バッチタスクの ID。
object
string
削除されたバッチタスクのタイプ。
deleted
string
バッチタスクが削除されたかどうかを示します。
バッチタスクの説明
パラメーター | タイプ | 説明 |
id | string | 削除されたバッチタスクの ID。 |
object | string | 削除されたバッチタスクのタイプ。 |
endpoint | string | データエンドポイント。 |
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 | メタデータ。 |