(참고: open API를 이용한 custom GPT는 불가능함, 내부 api로 외부데이터 연동은 가능)

1. OpenAI 플랫폼에서 Custom GPT 생성하기

Custom GPT를 설정하려면 OpenAI 플랫폼에서 새로운 Custom GPT를 생성해야 합니다.

1.1. OpenAI 플랫폼 접속

  1. OpenAI Custom GPT 페이지로 이동
  2. 로그인 후 상단의 My GPTs 메뉴 클릭
  3. "Create a GPT" 버튼을 클릭하여 새로운 Custom GPT 생성 시작

2. Custom GPT 설정 과정

Custom GPT는 OpenAI의 Guided Setup을 통해 설정할 수 있습니다.
이 과정에서는 GPT의 성격, 역할, 학습 데이터, API 기능 설정을 조정할 수 있습니다.

2.1. 기본 정보 입력

  • GPT의 이름 설정 → (예: "채권 전문가 GPT")
  • 설명 입력 → (예: "이 GPT는 채권 회수 및 법률 상담을 위한 맞춤형 AI입니다.")

2.2. 역할 및 동작 방식 정의 (Instructions)

Custom GPT의 동작 방식을 정의하는 가장 중요한 과정입니다.

✅ "Instructions" 탭에서 설정할 내용

  1. Assistant Instructions
    → GPT가 어떻게 행동해야 하는지 설명
  2. text
    복사편집
    당신은 금융 및 법률 전문가로서 채권 회수와 관련된 법률 상담을 제공합니다. 사용자의 질문에 대해 구체적인 법률 조항을 참조하며, 금융 기관의 실무적인 조언을 제공합니다.
  3. User Instructions
    → 사용자가 Custom GPT를 어떻게 사용할지 안내
  4. text
    복사편집
    질문을 작성할 때, 관련된 법률 조항이나 금융 용어를 포함해 주세요. 예시: "대여금 반환 청구 소송을 진행하려면 어떤 절차를 따라야 하나요?"

2.3. 추가적인 데이터 업로드 (Knowledge)

사용자가 Custom GPT에 대한 추가 정보를 제공할 수도 있습니다.

  • FAQ 데이터 업로드 (CSV, JSON 형식)
  • PDF, 텍스트 문서 업로드 (예: 회사 내부 지침, 법률 문서 등)

예시:

  • 금융 기관의 채권 회수 정책을 포함한 PDF 파일 업로드
  • 법률 상담 시 자주 묻는 질문(FAQ) 데이터 업로드

2.4. API 호출 및 도구 사용 설정 (Actions)

Custom GPT는 API 호출 및 외부 도구(Functions)와 연동할 수도 있습니다.

  • 예를 들어, Spring Boot API, Google 검색, 데이터베이스 API 등을 호출 가능

예제:

{
  "name": "채권 회수 API",
  "description": "고객의 채권 정보를 조회하고 법률 절차를 안내합니다.",
  "parameters": {
    "채권자명": {
      "type": "string",
      "description": "채권자의 이름"
    },
    "채무자명": {
      "type": "string",
      "description": "채무자의 이름"
    }
  }
}

이 기능을 활용하면 API를 직접 호출하여 최신 정보를 제공하는 Custom GPT를 만들 수 있습니다.


3. Custom GPT를 API에서 호출하는 방법

Custom GPT를 OpenAI API에서 사용하려면, API에서 model 값을 Custom GPT ID로 변경하면 됩니다.

✅ Custom GPT API 호출 예제 (Java)

import okhttp3.*;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.IOException;

@Service
public class OpenAICustomService {
    private static final String API_URL = "https://api.openai.com/v1/chat/completions";
    private final OkHttpClient client = new OkHttpClient();

    @Value("${openai.api.key}")
    private String apiKey;

    @Value("${openai.custom.gpt.id}") // Custom GPT ID (예: gpt-4-custom-XXXXX)
    private String customGptId;

    public String getCustomGptResponse(String userInput) throws IOException {
        String json = "{"
                + "\"model\":\"" + customGptId + "\","
                + "\"messages\":[{\"role\":\"user\",\"content\":\"" + userInput + "\"}],"
                + "\"temperature\":0.7"
                + "}";

        RequestBody body = RequestBody.create(json, MediaType.get("application/json"));

        Request request = new Request.Builder()
                .url(API_URL)
                .header("Authorization", "Bearer " + apiKey)
                .header("Content-Type", "application/json")
                .post(body)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }

            ObjectMapper mapper = new ObjectMapper();
            JsonNode rootNode = mapper.readTree(response.body().string());
            return rootNode.get("choices").get(0).get("message").get("content").asText();
        }
    }
}

설정 완료 후 API에서 Custom GPT를 호출하면, 사전에 설정한 역할, 동작 방식, 지식 등을 반영한 응답을 반환합니다.


4. 결론

OpenAI API에서 Custom GPT를 사용하려면 먼저 OpenAI 플랫폼에서 설정이 필요합니다.
사전 설정을 통해 특정한 업무(법률, 금융, IT 등)에 최적화된 GPT를 만들 수 있습니다.
API에서 model 값을 Custom GPT ID로 변경하면 사전 설정이 반영된 맞춤형 응답을 받을 수 있습니다.

 

 

5. customGptId 조회 방식

curl https://api.openai.com/v1/models \
  -H "Authorization: Bearer YOUR_OPENAI_API_KEY"

 

 

 

6. custom GPT 구성(Config)

- 우측 큰화면의 상단에 GPT제목을 누르고, 편집을 누른 후, "구성"탭에서 설정.

인증형식은 API key로 하고, https://platform.openai.com/ 에서 카드설정+발급받은 키를 이용하게 되며,
인증방식은 기본이 아닌->  "Bearer" 로 설정하는게 편함.

 

심플 get용 스키마:

{
  "openapi": "3.1.0",
  "info": {
    "title": "간단한 GET API",
    "description": "GET 요청을 받아 텍스트를 반환하는 API",
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "https://api.example.com"
    }
  ],
  "paths": {
    "/hello": {
      "get": {
        "summary": "텍스트 반환",
        "operationId": "getHello",
        "responses": {
          "200": {
            "description": "성공적인 응답",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string",
                  "example": "Hello, GPT!"
                }
              }
            }
          }
        }
      }
    }
  }
}

 

 

post용 스키마:

{
  "openapi": "3.1.0",
  "info": {
    "title": "채권 조회 API",
    "description": "채권자 및 채무자 정보를 입력하면 채권 상태를 반환합니다.",
    "version": "v1.0.0"
  },
  "servers": [
    {
      "url": "https://api.example.com"
    }
  ],
  "paths": {
    "/getDebtStatus": {
      "post": {
        "summary": "채권 상태 조회",
        "operationId": "getDebtStatus",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DebtRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "채권 상태 응답",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DebtResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "DebtRequest": {
        "type": "object",
        "properties": {
          "채권자명": {
            "type": "string",
            "description": "채권자의 이름"
          },
          "채무자명": {
            "type": "string",
            "description": "채무자의 이름"
          }
        },
        "required": ["채권자명", "채무자명"]
      },
      "DebtResponse": {
        "type": "object",
        "properties": {
          "결과": {
            "type": "string",
            "description": "응답 상태 (성공 또는 실패)"
          },
          "채권 상태": {
            "type": "string",
            "description": "채권의 현재 상태 (예: 연체, 회수 완료 등)"
          },
          "회수 가능 금액": {
            "type": "number",
            "description": "현재 회수 가능한 금액 (원화 기준)"
          }
        }
      }
    }
  }
}
Posted by yongary
,