다음을 통해 공유


미세 조정 및 함수 호출

채팅 완료 API를 사용하는 모델은 함수 호출을 지원합니다. 불행하게도 채팅 완료 호출에 정의된 함수가 항상 예상대로 수행되는 것은 아닙니다. 함수 호출 예를 사용하여 모델을 미세 조정하면 다음을 통해 모델 출력을 개선할 수 있습니다.

  • 전체 함수 정의가 없는 경우에도 비슷한 형식의 응답을 가져옵니다. (잠재적으로 프롬프트 토큰에 대한 비용을 절약할 수 있습니다.)
  • 더욱 정확하고 일관된 결과를 가져오세요.

Important

functionsfunction_call 매개 변수는 API의 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": []}

다음 단계