create https://github.com/openai/openai-python/blob/main/src/openai/resources/chat/completions.py#L30

parse

1. seedtemperature

위 파일에 있는 create 힘수의 docstring을 보면 다음과 같이 설명되어 있다. (parse도 동일)

temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
make the output more random, while lower values like 0.2 will make it more
focused and deterministic. We generally recommend altering this or top_p but
not both.

seed: This feature is in Beta. If specified, our system will make a best effort to
sample deterministically, such that repeated requests with the same seed and
parameters should return the same result. Determinism is not guaranteed, and you
should refer to the system_fingerprint response parameter to monitor changes
in the backend.

즉, temperaturecreate 함수의 인자로 넘겨줄 수 있지만, seed 고정은 아직 안정적으로 동작하지 않는다.

추후에 다음과 같이 수정할 수 있다.

from openai import OpenAI

client = OpenAI()

inference = client.chat.completions.create(
		model=model_name,   # "solar-pro"
		messages=built_message,
		seed=42,
		temperature=0,
		response_format=SOME_FORMAT,
)

2. response_format vs JsonOutputParser

create, parse의 내부 구현은 공개되지 않았다ㅠㅠ 하지만, 모듈 구조와 의존성을 뜯어보니 API 요청 시에 로직이 다른 듯?

JsonOutputParser는 포맷을 Pydantic으로 선언하지 않은 경우, 프롬프트 끝에 특정 문자열을 붙여서 LLM 입력으로 보내는 것 같다. 그래서 버그가 많이 발생했던 것 같다.

JsonOutputParser를 사용하지 않고, 굳이 response_format로 사용하는 이유는 JsonOutputParser가 어떻게 잘못 동작할지 예측할 수 없기 때문이다. 특히 key 문자열이 예상치 못한 값으로 포맷팅되어 출력되면 출력을 컨트롤하기 어렵다.

response_format={
    "type": "json_schema",
    "json_schema": {
        "name": "email_summary_creation",
        "strict": True,
        "schema": {
            "type": "object",
            "properties": {
                "final_report": {
                    "type": "string",
                    "description": "The finalized version of the email summary report with improvements applied."
                }
            },
            "required": ["final_report"]
        },
    },
}