다음을 통해 공유


미세 조정 및 함수 호출

채팅 완료 API를 사용하는 모델은 함수 호출을 지원합니다. 안타깝게도 채팅 완료 호출에 정의된 함수가 항상 예상대로 수행되는 것은 아닙니다. 함수 호출 예제를 사용하여 모델을 미세 조정하면 다음을 수행하여 모델 출력을 향상시킬 수 있습니다.

  • 전체 함수 정의가 없는 경우에도 비슷한 형식의 응답을 가져옵니다. (프롬프트 토큰에 비용을 절감할 수 있습니다.)
  • 더 정확하고 일관된 출력을 가져옵니다.

Important

functions API 버전 릴리스에서는 매개 변수와 function_call 매개 변수가 2023-12-01-preview 더 이상 사용되지 않습니다. 그러나 미세 조정 API는 현재 레거시 매개 변수를 사용해야 합니다.

학습 파일 생성

함수 호출 예제의 학습 파일을 생성할 때 다음과 같은 함수 정의를 사용합니다.

{
    "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 .

{"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 실제 항목은 한 줄입니다.

{"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": []}

다음 단계