본문 바로가기
Other/Programming

ChatGPT VS Gemini API

by 해학 2025. 3. 16.
728x90
 
 

Programming

당위성을 비교

 

What ?

ChatGPT VS Gemini API

OpenAI에서 제공하는 API로, 주로 대규모 언어 모델(LLM)을 활용하여 자연어 처리를 합니다.

둘의 특징을 고려해서 적절한 상황에 사용합니다.


 Compare !

ChatGPT VS Gemini API
속성 ChatGPT GeminiAPI
주요 기능 자연어 처리
(대화, 요약, 분석 등)
복잡한 자연어 처리와 분석,
고급 데이터 인사이트 도출
모델 GPT-4 LLM (LLM+X) 모델
강점 대화형 분석, 요약,
간단한 데이터 처리
대규모 데이터 분석,
정교한 패턴 분석
적합한 사용 사례 로그 요약,
간단한 이슈 파악,
오류 설명
복잡한 로그 패턴 분석,
이상 탐지,
트렌드 분석
처리 속도 빠름 상대적으로 느리지만 깊이 있는 분석 가능
응답 품질 자연어에 강함,
데이터 요약 능력 우수
자연어 처리뿐 아니라
데이터 분석 능력도 탁월

What ?

ChatGPT

 

간단한 로그 요약: "최근 로그 데이터를 요약해서 이슈를 파악해줘."

에러 메시지 분석: "로그에 있는 에러의 원인을 설명해줘."

대화형 질의응답: "어떤 페이지에서 오류가 많이 발생하나요?"

response = openai.ChatCompletion.create(
    model="gpt-4-turbo",
    messages=[{"role": "user", "content": "최근 로그를 요약해줘"}]
)
print(response['choices'][0]['message']['content'])

 

JSON 형태로 정리된 로그 데이터 : 각 로그 이벤트를 객체로 묶어 구조화하여 전달합니다.

{
  "timestamp": "2025-03-20T12:05:21Z",
  "user_id": "12345",
  "action": "page_view",
  "page": "/home",
  "duration": 15
}

요약 또는 텍스트 기반 로그 데이터 : 원시 로그보다는 정제된 로그가 더 효율적입니다.

  • 예: "사용자 12345가 /home 페이지에서 15초 체류 후 /product로 이동했습니다." 

자연어 설명이 포함된 데이터 : 데이터가 무엇을 의미하는지 자연어로 설명합니다.

  • 예: "2025-03-20 12:05:21에 사용자 12345가 /home 페이지에 접속했습니다.

What ?

Gemini API

대규모 로그 패턴 분석: 여러 일자나 서비스의 로그를 비교 분석

이상 탐지 및 인사이트 도출: 예측 불가능한 패턴 파악

트렌드 분석: 사용자 행동 변화나 오류 증가 경향 분석

response = openai.ChatCompletion.create(
    model="gemini-1",
    messages=[{"role": "user", "content": "대규모 로그 데이터를 분석하고 트렌드를 파악해줘"}]
)
print(response['choices'][0]['message']['content'])

 

문장 구조를 갖춘 자연어 로그 설명 : "사용자가 특정 페이지에서 머문 시간과 이동 경로를 분석해 주세요."

대화형 질의응답을 위한 형태 : "다음 로그에서 사용자 행동 패턴을 파악하고 UX 개선 방안을 제안해 주세요."

구조화된 데이터 + 자연어 해석 : JSON과 함께 추가로 요약 문구를 넣어 의미를 명확히 전달합니다.

{
  "description": "최근 사용자 행동 로그입니다. 페이지 이동과 체류 시간을 분석하여 UX 개선점을 도출해 주세요.",
  "logs": [
    {
      "timestamp": "2025-03-20T12:05:21Z",
      "user_id": "12345",
      "action": "page_view",
      "page": "/home",
      "duration": 15
    },
    {
      "timestamp": "2025-03-20T12:05:36Z",
      "user_id": "12345",
      "action": "page_view",
      "page": "/product",
      "duration": 30
    },
    {
      "timestamp": "2025-03-20T12:06:10Z",
      "user_id": "67890",
      "action": "page_view",
      "page": "/contact",
      "duration": 5
    }
  ]
}

 

How ?

ChatGPT VS Gemini API

💡   공통 사항

// build.gradle
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'com.fasterxml.jackson.core:jackson-databind'
    implementation 'org.springframework.boot:spring-boot-starter-json'
    implementation 'org.apache.httpcomponents:httpclient:4.5.13'
}
// .env
api-key: "API_KEY"
// 요청 예시
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.client.RestTemplate;
import org.springframework.http.*;
import org.springframework.beans.factory.annotation.Value;

@Service
public class OpenAiService {

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

    private static final String API_URL = "https://api.openai.com/v1/chat/completions";

    public String callOpenAiApi(String model, String prompt) {
        try {
            RestTemplate restTemplate = new RestTemplate();
            HttpHeaders headers = new HttpHeaders();
            headers.set("Authorization", "Bearer " + apiKey);
            headers.setContentType(MediaType.APPLICATION_JSON);

            // JSON 형식의 로그 데이터
            String logData = "{\"timestamp\": \"2025-03-21T12:30:45Z\", \"user_id\": \"12345\", \"action\": \"page_view\", \"page\": \"/home\", \"duration\": 20, \"browser\": \"Chrome\", \"device\": \"Mobile\"}";

            // ChatGPT 요청 데이터
            String requestBody = String.format(
                "{\"model\": \"%s\", \"messages\": [{\"role\": \"user\", \"content\": \"다음 JSON 로그 데이터를 자연어로 분석해 주세요: %s\"}]}",
                model, logData
            );

            HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
            ResponseEntity<String> response = restTemplate.exchange(API_URL, HttpMethod.POST, entity, String.class);

            return response.getBody();
        } catch (Exception e) {
            e.printStackTrace();
            return "Error: " + e.getMessage();
        }
    }
}

 

💡   ChatGPT

curl "http://localhost:8080/api/openai/chatgpt?prompt=로그 데이터를 요약하고 문제점을 분석해 주세요."

 

💡   Gemini API

curl "http://localhost:8080/api/openai/gemini?prompt=로그 데이터를 분석하여 사용자 행동 패턴과 문제점을 도출해 주세요."

 


 

 

728x90

'Other > Programming' 카테고리의 다른 글

소프트 삭제를 안 쓰는 경우  (0) 2025.04.18
마이그레이션  (0) 2025.02.07
env  (0) 2025.02.04
Hash Table  (0) 2025.01.23
Map( )  (0) 2025.01.20