🤖 AI/ML

GPT-4

GPT-4

OpenAI's latest large language model. Features multimodal capabilities and improved reasoning.

📖 Detailed Explanation

GPT-4 is a large multimodal language model released by OpenAI in March 2023, capable of accepting both text and images as input. The exact number of parameters has not been disclosed, but it is estimated to be a Mixture of Experts (MoE) architecture with 1.7 trillion parameters, in which 2 of 8 experts are activated at a time.

GPT-4 shows significantly improved performance over GPT-3.5 on a variety of benchmarks. It scored in the top 10% on the U.S. bar exam (GPT-3.5 scored in the bottom 10%), 700 on SAT Math (GPT-3.5: 590), and 67% on HumanEval for coding ability (GPT-3.5: 48%).

GPT-4 Turbo supports a 128K context window, allowing it to process about 300 pages of text at once. It also provides developer-friendly features such as JSON mode, Function Calling, and Reproducible outputs based on seeds. It costs 3 times less than GPT-4.

In practice, GPT-4 is mainly used for complex reasoning, code generation, document analysis, and multimodal tasks. Using the Vision feature, chart analysis, UI design review, and image-based QA are possible, and when combined with the Assistants API, advanced agent features such as RAG and Code Interpreter can be implemented.

💻 Code Example

from openai import OpenAI
import base64

client = OpenAI(api_key="your-api-key")

# GPT-4 Turbo with Vision (이미지 분석)
def analyze_image(image_path: str, question: str) -> str:
    with open(image_path, "rb") as f:
        image_data = base64.standard_b64encode(f.read()).decode("utf-8")

    response = client.chat.completions.create(
        model="gpt-4-turbo",
        messages=[{
            "role": "user",
            "content": [
                {"type": "text", "text": question},
                {"type": "image_url", "image_url": {
                    "url": f"data:image/jpeg;base64,{image_data}",
                    "detail": "high"  # low, high, auto
                }}
            ]
        }],
        max_tokens=1000
    )
    return response.choices[0].message.content

# 재현 가능한 출력 (seed 사용)
response = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[{"role": "user", "content": "Generate a haiku about coding."}],
    seed=42,
    temperature=1
)
print(f"System fingerprint: {response.system_fingerprint}")

# JSON 모드 활용
response = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[
        {"role": "system", "content": "Extract entities as JSON with keys: persons, organizations, locations"},
        {"role": "user", "content": "Apple CEO Tim Cook announced new products in Cupertino."}
    ],
    response_format={"type": "json_object"}
)
import json
entities = json.loads(response.choices[0].message.content)

# Assistants API with Code Interpreter
assistant = client.beta.assistants.create(
    name="Data Analyst",
    instructions="You analyze data and create visualizations.",
    model="gpt-4-turbo",
    tools=[{"type": "code_interpreter"}]
)

thread = client.beta.threads.create()
client.beta.threads.messages.create(
    thread_id=thread.id,
    role="user",
    content="Analyze the attached CSV and plot sales trends."
)

run = client.beta.threads.runs.create_and_poll(
    thread_id=thread.id,
    assistant_id=assistant.id
)

# 긴 문서 처리 (128K 컨텍스트)
with open("long_document.txt", "r") as f:
    long_text = f.read()  # 최대 ~300페이지

response = client.chat.completions.create(
    model="gpt-4-turbo",
    messages=[
        {"role": "system", "content": "Summarize the key points of this document."},
        {"role": "user", "content": long_text}
    ],
    max_tokens=2000
)

📊 Performance & Cost

This is API pricing information for OpenAI GPT-4 family models as of January 2025.

Model Input (1M tokens) Output (1M tokens) Context
GPT-4o $2.50 ~ $5.00 $10.00 ~ $15.00 128K tokens
GPT-4o-mini $0.15 $0.60 128K tokens
GPT-4 Turbo $10.00 $30.00 128K tokens

Cost optimization: GPT-4o-mini is 60% cheaper than GPT-3.5 Turbo while offering improved performance. Routing simple tasks to mini and complex reasoning to GPT-4o is recommended.

🗣️ Say It Like This in Practice

Technical interview scenario

"What are the differences between GPT-4 and Claude 3?" - "GPT-4's strengths are multimodality and function calling, while Claude 3 excels at 200K context and document analysis. Coding benchmarks are similar, but GPT-4 integrates easily with the OpenAI ecosystem (DALL-E, Whisper), and Claude has higher safety based on Constitutional AI. You should choose according to your use case."

Project meeting

"Can GPT-4 Vision analyze UI screenshots?" - "Yes, if you set detail to high, it recognizes UI elements accurately. In our project, we used it to analyze app screenshots and find accessibility issues, and it caught things like button contrast problems and touch target sizes well. However, the token cost per image is high, so use it selectively only where needed."

Code Review

"I fixed the seed to 42, so why are the results different?" - "The seed guarantees reproducibility only for the same system_fingerprint. When OpenAI updates the model, the fingerprint changes and the results may differ as well. In production, we recommend logging the fingerprint and caching important outputs."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

1
Vision token cost

Depending on resolution, image analysis consumes 85 to 1,105 tokens. detail=high uses more than 4 times as many tokens, so for bulk processing, consider detail=low or resizing images.

2
Context window limits

Even with a 128K context, performance degrades when the input is too long. Because of the Lost in the Middle phenomenon, information in the middle can be ignored, so place important information at the beginning or the end.

3
Model version management

gpt-4-turbo automatically points to the latest version and may change. In production, use a pinned version such as gpt-4-turbo-2024-04-09 to maintain consistency.

🔗 Related Terms

📚 Learn More