OpenAI1 OpenAI API - Structured output 사용 시 json 파싱 제대로 안될 때. GPT API를 사용할 때, GPT에게 답변을 json 포맷으로 달라고 말하면서 schema를 명시적으로 선언해주는 것은 약간은 비효율적이다. 본문 내에 적어야하기 때문에 토큰도 소모하기도 하고..아래 모델 이후 모델부터는 response_format 파라미터를 통해서 출력형태를 직접 지정해줄 수 있다.from pydantic import BaseModelfrom openai import OpenAIclient = OpenAI()class CalendarEvent(BaseModel): name: str date: str participants: list[str]completion = client.beta.chat.completions.parse( model="gpt-4o-2024-0.. 2024. 10. 6. 이전 1 다음 반응형