次の方法で共有


微調整とツール呼び出し

チャット補完 API を使用するモデルは、 ツール呼び出しをサポートします。 残念ながら、チャット補完呼び出しで定義されている関数は、期待どおりに動作しないことがあります。 ツール呼び出し例を使用してモデルを微調整すると、次の機能を使用してモデルの出力を向上させることができます。

  • 完全な関数定義が存在しない場合でも、同様の形式が設定された応答を取得します。 (プロンプト トークンのコストを節約できる可能性があります。)
  • より正確で一貫性のある出力を取得します。

function_call functionsは、toolsを優先して非推奨となりました。 代わりに tools パラメーターを使用することをお勧めします。

トレーニング ファイルの構築

例を呼び出すツールのトレーニング ファイルを作成するときは、次のような関数定義を使用します。

{
    "messages": [
        { "role": "user", "content": "What is the weather in San Francisco?" },
        {
            "role": "assistant",
            "tool_calls": [
                {
                    "id": "call_id",
                    "type": "function",
                    "function": {
                        "name": "get_current_weather",
                        "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"
                    }
                }
            ]
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_current_weather",
                "description": "Get the current weather",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and country, eg. San Francisco, USA"
                        },
                        "format": { "type": "string", "enum": ["celsius", "fahrenheit"] }
                    },
                    "required": ["location", "format"]
                }
            }
        }
    ]
}

また、次のように .jsonl トレーニング ファイル内で情報を 1 行で表現します。

{"messages":[{"role":"user","content":"What is the weather in San Francisco?"},{"role":"assistant","tool_calls":[{"id":"call_id","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}}]}],"tools":[{"type":"function","function":{"name":"get_current_weather","description":"Get the current weather","parameters":{"type":"object","properties":{"location":{"type":"string","description":"The city and country, eg. San Francisco, USA"},"format":{"type":"string","enum":["celsius","fahrenheit"]}},"required":["location","format"]}}}]}

すべてのファインチューニング トレーニングと同様に、サンプルファイルには少なくとも10個の例が必要です。

コストを最適化する

完全な関数定義でモデルをファインチューニングした後、使用するプロンプト トークンを減らすために最適化しようとしている場合、OpenAI は次を試すことを推奨しています。

  • 関数とパラメーターの説明を省略する: 関数とパラメーターから説明フィールドを削除します。
  • パラメーターを省略する: パラメーター オブジェクトからプロパティ フィールド全体を削除します。
  • 関数全体を省略する: 関数配列から関数オブジェクト全体を削除します。

品質を最適化する

または、ツール呼び出し出力の品質を向上させる場合は、微調整トレーニング データセットに存在する関数定義と、後続のチャット完了呼び出しは同じままにすることをお勧めします。

関数出力に対するモデルの応答をカスタマイズする

ツール呼び出しの例に基づく微調整を使用して、関数の出力に対するモデルの応答を向上させることもできます。 これを実現するには、関数の応答メッセージとアシスタントの応答メッセージから構成される例を含めます。それにより、アシスタントによって関数の応答が解釈され、コンテキストに配置されます。

{
    "messages": [
        {"role": "user", "content": "What is the weather in San Francisco?"},
        {"role": "assistant", "tool_calls": [{"id": "call_id", "type": "function", "function": {"name": "get_current_weather", "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}}]}
        {"role": "tool", "tool_call_id": "call_id", "content": "21.0"},
        {"role": "assistant", "content": "It is 21 degrees celsius in San Francisco, CA"}
    ],
    "tools": [] // same as before
}

前の例と同様に、この例も読みやすくするために人為的に拡張されています。 .jsonl トレーニング ファイルの実際のエントリは 1 行になります。

{"messages":[{"role":"user","content":"What is the weather in San Francisco?"},{"role":"assistant","tool_calls":[{"id":"call_id","type":"function","function":{"name":"get_current_weather","arguments":"{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}}]},{"role":"tool","tool_call_id":"call_id","content":"21.0"},{"role":"assistant","content":"It is 21 degrees celsius in San Francisco, CA"}],"tools":[]}

関数呼び出し

トレーニング ファイルの構築

関数呼び出しの例のトレーニング ファイルを構築する場合は、次のような関数定義を使用します。

{
    "messages": [
        {"role": "user", "content": "What is the weather in San Francisco?"},
        {"role": "assistant", "function_call": {"name": "get_current_weather", "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}
    ],
    "functions": [{
        "name": "get_current_weather",
        "description": "Get the current weather",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {"type": "string", "description": "The city and country, eg. San Francisco, USA"},
                "format": {"type": "string", "enum": ["celsius", "fahrenheit"]}
            },
            "required": ["location", "format"]
        }
    }]
}

また、次のように .jsonl トレーニング ファイル内で情報を 1 行で表現します。

{"messages": [{"role": "user", "content": "What is the weather in San Francisco?"}, {"role": "assistant", "function_call": {"name": "get_current_weather", "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"}}], "functions": [{"name": "get_current_weather", "description": "Get the current weather", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "The city and country, eg. San Francisco, USA"}, "format": {"type": "string", "enum": ["celsius", "fahrenheit"]}}, "required": ["location", "format"]}}]}

すべてのファインチューニング トレーニングと同様に、サンプルファイルには少なくとも10個の例が必要です。

コストを最適化する

完全な関数定義でモデルをファインチューニングした後、使用するプロンプト トークンを減らすために最適化しようとしている場合、OpenAI は次を試すことを推奨しています。

  • 関数とパラメーターの説明を省略する: 関数とパラメーターから説明フィールドを削除します。
  • パラメーターを省略する: パラメーター オブジェクトからプロパティ フィールド全体を削除します。
  • 関数全体を省略する: 関数配列から関数オブジェクト全体を削除します。

品質を最適化する

関数呼び出し出力の品質を向上させようとしている場合は、ファインチューニング トレーニング データセットに存在する関数定義と、その後のチャットの完了呼び出しを同一に保つことが推奨されます。

関数出力に対するモデルの応答をカスタマイズする

関数呼び出しの例に基づくファインチューニングを使用して、関数出力に対するモデルの応答を改善することもできます。 これを実現するには、関数の応答メッセージとアシスタントの応答メッセージから構成される例を含めます。それにより、アシスタントによって関数の応答が解釈され、コンテキストに配置されます。

{
    "messages": [
        {"role": "user", "content": "What is the weather in San Francisco?"},
        {"role": "assistant", "function_call": {"name": "get_current_weather", "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celcius\"}"}}
        {"role": "function", "name": "get_current_weather", "content": "21.0"},
        {"role": "assistant", "content": "It is 21 degrees celsius in San Francisco, CA"}
    ],
    "functions": [...] // same as before
}

前の例と同様に、この例も読みやすくするために人為的に拡張されています。 .jsonl トレーニング ファイルの実際のエントリは 1 行になります。

{"messages": [{"role": "user", "content": "What is the weather in San Francisco?"}, {"role": "assistant", "function_call": {"name": "get_current_weather", "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celcius\"}"}}, {"role": "function", "name": "get_current_weather", "content": "21.0"}, {"role": "assistant", "content": "It is 21 degrees celsius in San Francisco, CA"}], "functions": []}

次のステップ