Ver3.0 ๐ Python์ผ๋ก ChatGPT API ์ฐ๋ํ๊ธฐ: ์ด๋ณด์๋ ๋ฐ๋ผํ๋ ์๋ฒฝ ๊ฐ์ด๋

๐ Python์ผ๋ก ChatGPT API ์ฐ๋ํ๊ธฐ: ์ด๋ณด์๋ ๋ฐ๋ผํ๋ ์๋ฒฝ ๊ฐ์ด๋
AI ์ฑ๋ด์ ๋ด ํ๋ก๊ทธ๋จ์ ์ง์ ์ฐ๊ฒฐํด๋ณด์! ๐ฌโจ
๐ฏ ChatGPT API, ์ ๋ฐฐ์์ผ ํ ๊น?
์์ฆ AI ๊ธฐ์ ์ด ์ ๋ง ํซํ์์? ํนํ ChatGPT๋ ์ฐ๋ฆฌ ์ผ์์ ์์ ํ ๋
น์๋ค์์ด. ๊ทผ๋ฐ ์น์ฌ์ดํธ์ ์ ์ํด์ ๋ํํ๋ ๊ฒ๋ ์ข์ง๋ง, ๋ด๊ฐ ๋ง๋ ํ๋ก๊ทธ๋จ์ ์ง์ ChatGPT๋ฅผ ์ฐ๊ฒฐํ ์ ์๋ค๋ฉด ์ด๋จ๊น? ๐ค
์์ํด๋ด. ์๋์ผ๋ก ๊ณ ๊ฐ ๋ฌธ์์ ๋ต๋ณํ๋ ์ฑ๋ด, ๋ธ๋ก๊ทธ ๊ธ์ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ ๋๊ตฌ, ์ฌ์ง์ด ์ฝ๋ ๋ฆฌ๋ทฐ๋ฅผ ํด์ฃผ๋ ํ๋ก๊ทธ๋จ๊น์ง! ์ด ๋ชจ๋ ๊ฒ ChatGPT API๋ฅผ ํตํด ๊ฐ๋ฅํด. Python์ผ๋ก API๋ฅผ ์ฐ๋ํ๋ฉด ์ ๋ง ๋ฌด๊ถ๋ฌด์งํ ๊ฐ๋ฅ์ฑ์ด ์ด๋ฆฌ๋ ๊ฑฐ์ง.
์ด ๊ธ์์๋ ์์ ๊ธฐ์ด๋ถํฐ ์ค์ ํ์ฉ๊น์ง, ์น๊ตฌํํ
์ค๋ช
ํ๋ฏ์ด ์ฝ๊ฒ ์๋ ค์ค๊ฒ. ํ๋ก๊ทธ๋๋ฐ ๊ฒฝํ์ด ์กฐ๊ธ๋ง ์์ด๋ ์ถฉ๋ถํ ๋ฐ๋ผ์ฌ ์ ์์ผ๋๊น ๊ฑฑ์ ๋ง! ๐
๐ ์์ํ๊ธฐ ์ ์ ์์์ผ ํ ๊ฒ๋ค
๐ OpenAI API ํค ๋ฐ๊ธ๋ฐ๊ธฐ
ChatGPT API๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด ๋จผ์ OpenAI์์ API ํค๋ฅผ ๋ฐ๊ธ๋ฐ์์ผ ํด. ์ด๊ฑด ๋ง์น ์ง ์ด์ ๊ฐ์ ๊ฑฐ์ผ. ์ด ํค๊ฐ ์์ด์ผ OpenAI ์๋ฒ์ ์ ๊ทผํ ์ ์๊ฑฐ๋ .
๋ฐ๊ธ ๊ณผ์ ์ ์ด๋ ๊ฒ ์งํ๋ผ:
1. OpenAI ๊ณต์ ์น์ฌ์ดํธ(platform.openai.com)์ ์ ์
2. ํ์๊ฐ์
๋๋ ๋ก๊ทธ์ธ
3. API Keys ๋ฉ๋ด๋ก ์ด๋
4. "Create new secret key" ๋ฒํผ ํด๋ฆญ
5. ์์ฑ๋ ํค๋ฅผ ์์ ํ ๊ณณ์ ๋ณต์ฌํด์ ๋ณด๊ด
โ ๏ธ ์ค์! API ํค๋ ์ ๋ ๊ณต๊ฐ๋ ๊ณณ์ ์ฌ๋ฆฌ๋ฉด ์ ๋ผ. GitHub ๊ฐ์ ๊ณณ์ ์ค์๋ก ์ฌ๋ฆฌ๋ฉด ๋ค๋ฅธ ์ฌ๋์ด ๋์ ํค๋ก API๋ฅผ ์ฌ์ฉํด์ ์๊ธ์ด ํญํ์ฒ๋ผ ๋์ฌ ์ ์์ด!
๐ฐ ์๊ธ ์ฒด๊ณ ์ดํดํ๊ธฐ
ChatGPT API๋ ๋ฌด๋ฃ๊ฐ ์๋์ผ. ์ฌ์ฉํ ๋งํผ ๋์ ๋ด๋ ์ข
๋์ ๋ฐฉ์์ด์ง. ํ์ง๋ง ๊ฑฑ์ ๋ง! ํ
์คํธ ์ฉ๋๋ก๋ ์ ๋ง ์ ๋ ดํ๊ฑฐ๋ .
GPT-4o ๋ชจ๋ธ ๊ธฐ์ค์ผ๋ก:
โข ์
๋ ฅ ํ ํฐ(Input): 100๋ง ํ ํฐ๋น ์ฝ $2.50
โข ์ถ๋ ฅ ํ ํฐ(Output): 100๋ง ํ ํฐ๋น ์ฝ $10.00
ํ ํฐ์ด ๋ญ๋๊ณ ? ๊ฐ๋จํ ๋งํ๋ฉด ๋จ์ด ์กฐ๊ฐ์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋ผ. ์์ด๋ก "Hello, how are you?"๋ ๋๋ต 5๊ฐ ํ ํฐ ์ ๋์ผ. ํ๊ธ์ ์กฐ๊ธ ๋ ๋ง์ ํ ํฐ์ ์ฌ์ฉํ๋ ํธ์ด๊ณ .
์ค์ ๋ก ๊ฐ๋จํ ์ง๋ฌธ ํ๋ ๋ต๋ณ ๋ฐ๋ ๋ฐ ๋ช ์ผํธ๋ ์ ๋ค์ด. ์ฒ์ ์์ํ ๋๋ $5 ์ ๋๋ง ์ถฉ์ ํด๋ ์ถฉ๋ถํ ํ
์คํธํ ์ ์์ด! ๐ต
๐ Python ํ๊ฒฝ ์ค๋น
Python 3.7 ์ด์ ๋ฒ์ ์ด ์ค์น๋์ด ์์ด์ผ ํด. ์์ฆ์ ๋๋ถ๋ถ 3.9๋ 3.10 ๋ฒ์ ์ ์ฐ๋๊น ๋ฌธ์ ์์ ๊ฑฐ์ผ.
ํฐ๋ฏธ๋์ด๋ ๋ช
๋ น ํ๋กฌํํธ์์ ํ์ธํด๋ณด์:
python --version
๋๋
python3 --version
๋ฒ์ ์ด ์ ๋์ค๋ฉด ์ค๋น ์๋ฃ! ๐
๐ ๏ธ OpenAI ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์นํ๊ธฐ
์, ์ด์ ๋ณธ๊ฒฉ์ ์ผ๋ก ์์ํด๋ณผ๊น? ๋จผ์ OpenAI์์ ์ ๊ณตํ๋ ๊ณต์ Python ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํด์ผ ํด. ์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์์ผ๋ฉด API ํธ์ถ์ด ์ ๋ง ๊ฐ๋จํด์ ธ.
ํฐ๋ฏธ๋์ ์ด๊ณ ๋ค์ ๋ช
๋ น์ด๋ฅผ ์
๋ ฅํด:
pip install openai
๋ง์ฝ pip ๋์ pip3๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค๋ฉด:
pip3 install openai
์ค์น๊ฐ ์๋ฃ๋๋ฉด Python ์ธํฐํ๋ฆฌํฐ์์ ํ์ธํด๋ณผ ์ ์์ด:
python
>>> import openai
>>> print(openai.__version__)
๋ฒ์ ์ ๋ณด๊ฐ ๋์ค๋ฉด ์ฑ๊ณต! ์ต์ ๋ฒ์ ์ 1.x ๋์ผ ๊ฑฐ์ผ. ์ฐธ๊ณ ๋ก OpenAI ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ฒ์ 1.0 ์ดํ๋ก ์ฌ์ฉ๋ฒ์ด ๋ง์ด ๋ฐ๋์์ด. ์ด ๊ธ์์๋ ์ต์ ๋ฒ์ ๊ธฐ์ค์ผ๋ก ์ค๋ช ํ ๊ฒ. ๐ฆ
๐จ ์ฒซ ๋ฒ์งธ API ํธ์ถ: Hello, ChatGPT!
๋๋์ด ์ฝ๋๋ฅผ ์์ฑํ ์๊ฐ์ด์ผ! ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ์์ ๋ถํฐ ์์ํด๋ณด์. ์๋ก์ด Python ํ์ผ์ ๋ง๋ค๊ณ ๋ค์ ์ฝ๋๋ฅผ ์ ๋ ฅํด๋ด:
from openai import OpenAI
# API ํค ์ค์
client = OpenAI(api_key="์ฌ๊ธฐ์_๋์_API_ํค๋ฅผ_์
๋ ฅ")
# ChatGPT์๊ฒ ์ง๋ฌธํ๊ธฐ
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "์๋
! ๋๋ ๋๊ตฌ๋?"}
]
)
# ๋ต๋ณ ์ถ๋ ฅ
print(response.choices[0].message.content)
์ฝ๋๋ฅผ ์คํํ๋ฉด ChatGPT๊ฐ ์๊ธฐ์๊ฐ๋ฅผ ํด์ค ๊ฑฐ์ผ! ๐
์ฝ๋ ์ค๋ช
:
1. OpenAI ํด๋ผ์ด์ธํธ ์์ฑ
OpenAI(api_key="...")๋ก ํด๋ผ์ด์ธํธ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด. ์ด๊ฒ API์ ํต์ ํ๋ ํต์ฌ ๋๊ตฌ์ผ.
2. chat.completions.create() ๋ฉ์๋
์ด๊ฒ ์ค์ ๋ก ChatGPT์ ๋ํํ๋ ๋ถ๋ถ์ด์ผ. ์ฌ๋ฌ ํ๋ผ๋ฏธํฐ๋ฅผ ๋ฐ๋๋ฐ:
โข model: ์ฌ์ฉํ ๋ชจ๋ธ ์ง์ (gpt-4o-mini, gpt-4o, gpt-4-turbo ๋ฑ)
โข messages: ๋ํ ๋ด์ฉ์ ๋ด์ ๋ฆฌ์คํธ
3. messages ๊ตฌ์กฐ
๊ฐ ๋ฉ์์ง๋ ๋์
๋๋ฆฌ ํํ์ผ:
โข role: ๋๊ฐ ๋งํ๋์ง (system, user, assistant)
โข content: ์ค์ ๋ฉ์์ง ๋ด์ฉ
4. ์๋ต ์ฒ๋ฆฌ
response.choices[0].message.content์ ChatGPT์ ๋ต๋ณ์ด ๋ค์ด์์ด.
๐ API ํค ์์ ํ๊ฒ ๊ด๋ฆฌํ๊ธฐ
์๊น ๋งํ๋ฏ์ด API ํค๋ฅผ ์ฝ๋์ ์ง์ ๋ฃ์ผ๋ฉด ์ํํด. ํนํ GitHub ๊ฐ์ ๊ณณ์ ์ฌ๋ฆด ๋ ์ค์๋ก ํค๊ฐ ๋ ธ์ถ๋ ์ ์๊ฑฐ๋ . ์์ ํ๊ฒ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์์๋ณด์! ๐ก๏ธ
๋ฐฉ๋ฒ 1: ํ๊ฒฝ๋ณ์ ์ฌ์ฉํ๊ธฐ
๊ฐ์ฅ ์ผ๋ฐ์ ์ด๊ณ ์์ ํ ๋ฐฉ๋ฒ์ด์ผ. ์ด์์ฒด์ ์ ํ๊ฒฝ๋ณ์์ API ํค๋ฅผ ์ ์ฅํ๋ ๊ฑฐ์ง.
Windows์์:
set OPENAI_API_KEY=your_api_key_here
Mac/Linux์์:
export OPENAI_API_KEY=your_api_key_here
๊ทธ๋ฆฌ๊ณ Python ์ฝ๋์์๋ ์ด๋ ๊ฒ ๋ถ๋ฌ์:
import os
from openai import OpenAI
api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=api_key)
๋ฐฉ๋ฒ 2: .env ํ์ผ ์ฌ์ฉํ๊ธฐ
ํ๋ก์ ํธ๋ง๋ค ๋ค๋ฅธ ํค๋ฅผ ์ฌ์ฉํ๊ฑฐ๋, ํ์๋ค๊ณผ ํ์
ํ ๋ ํธ๋ฆฌํ ๋ฐฉ๋ฒ์ด์ผ.
๋จผ์ python-dotenv ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์น:
pip install python-dotenv
ํ๋ก์ ํธ ๋ฃจํธ์ .env ํ์ผ์ ๋ง๋ค์ด:
OPENAI_API_KEY=your_api_key_here
Python ์ฝ๋์์ ๋ถ๋ฌ์ค๊ธฐ:
from dotenv import load_dotenv
import os
from openai import OpenAI
load_dotenv() # .env ํ์ผ ๋ก๋
api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=api_key)
๋ฐฉ๋ฒ 3: ์ค์ ํ์ผ ์ฌ์ฉํ๊ธฐ
์ข ๋ ๋ณต์กํ ์ค์ ์ด ํ์ํ ๋๋ JSON์ด๋ YAML ํ์ผ์ ์ฌ์ฉํ ์๋ ์์ด.
config.json ํ์ผ:
{
"openai_api_key": "your_api_key_here",
"model": "gpt-4o-mini",
"temperature": 0.7
}
Python์์ ์ฝ๊ธฐ:
import json
from openai import OpenAI
with open('config.json', 'r') as f:
config = json.load(f)
client = OpenAI(api_key=config['openai_api_key'])
์ด ๋ฐฉ๋ฒ๋ config.json์ .gitignore์ ์ถ๊ฐํ๋ ๊ฑธ ์์ง ๋ง!
๐ฌ ๋ํ ๋งฅ๋ฝ ์ ์งํ๊ธฐ
ChatGPT์ ์ง์ง ๊ฐ๋ ฅํจ์ ๋ํ์ ๋งฅ๋ฝ์ ์ดํดํ๋ค๋ ๊ฑฐ์ผ. ์ด์ ๋ํ ๋ด์ฉ์ ๊ธฐ์ตํ๊ณ ๊ทธ์ ๋ง์ถฐ ๋ต๋ณํ์ง. ์ด๊ฑธ ๊ตฌํํ๋ ค๋ฉด messages ๋ฆฌ์คํธ์ ๋ํ ํ์คํ ๋ฆฌ๋ฅผ ๊ณ์ ์ถ๊ฐํด์ผ ํด.
์ค์ ์ฑํ
์ฑ์ฒ๋ผ ์๋ํ๋ ์์ ๋ฅผ ๋ง๋ค์ด๋ณผ๊น?
from openai import OpenAI
import os
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# ๋ํ ํ์คํ ๋ฆฌ๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ
conversation_history = []
def chat(user_message):
"""์ฌ์ฉ์ ๋ฉ์์ง๋ฅผ ๋ฐ์์ ChatGPT ์๋ต์ ๋ฐํ"""
# ์ฌ์ฉ์ ๋ฉ์์ง๋ฅผ ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
conversation_history.append({
"role": "user",
"content": user_message
})
# API ํธ์ถ
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=conversation_history
)
# ์ด์์คํดํธ ์๋ต์ ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
assistant_message = response.choices[0].message.content
conversation_history.append({
"role": "assistant",
"content": assistant_message
})
return assistant_message
# ๋ํ ์์!
print("ChatGPT: ์๋
ํ์ธ์! ๋ฌด์์ ๋์๋๋ฆด๊น์?")
while True:
user_input = input("You: ")
if user_input.lower() in ['์ข
๋ฃ', 'quit', 'exit']:
print("ChatGPT: ๋ํ๋ฅผ ์ข
๋ฃํฉ๋๋ค. ์ข์ ํ๋ฃจ ๋์ธ์!")
break
response = chat(user_input)
print(f"ChatGPT: {response}")
์ด ์ฝ๋์ ํต์ฌ์ conversation_history ๋ฆฌ์คํธ์ผ. ๋ชจ๋ ๋ํ ๋ด์ฉ์ด ์ฌ๊ธฐ์ ์์ด๋ฉด์ ChatGPT๊ฐ ๋งฅ๋ฝ์ ์ดํดํ ์ ์๊ฒ ๋๋ ๊ฑฐ์ง.
์๋ฅผ ๋ค์ด ์ด๋ฐ ๋ํ๊ฐ ๊ฐ๋ฅํด:
You: ํ์ด์ฌ์ผ๋ก ๋ฆฌ์คํธ๋ฅผ ์ ๋ ฌํ๋ ๋ฐฉ๋ฒ ์๋ ค์ค
ChatGPT: [์ ๋ ฌ ๋ฐฉ๋ฒ ์ค๋ช
]
You: ๊ทธ๋ผ ์ญ์์ผ๋ก ์ ๋ ฌํ๋ ค๋ฉด?
ChatGPT: [์ญ์ ์ ๋ ฌ ๋ฐฉ๋ฒ ์ค๋ช
]
๋ ๋ฒ์งธ ์ง๋ฌธ์์ "๊ทธ๋ผ"์ด๋ผ๊ณ ํ์ ๋, ChatGPT๋ ์ด์ ๋ํ๋ฅผ ๊ธฐ์ตํ๊ณ ์์ด์ ๋ฆฌ์คํธ ์ ๋ ฌ์ ๋ํ ์ง๋ฌธ์์ ์์์ฐจ๋ฆฌ๋ ๊ฑฐ์ผ! ๐ง
๐๏ธ ํ๋ผ๋ฏธํฐ๋ก ์๋ต ์กฐ์ ํ๊ธฐ
ChatGPT API๋ ๋ค์ํ ํ๋ผ๋ฏธํฐ๋ฅผ ์ ๊ณตํด์ ์๋ต ์คํ์ผ์ ์ธ๋ฐํ๊ฒ ์กฐ์ ํ ์ ์์ด. ๋ง์น ๋ผ๋์ค ๋ค์ด์ผ์ ๋๋ฆฌ๋ฏ์ด ๋ง์ด์ผ! ๐ป
๐ก๏ธ temperature (์จ๋)
๋ฒ์: 0.0 ~ 2.0 (๊ธฐ๋ณธ๊ฐ: 1.0)
์ด๊ฒ ๊ฐ์ฅ ์ค์ํ ํ๋ผ๋ฏธํฐ์ผ! ์๋ต์ ์ฐฝ์์ฑ๊ณผ ๋ฌด์์์ฑ์ ์กฐ์ ํด.
โข ๋ฎ์ ๊ฐ (0.0 ~ 0.3): ์ผ๊ด๋๊ณ ์์ธก ๊ฐ๋ฅํ ๋ต๋ณ. ์ฌ์ค ๊ธฐ๋ฐ ์ง๋ฌธ์ ์ ํฉ
โข ์ค๊ฐ ๊ฐ (0.5 ~ 1.0): ๊ท ํ์กํ ๋ต๋ณ. ์ผ๋ฐ์ ์ธ ๋ํ์ ์ข์
โข ๋์ ๊ฐ (1.5 ~ 2.0): ์ฐฝ์์ ์ด๊ณ ๋ค์ํ ๋ต๋ณ. ๋ธ๋ ์ธ์คํ ๋ฐ์ด๋ ์ฐฝ์์ ์ ์ฉ
์์ :
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "ํ์ด์ฌ์ด๋?"}],
temperature=0.2 # ์ ํํ๊ณ ์ผ๊ด๋ ๋ต๋ณ
)
๐ฒ top_p (nucleus sampling)
๋ฒ์: 0.0 ~ 1.0 (๊ธฐ๋ณธ๊ฐ: 1.0)
temperature์ ๋น์ทํ์ง๋ง ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ์๋ํด. ๋์ ํ๋ฅ ์ด top_p์ ๋๋ฌํ ๋๊น์ง์ ํ ํฐ๋ง ๊ณ ๋ คํ๋ ๊ฑฐ์ผ.
โข ๋ฎ์ ๊ฐ (0.1): ๊ฐ์ฅ ํ๋ฅ ๋์ ๋จ์ด๋ค๋ง ์ ํ
โข ๋์ ๊ฐ (0.9): ๋ ๋ค์ํ ๋จ์ด ์ ํ ๊ฐ๋ฅ
๐ก ๋ณดํต temperature์ top_p ์ค ํ๋๋ง ์กฐ์ ํ๋ ๊ฑธ ์ถ์ฒํด. ๋ ๋ค ์กฐ์ ํ๋ฉด ์์ธกํ๊ธฐ ์ด๋ ค์์ ธ!
๐ max_tokens (์ต๋ ํ ํฐ ์)
์๋ต์ ์ต๋ ๊ธธ์ด๋ฅผ ์ ํํด. ๋น์ฉ ๊ด๋ฆฌ์๋ ์ค์ํ๊ณ , ์งง์ ๋ต๋ณ์ด ํ์ํ ๋ ์ ์ฉํด.
์์ :
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "AI๋ฅผ ํ ๋ฌธ์ฅ์ผ๋ก ์ค๋ช
ํด์ค"}],
max_tokens=50 # ์งง์ ๋ต๋ณ ๊ฐ์
)
๐ฏ presence_penalty & frequency_penalty
๋ฒ์: -2.0 ~ 2.0 (๊ธฐ๋ณธ๊ฐ: 0)
presence_penalty: ์๋ก์ด ์ฃผ์ ๋ก ์ ํํ๋๋ก ์ ๋
โข ์์ ๊ฐ: ์ด๋ฏธ ์ธ๊ธ๋ ํ ํฐ์ ๋ ์ฌ์ฉํ๊ฒ ํจ
โข ์์ ๊ฐ: ๊ฐ์ ์ฃผ์ ๋ฅผ ๊ณ์ ์ด์ผ๊ธฐํ๊ฒ ํจ
frequency_penalty: ๋ฐ๋ณต์ ์ค์
โข ์์ ๊ฐ: ์์ฃผ ๋์จ ๋จ์ด๋ฅผ ๋ ์ฌ์ฉ
โข ์์ ๊ฐ: ๋ฐ๋ณต์ ํ์ฉ
์์ :
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "์ฐฝ์์ ์ธ ์ด์ผ๊ธฐ๋ฅผ ์จ์ค"}],
presence_penalty=0.6, # ๋ค์ํ ์ฃผ์
frequency_penalty=0.5 # ๋ฐ๋ณต ์ค์ด๊ธฐ
)
์ด๋ฐ ํ๋ผ๋ฏธํฐ๋ค์ ์กฐํฉํ๋ฉด ์ ๋ง ๋ค์ํ ์คํ์ผ์ ์๋ต์ ๋ง๋ค ์ ์์ด. ํ๋ก์ ํธ ์ฑ๊ฒฉ์ ๋ง๊ฒ ์คํํด๋ณด๋ ๊ฒ ์ค์ํด! ๐งช
๐ญ System Role๋ก AI ์ฑ๊ฒฉ ์ ํ๊ธฐ
messages ๋ฆฌ์คํธ์์ role์ด "system"์ธ ๋ฉ์์ง๋ ํน๋ณํด. ์ด๊ฑด ChatGPT์๊ฒ ์ด๋ค ์ญํ ์ ๋งก์์ง ์ง์ํ๋ ๊ฑฐ์ผ. ๋ง์น ๋ฐฐ์ฐ์๊ฒ ์บ๋ฆญํฐ ์ค์ ์ ์๋ ค์ฃผ๋ ๊ฒ์ฒ๋ผ!
system ๋ฉ์์ง๋ ๋ํ ์์ ๋ถ๋ถ์ ํ ๋ฒ๋ง ๋ฃ์ผ๋ฉด ๋ผ. ๊ทธ๋ฌ๋ฉด ChatGPT๊ฐ ๊ทธ ์ญํ ์ ๊ณ์ ์ ์งํ์ง.
์์ 1: ์น์ ํ Python ํํฐ
messages = [
{
"role": "system",
"content": "๋น์ ์ ์น์ ํ๊ณ ์ธ๋ด์ฌ ๋ง์ Python ํ๋ก๊ทธ๋๋ฐ ์ ์๋์
๋๋ค. ์ด๋ณด์๋ ์ดํดํ ์ ์๋๋ก ์ฝ๊ฒ ์ค๋ช
ํ๊ณ , ํญ์ ์์ ์ฝ๋๋ฅผ ํจ๊ป ์ ๊ณตํฉ๋๋ค."
},
{
"role": "user",
"content": "for ๋ฃจํ๊ฐ ๋ญ์์?"
}
]
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages
)
์์ 2: ์ ๋ฌธ ์ฝ๋ ๋ฆฌ๋ทฐ์ด
messages = [
{
"role": "system",
"content": """๋น์ ์ 10๋
๊ฒฝ๋ ฅ์ ์๋์ด ๊ฐ๋ฐ์์
๋๋ค.
์ฝ๋๋ฅผ ๋ฆฌ๋ทฐํ ๋ ๋ค์์ ์ค์ ์ ์ผ๋ก ํ์ธํฉ๋๋ค:
1. ์ฝ๋ ๊ฐ๋
์ฑ
2. ์ฑ๋ฅ ์ต์ ํ ๊ฐ๋ฅ์ฑ
3. ๋ณด์ ์ทจ์ฝ์
4. ๋ฒ ์คํธ ํ๋ํฐ์ค ์ค์ ์ฌ๋ถ
ํผ๋๋ฐฑ์ ๊ฑด์ค์ ์ด๊ณ ๊ตฌ์ฒด์ ์ผ๋ก ์ ๊ณตํฉ๋๋ค."""
},
{
"role": "user",
"content": "์ด ์ฝ๋๋ฅผ ๋ฆฌ๋ทฐํด์ฃผ์ธ์: [์ฝ๋ ๋ด์ฉ]"
}
]
์์ 3: JSON ์ถ๋ ฅ ์ ๋ฌธ๊ฐ
messages = [
{
"role": "system",
"content": "๋น์ ์ ํญ์ ์ ํจํ JSON ํ์์ผ๋ก๋ง ์๋ตํฉ๋๋ค. ์ถ๊ฐ ์ค๋ช
์์ด ์์ JSON๋ง ์ถ๋ ฅํฉ๋๋ค."
},
{
"role": "user",
"content": "์ฌ๊ณผ, ๋ฐ๋๋, ์ค๋ ์ง์ ์์ ์ ๋ณด๋ฅผ ์๋ ค์ค"
}
]
์ด๋ ๊ฒ ํ๋ฉด ํ๋ก๊ทธ๋จ์์ ํ์ฑํ๊ธฐ ์ฌ์ด JSON ํํ๋ก ๋ต๋ณ์ ๋ฐ์ ์ ์์ด! ๋ฐ์ดํฐ ์ฒ๋ฆฌํ ๋ ์์ฒญ ์ ์ฉํ์ง. ๐
โก ์คํธ๋ฆฌ๋ฐ์ผ๋ก ์ค์๊ฐ ์๋ต ๋ฐ๊ธฐ
ChatGPT ์น์ฌ์ดํธ์์ ๋ต๋ณ์ด ํ ๊ธ์์ฉ ํ์ดํ๋๋ ๊ฑฐ ๋ดค์ง? ๊ทธ๊ฒ ๋ฐ๋ก ์คํธ๋ฆฌ๋ฐ์ด์ผ! API์์๋ ๋๊ฐ์ด ๊ตฌํํ ์ ์์ด. ์ฌ์ฉ์ ๊ฒฝํ์ด ํจ์ฌ ์ข์์ง๊ฑฐ๋ . โก
์ผ๋ฐ API ํธ์ถ์ ์ ์ฒด ์๋ต์ด ์์ฑ๋ ๋๊น์ง ๊ธฐ๋ค๋ ค์ผ ํ์ง๋ง, ์คํธ๋ฆฌ๋ฐ์ ์์ฑ๋๋ ์ฆ์ ๋ฐ์ ์ ์์ด. ๊ธด ๋ต๋ณ์ผ ๋ ํนํ ์ ์ฉํด!
from openai import OpenAI
import os
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# stream=True ์ต์
์ถ๊ฐ!
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "์ธ๊ณต์ง๋ฅ์ ์ญ์ฌ์ ๋ํด ์์ธํ ์ค๋ช
ํด์ค"}
],
stream=True # ์คํธ๋ฆฌ๋ฐ ํ์ฑํ
)
print("ChatGPT: ", end="")
# ์คํธ๋ฆผ์์ ์ฒญํฌ๋ฅผ ํ๋์ฉ ๋ฐ์์ ์ถ๋ ฅ
for chunk in response:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)
print() # ์ค๋ฐ๊ฟ
์ฝ๋ ์ค๋ช
:
1. stream=True ํ๋ผ๋ฏธํฐ๋ฅผ ์ถ๊ฐํ๋ฉด ์คํธ๋ฆฌ๋ฐ ๋ชจ๋๊ฐ ํ์ฑํ๋ผ
2. ์๋ต ๊ฐ์ฒด๋ฅผ for ๋ฃจํ๋ก ์ํํ๋ฉด์ ์ฒญํฌ(chunk)๋ฅผ ํ๋์ฉ ๋ฐ์
3. chunk.choices[0].delta.content์ ์๋ก ์์ฑ๋ ํ
์คํธ๊ฐ ๋ค์ด์์ด
4. end=""์ flush=True๋ก ์ฆ์ ์ถ๋ ฅ๋๊ฒ ํด
์คํํ๋ฉด ChatGPT ์น์ฌ์ดํธ์ฒ๋ผ ๋ต๋ณ์ด ์ค์๊ฐ์ผ๋ก ๋ํ๋๋ ๊ฑธ ๋ณผ ์ ์์ด! ๐
์คํธ๋ฆฌ๋ฐ + ๋ํ ํ์คํ ๋ฆฌ
์คํธ๋ฆฌ๋ฐ๊ณผ ๋ํ ํ์คํ ๋ฆฌ๋ฅผ ํจ๊ป ์ฌ์ฉํ๋ ค๋ฉด ์ ์ฒด ์๋ต์ ๋ชจ์์ผ ํด:
def chat_with_streaming(user_message, conversation_history):
"""์คํธ๋ฆฌ๋ฐ์ผ๋ก ๋ํํ๋ฉด์ ํ์คํ ๋ฆฌ ๊ด๋ฆฌ"""
conversation_history.append({
"role": "user",
"content": user_message
})
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=conversation_history,
stream=True
)
full_response = ""
print("ChatGPT: ", end="")
for chunk in response:
if chunk.choices[0].delta.content is not None:
content = chunk.choices[0].delta.content
print(content, end="", flush=True)
full_response += content
print()
# ์์ฑ๋ ์๋ต์ ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
conversation_history.append({
"role": "assistant",
"content": full_response
})
return full_response
โข ๊ธด ๋ต๋ณ์ด ์์๋ ๋
โข ์ฌ์ฉ์์๊ฒ ์ฆ๊ฐ์ ์ธ ํผ๋๋ฐฑ์ ์ฃผ๊ณ ์ถ์ ๋
๋ฐ๋๋ก ๋ฐฑ๊ทธ๋ผ์ด๋ ์์ ์ด๋ ๋ฐฐ์น ์ฒ๋ฆฌ์๋ ์ผ๋ฐ ๋ชจ๋๊ฐ ๋ ๊ฐ๋จํด!
๐ก๏ธ ์๋ฌ ์ฒ๋ฆฌ์ ์ฌ์๋ ๋ก์ง
API ํธ์ถ์ ํญ์ ์ฑ๊ณตํ๋ค๋ ๋ณด์ฅ์ด ์์ด. ๋คํธ์ํฌ ๋ฌธ์ , ์๋ฒ ๊ณผ๋ถํ, ์๋ชป๋ ์์ฒญ ๋ฑ ๋ค์ํ ์ด์ ๋ก ์คํจํ ์ ์์ง. ์์ ์ ์ธ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค๋ ค๋ฉด ์๋ฌ ์ฒ๋ฆฌ๊ฐ ํ์์ผ! ๐ก๏ธ
๊ธฐ๋ณธ ์๋ฌ ์ฒ๋ฆฌ
from openai import OpenAI, OpenAIError
import os
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "์๋
!"}]
)
print(response.choices[0].message.content)
except OpenAIError as e:
print(f"OpenAI API ์๋ฌ ๋ฐ์: {e}")
except Exception as e:
print(f"์์์น ๋ชปํ ์๋ฌ: {e}")
๊ตฌ์ฒด์ ์ธ ์๋ฌ ํ์ ์ฒ๋ฆฌ
OpenAI ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ค์ํ ์๋ฌ ํ์ ์ ์ ๊ณตํด:
from openai import (
OpenAI,
APIError,
APIConnectionError,
RateLimitError,
AuthenticationError
)
import time
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def chat_with_error_handling(message):
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": message}]
)
return response.choices[0].message.content
except AuthenticationError:
print("โ API ํค๊ฐ ์ ํจํ์ง ์์ต๋๋ค!")
return None
except RateLimitError:
print("โณ ์์ฒญ ํ๋ ์ด๊ณผ! ์ ์ ํ ๋ค์ ์๋ํฉ๋๋ค...")
time.sleep(60) # 1๋ถ ๋๊ธฐ
return chat_with_error_handling(message) # ์ฌ์๋
except APIConnectionError:
print("๐ ๋คํธ์ํฌ ์ฐ๊ฒฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.")
return None
except APIError as e:
print(f"โ ๏ธ API ์๋ฌ: {e}")
return None
์ฌ์๋ ๋ก์ง ๊ตฌํํ๊ธฐ
์ผ์์ ์ธ ๋คํธ์ํฌ ๋ฌธ์ ๋ ์๋ฒ ๊ณผ๋ถํ๋ ์ฌ์๋ํ๋ฉด ํด๊ฒฐ๋๋ ๊ฒฝ์ฐ๊ฐ ๋ง์. ์ง์ ๋ฐฑ์คํ(exponential backoff) ์ ๋ต์ ์ฌ์ฉํด๋ณด์:
import time
from openai import OpenAI, APIError
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def chat_with_retry(message, max_retries=3):
"""์ฌ์๋ ๋ก์ง์ด ํฌํจ๋ ์ฑํ
ํจ์"""
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": message}]
)
return response.choices[0].message.content
except APIError as e:
if attempt < max_retries - 1:
# ๋๊ธฐ ์๊ฐ์ ์ ์ ๋๋ฆผ (1์ด, 2์ด, 4์ด...)
wait_time = 2 ** attempt
print(f"โณ ์๋ฌ ๋ฐ์. {wait_time}์ด ํ ์ฌ์๋... (์๋ {attempt + 1}/{max_retries})")
time.sleep(wait_time)
else:
print(f"โ {max_retries}๋ฒ ์๋ ํ ์คํจ: {e}")
return None
return None
# ์ฌ์ฉ ์์
result = chat_with_retry("ํ์ด์ฌ์ด๋?")
if result:
print(result)
else:
print("์๋ต์ ๋ฐ์ง ๋ชปํ์ต๋๋ค.")
โข Rate Limit ์๋ฌ๋ ์ถฉ๋ถํ ๊ธฐ๋ค๋ฆฐ ํ ์ฌ์๋ํด์ผ ํด
โข ์๋ฌ ๋ก๊ทธ๋ฅผ ๋จ๊ฒจ์ ๋ฌธ์ ํ์ ์ ๋์์ด ๋๊ฒ ํ์
๐ฐ ๋น์ฉ ์ต์ ํ ํ
API ์ฌ์ฉ๋ฃ๊ฐ ๊ฑฑ์ ๋์ง? ๊ฑฑ์ ๋ง! ๋๋ํ๊ฒ ์ฌ์ฉํ๋ฉด ๋น์ฉ์ ํฌ๊ฒ ์ค์ผ ์ ์์ด. ์ค์ ๋ก ๋ง์ ๊ฐ๋ฐ์๋ค์ด ์ด๋ฐ ๋ฐฉ๋ฒ๋ค๋ก ๋น์ฉ์ ์ ๊ฐํ๊ณ ์๊ฑฐ๋ . ๐ก
1. ์ ์ ํ ๋ชจ๋ธ ์ ํํ๊ธฐ
๋ชจ๋ธ๋ง๋ค ๊ฐ๊ฒฉ์ด ๋ฌ๋ผ. ํญ์ ์ต์ ๋ชจ๋ธ์ ์ธ ํ์๋ ์์ด!
๋ชจ๋ธ๋ณ ํน์ง:
โข gpt-4o: ๊ฐ์ฅ ๊ฐ๋ ฅํ์ง๋ง ๋น์. ๋ณต์กํ ์ถ๋ก ์ด ํ์ํ ๋
โข gpt-4o-mini: ๊ฐ์ฑ๋น ์ต๊ณ ! ๋๋ถ๋ถ์ ์์
์ ์ถฉ๋ถ
โข gpt-3.5-turbo: ์ ๋ ดํ๊ณ ๋น ๋ฆ. ๊ฐ๋จํ ์์
์ ์ ํฉ
๐ก ํ: ํ๋กํ ํ์
์ gpt-4o-mini๋ก ๊ฐ๋ฐํ๊ณ , ์ ๋ง ํ์ํ ๋ถ๋ถ๋ง gpt-4o๋ฅผ ์ฌ์ฉํ์!
2. ํ ํฐ ์ฌ์ฉ๋ ๋ชจ๋ํฐ๋ง
API ์๋ต์๋ ์ฌ์ฉ๋ ํ ํฐ ์ ๋ณด๊ฐ ํฌํจ๋์ด ์์ด. ์ด๊ฑธ ์ถ์ ํ๋ฉด ๋น์ฉ์ ์์ธกํ ์ ์์ง:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "์๋
!"}]
)
# ํ ํฐ ์ฌ์ฉ๋ ํ์ธ
usage = response.usage
print(f"์
๋ ฅ ํ ํฐ: {usage.prompt_tokens}")
print(f"์ถ๋ ฅ ํ ํฐ: {usage.completion_tokens}")
print(f"์ด ํ ํฐ: {usage.total_tokens}")
# ๋๋ต์ ์ธ ๋น์ฉ ๊ณ์ฐ (gpt-4o-mini ๊ธฐ์ค)
input_cost = (usage.prompt_tokens / 1_000_000) * 0.15
output_cost = (usage.completion_tokens / 1_000_000) * 0.60
total_cost = input_cost + output_cost
print(f"์์ ๋น์ฉ: ${total_cost:.6f}")
3. max_tokens๋ก ์ถ๋ ฅ ์ ํ
๋ถํ์ํ๊ฒ ๊ธด ๋ต๋ณ์ ๋น์ฉ ๋ญ๋น์ผ. ํ์ํ ๊ธธ์ด๋งํผ๋ง ๋ฐ์:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "AI๋ฅผ ํ ๋ฌธ์ฅ์ผ๋ก ์ค๋ช
ํด์ค"}],
max_tokens=100 # ์งง์ ๋ต๋ณ์ผ๋ก ์ ํ
)
4. ๋ํ ํ์คํ ๋ฆฌ ๊ด๋ฆฌ
๋ํ๊ฐ ๊ธธ์ด์ง์๋ก ๋งค๋ฒ ์ ์ฒด ํ์คํ ๋ฆฌ๋ฅผ ๋ณด๋ด์ผ ํด์ ๋น์ฉ์ด ์ฆ๊ฐํด. ์ค๋๋ ๋ฉ์์ง๋ ์ ๊ฑฐํ์:
def manage_conversation_history(history, max_messages=10):
"""์ต๊ทผ ๋ฉ์์ง๋ง ์ ์ง"""
if len(history) > max_messages:
# system ๋ฉ์์ง๋ ์ ์งํ๊ณ ๋๋จธ์ง๋ง ์ ํ
system_messages = [msg for msg in history if msg["role"] == "system"]
other_messages = [msg for msg in history if msg["role"] != "system"]
# ์ต๊ทผ ๋ฉ์์ง๋ง ์ ์ง
recent_messages = other_messages[-(max_messages-len(system_messages)):]
return system_messages + recent_messages
return history
5. ์บ์ฑ ํ์ฉํ๊ธฐ
๊ฐ์ ์ง๋ฌธ์ ๋ํ ๋ต๋ณ์ ์บ์ฑํ๋ฉด API ํธ์ถ์ ์ค์ผ ์ ์์ด:
import hashlib
import json
# ๊ฐ๋จํ ๋ฉ๋ชจ๋ฆฌ ์บ์
response_cache = {}
def get_cached_response(messages):
"""์บ์๋ ์๋ต์ด ์์ผ๋ฉด ๋ฐํ, ์์ผ๋ฉด API ํธ์ถ"""
# ๋ฉ์์ง๋ฅผ ํด์๋ก ๋ณํ (์บ์ ํค๋ก ์ฌ์ฉ)
cache_key = hashlib.md5(
json.dumps(messages, sort_keys=True).encode()
).hexdigest()
# ์บ์ ํ์ธ
if cache_key in response_cache:
print("๐พ ์บ์์์ ์๋ต ๋ฐํ!")
return response_cache[cache_key]
# API ํธ์ถ
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages
)
result = response.choices[0].message.content
# ์บ์์ ์ ์ฅ
response_cache[cache_key] = result
return result
โ max_tokens๋ก ์ถ๋ ฅ ๊ธธ์ด ์ ํ
โ ๋ํ ํ์คํ ๋ฆฌ ์ ์ ํ ๊ด๋ฆฌ
โ ์์ฃผ ์ฌ์ฉ๋๋ ์๋ต์ ์บ์ฑ
โ ํ ํฐ ์ฌ์ฉ๋ ์ ๊ธฐ์ ์ผ๋ก ๋ชจ๋ํฐ๋ง
โ ๊ฐ๋ฐ ์ค์๋ ํ ์คํธ ๊ณ์ ์ฌ์ฉ
๐ ์ค์ ํ๋ก์ ํธ: ๊ฐ๋จํ ์ฑ๋ด ๋ง๋ค๊ธฐ
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ ๋ชจ๋ ํ์ฉํด์ ์ค์ ๋ก ์๋ํ๋ ์ฑ๋ด์ ๋ง๋ค์ด๋ณด์! ์ด ์ฑ๋ด์ ๋ํ ํ์คํ ๋ฆฌ, ์๋ฌ ์ฒ๋ฆฌ, ์คํธ๋ฆฌ๋ฐ, ๋น์ฉ ์ถ์ ๊น์ง ๋ชจ๋ ํฌํจํ๊ณ ์์ด. ๐ค
from openai import OpenAI, OpenAIError
from dotenv import load_dotenv
import os
import time
# ํ๊ฒฝ๋ณ์ ๋ก๋
load_dotenv()
class ChatBot:
"""ChatGPT ๊ธฐ๋ฐ ์ฑ๋ด ํด๋์ค"""
def __init__(self, model="gpt-4o-mini", system_message=None):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
self.model = model
self.conversation_history = []
self.total_tokens_used = 0
# ์์คํ
๋ฉ์์ง ์ค์
if system_message:
self.conversation_history.append({
"role": "system",
"content": system_message
})
def chat(self, user_message, stream=True):
"""์ฌ์ฉ์ ๋ฉ์์ง๋ฅผ ๋ฐ์ ์๋ต ๋ฐํ"""
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
self.conversation_history.append({
"role": "user",
"content": user_message
})
try:
if stream:
return self._chat_with_streaming()
else:
return self._chat_normal()
except OpenAIError as e:
error_msg = f"์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}"
print(error_msg)
return error_msg
def _chat_normal(self):
"""์ผ๋ฐ ๋ชจ๋ ์ฑํ
"""
response = self.client.chat.completions.create(
model=self.model,
messages=self.conversation_history
)
assistant_message = response.choices[0].message.content
# ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
self.conversation_history.append({
"role": "assistant",
"content": assistant_message
})
# ํ ํฐ ์ฌ์ฉ๋ ์ถ์
self.total_tokens_used += response.usage.total_tokens
return assistant_message
def _chat_with_streaming(self):
"""์คํธ๋ฆฌ๋ฐ ๋ชจ๋ ์ฑํ
"""
response = self.client.chat.completions.create(
model=self.model,
messages=self.conversation_history,
stream=True
)
full_response = ""
print("๐ค ChatBot: ", end="", flush=True)
for chunk in response:
if chunk.choices[0].delta.content is not None:
content = chunk.choices[0].delta.content
print(content, end="", flush=True)
full_response += content
print() # ์ค๋ฐ๊ฟ
# ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
self.conversation_history.append({
"role": "assistant",
"content": full_response
})
return full_response
def clear_history(self):
"""๋ํ ํ์คํ ๋ฆฌ ์ด๊ธฐํ (์์คํ
๋ฉ์์ง๋ ์ ์ง)"""
system_messages = [
msg for msg in self.conversation_history
if msg["role"] == "system"
]
self.conversation_history = system_messages
print("๐ ๋ํ ํ์คํ ๋ฆฌ๊ฐ ์ด๊ธฐํ๋์์ต๋๋ค.")
def get_stats(self):
"""ํต๊ณ ์ ๋ณด ๋ฐํ"""
return {
"total_messages": len(self.conversation_history),
"total_tokens": self.total_tokens_used,
"estimated_cost": self.total_tokens_used * 0.0000002 # ๋๋ต์ ์ธ ๋น์ฉ
}
# ์ฑ๋ด ์ฌ์ฉ ์์
def main():
# ์ฑ๋ด ์ด๊ธฐํ
bot = ChatBot(
model="gpt-4o-mini",
system_message="๋น์ ์ ์น์ ํ๊ณ ์ ๋จธ๋ฌ์คํ AI ์ด์์คํดํธ์
๋๋ค. ์ด๋ชจ์ง๋ฅผ ์ ์ ํ ์ฌ์ฉํ๋ฉฐ ๋ํํฉ๋๋ค."
)
print("=" * 50)
print("๐ ChatGPT ์ฑ๋ด์ ์ค์ ๊ฒ์ ํ์ํฉ๋๋ค!")
print("=" * 50)
print("๋ช
๋ น์ด:")
print(" - '์ข
๋ฃ' ๋๋ 'quit': ํ๋ก๊ทธ๋จ ์ข
๋ฃ")
print(" - '์ด๊ธฐํ' ๋๋ 'clear': ๋ํ ํ์คํ ๋ฆฌ ์ด๊ธฐํ")
print(" - 'ํต๊ณ' ๋๋ 'stats': ์ฌ์ฉ ํต๊ณ ํ์ธ")
print("=" * 50)
print()
while True:
# ์ฌ์ฉ์ ์
๋ ฅ
user_input = input("๐ค You: ").strip()
if not user_input:
continue
# ๋ช
๋ น์ด ์ฒ๋ฆฌ
if user_input.lower() in ['์ข
๋ฃ', 'quit', 'exit']:
stats = bot.get_stats()
print("\n๐ ์ต์ข
ํต๊ณ:")
print(f" ์ด ๋ฉ์์ง: {stats['total_messages']}๊ฐ")
print(f" ์ด ํ ํฐ: {stats['total_tokens']}๊ฐ")
print(f" ์์ ๋น์ฉ: ${stats['estimated_cost']:.6f}")
print("\n๐ ์ฑ๋ด์ ์ข
๋ฃํฉ๋๋ค. ์ข์ ํ๋ฃจ ๋์ธ์!")
break
elif user_input.lower() in ['์ด๊ธฐํ', 'clear']:
bot.clear_history()
continue
elif user_input.lower() in ['ํต๊ณ', 'stats']:
stats = bot.get_stats()
print(f"\n๐ ํ์ฌ ํต๊ณ:")
print(f" ์ด ๋ฉ์์ง: {stats['total_messages']}๊ฐ")
print(f" ์ด ํ ํฐ: {stats['total_tokens']}๊ฐ")
print(f" ์์ ๋น์ฉ: ${stats['estimated_cost']:.6f}\n")
continue
# ์ผ๋ฐ ๋ํ
bot.chat(user_input, stream=True)
print()
if __name__ == "__main__":
main()
์ด ์ฑ๋ด์ ์ค์ ๋ก ์ฌ์ฉํ ์ ์๋ ์์ค์ด์ผ! ์ฃผ์ ๊ธฐ๋ฅ๋ค์ ์ดํด๋ณด๋ฉด:
โจ ์ฃผ์ ๊ธฐ๋ฅ:
โข ํด๋์ค ๊ธฐ๋ฐ ๊ตฌ์กฐ๋ก ์ฌ์ฌ์ฉ ๊ฐ๋ฅ
โข ์คํธ๋ฆฌ๋ฐ ๋ชจ๋ ์ง์
โข ๋ํ ํ์คํ ๋ฆฌ ๊ด๋ฆฌ
โข ์๋ฌ ์ฒ๋ฆฌ
โข ํ ํฐ ์ฌ์ฉ๋ ์ถ์
โข ๋ช
๋ น์ด ์์คํ
(์ข
๋ฃ, ์ด๊ธฐํ, ํต๊ณ)
โข ์์คํ
๋ฉ์์ง๋ก ์ฑ๊ฒฉ ์ค์ ๊ฐ๋ฅ
์ด ์ฝ๋๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์น ์ ํ๋ฆฌ์ผ์ด์
, Discord ๋ด, Slack ๋ด ๋ฑ ๋ค์ํ ํ๋ก์ ํธ๋ก ํ์ฅํ ์ ์์ด! ๐
๐ ์น ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ํตํฉํ๊ธฐ
์ฑ๋ด์ ๋ง๋ค์์ผ๋ ์ด์ ์น์์ ์ฌ์ฉํ ์ ์๊ฒ ํด๋ณด์! Flask๋ FastAPI ๊ฐ์ ์น ํ๋ ์์ํฌ์ ํตํฉํ๋ฉด ๋ฉ์ง ์น ์ฑํ ์ธํฐํ์ด์ค๋ฅผ ๋ง๋ค ์ ์์ด. ๐
Flask๋ก ๊ฐ๋จํ API ์๋ฒ ๋ง๋ค๊ธฐ
๋จผ์ Flask๋ฅผ ์ค์นํ์:
pip install flask flask-cors
๊ทธ๋ฆฌ๊ณ ๊ฐ๋จํ API ์๋ฒ๋ฅผ ๋ง๋ค์ด:
from flask import Flask, request, jsonify, Response
from flask_cors import CORS
from openai import OpenAI
import os
import json
app = Flask(__name__)
CORS(app) # CORS ํ์ฉ
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# ์ธ์
๋ณ ๋ํ ํ์คํ ๋ฆฌ ์ ์ฅ (์ค์ ๋ก๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค ์ฌ์ฉ ๊ถ์ฅ)
conversations = {}
@app.route('/chat', methods=['POST'])
def chat():
"""์ผ๋ฐ ์ฑํ
์๋ํฌ์ธํธ"""
data = request.json
user_message = data.get('message')
session_id = data.get('session_id', 'default')
if not user_message:
return jsonify({'error': '๋ฉ์์ง๊ฐ ํ์ํฉ๋๋ค'}), 400
# ์ธ์
ํ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ
if session_id not in conversations:
conversations[session_id] = []
# ์ฌ์ฉ์ ๋ฉ์์ง ์ถ๊ฐ
conversations[session_id].append({
"role": "user",
"content": user_message
})
try:
# API ํธ์ถ
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=conversations[session_id]
)
assistant_message = response.choices[0].message.content
# ์ด์์คํดํธ ์๋ต ์ถ๊ฐ
conversations[session_id].append({
"role": "assistant",
"content": assistant_message
})
return jsonify({
'response': assistant_message,
'tokens_used': response.usage.total_tokens
})
except Exception as e:
return jsonify({'error': str(e)}), 500
@app.route('/chat/stream', methods=['POST'])
def chat_stream():
"""์คํธ๋ฆฌ๋ฐ ์ฑํ
์๋ํฌ์ธํธ"""
data = request.json
user_message = data.get('message')
session_id = data.get('session_id', 'default')
if session_id not in conversations:
conversations[session_id] = []
conversations[session_id].append({
"role": "user",
"content": user_message
})
def generate():
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=conversations[session_id],
stream=True
)
full_response = ""
for chunk in response:
if chunk.choices[0].delta.content is not None:
content = chunk.choices[0].delta.content
full_response += content
# SSE ํ์์ผ๋ก ์ ์ก
yield f"data: {json.dumps({'content': content})}\n\n"
# ์์ฑ๋ ์๋ต์ ํ์คํ ๋ฆฌ์ ์ถ๊ฐ
conversations[session_id].append({
"role": "assistant",
"content": full_response
})
except Exception as e:
yield f"data: {json.dumps({'error': str(e)})}\n\n"
return Response(generate(), mimetype='text/event-stream')
@app.route('/clear/<session_id>', methods=['POST'])
def clear_conversation(session_id):
"""๋ํ ํ์คํ ๋ฆฌ ์ด๊ธฐํ"""
if session_id in conversations:
conversations[session_id] = []
return jsonify({'message': '๋ํ๊ฐ ์ด๊ธฐํ๋์์ต๋๋ค'})
if __name__ == '__main__':
app.run(debug=True, port=5000)
๊ฐ๋จํ HTML ํ๋ก ํธ์๋
์ด์ ์ด API๋ฅผ ์ฌ์ฉํ๋ ๊ฐ๋จํ ์น ํ์ด์ง๋ฅผ ๋ง๋ค์ด๋ณด์:
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT ์ฑ๋ด</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
}
#chat-container {
border: 1px solid #ddd;
height: 500px;
overflow-y: auto;
padding: 20px;
margin-bottom: 20px;
background: #f9f9f9;
}
.message {
margin: 10px 0;
padding: 10px;
border-radius: 8px;
}
.user-message {
background: #667eea;
color: white;
text-align: right;
}
.bot-message {
background: white;
border: 1px solid #ddd;
}
#input-container {
display: flex;
gap: 10px;
}
#message-input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
padding: 10px 20px;
background: #667eea;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background: #5568d3;
}
</style>
</head>
<body>
<h1>๐ค ChatGPT ์ฑ๋ด</h1>
<div id="chat-container"></div>
<div id="input-container">
<input type="text" id="message-input" placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...">
<button onclick="sendMessage()">์ ์ก</button>
<button onclick="clearChat()">์ด๊ธฐํ</button>
</div>
<script>
const sessionId = 'user_' + Date.now();
const chatContainer = document.getElementById('chat-container');
const messageInput = document.getElementById('message-input');
function addMessage(content, isUser) {
const messageDiv = document.createElement('div');
messageDiv.className = 'message ' + (isUser ? 'user-message' : 'bot-message');
messageDiv.textContent = content;
chatContainer.appendChild(messageDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
async function sendMessage() {
const message = messageInput.value.trim();
if (!message) return;
addMessage(message, true);
messageInput.value = '';
try {
const response = await fetch('http://localhost:5000/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
message: message,
session_id: sessionId
})
});
const data = await response.json();
addMessage(data.response, false);
} catch (error) {
addMessage('์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค: ' + error.message, false);
}
}
async function clearChat() {
try {
await fetch(`http://localhost:5000/clear/${sessionId}`, {
method: 'POST'
});
chatContainer.innerHTML = '';
addMessage('๋ํ๊ฐ ์ด๊ธฐํ๋์์ต๋๋ค.', false);
} catch (error) {
console.error('์ด๊ธฐํ ์คํจ:', error);
}
}
messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
</script>
</body>
</html>
์ด์ Flask ์๋ฒ๋ฅผ ์คํํ๊ณ HTML ํ์ผ์ ๋ธ๋ผ์ฐ์ ์์ ์ด๋ฉด ์๋ํ๋ ์น ์ฑ๋ด์ ๋ณผ ์ ์์ด! ๐
โข ์ฌ์ฉ์ ์ธ์ฆ๊ณผ Rate Limiting์ ์ถ๊ฐํ์
โข HTTPS๋ฅผ ์ฌ์ฉํด์ ๋ณด์์ ๊ฐํํ์
โข ์๋ฌ ๋ก๊น ๊ณผ ๋ชจ๋ํฐ๋ง์ ์ค์ ํ์
๐ ๊ณ ๊ธ ๊ธฐ๋ฅ ํ์ฉํ๊ธฐ
๊ธฐ๋ณธ์ ์ธ ์ฌ์ฉ๋ฒ์ ๋์ด์ ChatGPT API์ ๊ณ ๊ธ ๊ธฐ๋ฅ๋ค์ ์์๋ณด์. ์ด๋ฐ ๊ธฐ๋ฅ๋ค์ ํ์ฉํ๋ฉด ํจ์ฌ ๋ ๊ฐ๋ ฅํ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค ์ ์์ด! ๐ช
1. Function Calling (ํจ์ ํธ์ถ)
ChatGPT๊ฐ ํน์ ํจ์๋ฅผ ํธ์ถํ๋๋ก ํ ์ ์์ด. ์๋ฅผ ๋ค์ด ๋ ์จ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๊ฑฐ๋, ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ฅผ ์กฐํํ๊ฑฐ๋, ์ธ๋ถ API๋ฅผ ํธ์ถํ๋ ๋ฑ์ ์์
์ด ๊ฐ๋ฅํด์ง์ง!
๋ ์จ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ์์ :
import json
# ํจ์ ์ ์
def get_weather(location):
"""์ค์ ๋ก๋ ๋ ์จ API๋ฅผ ํธ์ถํ์ง๋ง, ์ฌ๊ธฐ์๋ ๋๋ฏธ ๋ฐ์ดํฐ ๋ฐํ"""
weather_data = {
"์์ธ": {"temperature": 15, "condition": "๋ง์"},
"๋ถ์ฐ": {"temperature": 18, "condition": "ํ๋ฆผ"},
}
return weather_data.get(location, {"temperature": 20, "condition": "์ ์ ์์"})
# ChatGPT์๊ฒ ํจ์ ์ ๋ณด ์ ๊ณต
functions = [
{
"name": "get_weather",
"description": "ํน์ ์ง์ญ์ ํ์ฌ ๋ ์จ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ต๋๋ค",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "๋ ์จ๋ฅผ ํ์ธํ ๋์ ์ด๋ฆ (์: ์์ธ, ๋ถ์ฐ)"
}
},
"required": ["location"]
}
}
]
# API ํธ์ถ
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "์์ธ ๋ ์จ ์ด๋?"}],
functions=functions,
function_call="auto"
)
message = response.choices[0].message
# ํจ์ ํธ์ถ์ด ํ์ํ์ง ํ์ธ
if message.function_call:
function_name = message.function_call.name
function_args = json.loads(message.function_call.arguments)
# ํจ์ ์คํ
if function_name == "get_weather":
weather = get_weather(function_args["location"])
# ํจ์ ๊ฒฐ๊ณผ๋ฅผ ChatGPT์๊ฒ ์ ๋ฌ
second_response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "์์ธ ๋ ์จ ์ด๋?"},
message,
{
"role": "function",
"name": function_name,
"content": json.dumps(weather)
}
]
)
print(second_response.choices[0].message.content)
else:
print(message.content)
์ด๋ ๊ฒ ํ๋ฉด ChatGPT๊ฐ ์์ฐ์ด ์ง๋ฌธ์ ์ดํดํ๊ณ , ์ ์ ํ ํจ์๋ฅผ ํธ์ถํ๊ณ , ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ๋ต๋ณ์ผ๋ก ๋ง๋ค์ด์ค! ๐ฏ
2. JSON Mode
ChatGPT๊ฐ ํญ์ ์ ํจํ JSON ํ์์ผ๋ก ์๋ตํ๋๋ก ๊ฐ์ ํ ์ ์์ด. ๋ฐ์ดํฐ ํ์ฑ์ด ํ์ํ ์ ํ๋ฆฌ์ผ์ด์ ์ ์๋ฒฝํด!
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "๋น์ ์ JSON ํ์์ผ๋ก๋ง ์๋ตํ๋ ์ด์์คํดํธ์
๋๋ค."
},
{
"role": "user",
"content": "ํ์ด์ฌ์ ์ฃผ์ ํน์ง 3๊ฐ์ง๋ฅผ JSON ๋ฐฐ์ด๋ก ์๋ ค์ค"
}
],
response_format={"type": "json_object"}
)
# JSON ํ์ฑ
result = json.loads(response.choices[0].message.content)
print(result)
3. Vision (์ด๋ฏธ์ง ๋ถ์)
GPT-4o ๋ชจ๋ธ์ ์ด๋ฏธ์ง๋ฅผ ๋ถ์ํ ์ ์์ด! ์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉํ๊ฑฐ๋ URL๋ก ์ ๊ณตํ๋ฉด ๋ผ.
import base64
# ์ด๋ฏธ์ง๋ฅผ base64๋ก ์ธ์ฝ๋ฉ
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# ์ด๋ฏธ์ง ๋ถ์
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": "์ด ์ด๋ฏธ์ง์ ๋ฌด์์ด ์๋์?"
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{encode_image('image.jpg')}"
}
}
]
}
]
)
print(response.choices[0].message.content)
์ด๋ฏธ์ง ์ ๊ฐ์ฒด ์ธ์, OCR, ์ด๋ฏธ์ง ์ค๋ช ์์ฑ ๋ฑ ๋ค์ํ ์ฉ๋๋ก ํ์ฉํ ์ ์์ด! ๐ธ
4. Embeddings (์๋ฒ ๋ฉ)
ํ ์คํธ๋ฅผ ๋ฒกํฐ๋ก ๋ณํํด์ ์๋ฏธ์ ์ ์ฌ๋๋ฅผ ๊ณ์ฐํ ์ ์์ด. ๊ฒ์ ์์ง, ์ถ์ฒ ์์คํ , ๋ฌธ์ ๋ถ๋ฅ ๋ฑ์ ํ์ฉ๋ผ.
def get_embedding(text):
"""ํ
์คํธ์ ์๋ฒ ๋ฉ ๋ฒกํฐ ์์ฑ"""
response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
return response.data[0].embedding
# ๋ ํ
์คํธ์ ์ ์ฌ๋ ๊ณ์ฐ
import numpy as np
text1 = "ํ์ด์ฌ์ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์
๋๋ค"
text2 = "Python is a programming language"
text3 = "๋๋ ์ฌ๊ณผ๋ฅผ ์ข์ํฉ๋๋ค"
embedding1 = get_embedding(text1)
embedding2 = get_embedding(text2)
embedding3 = get_embedding(text3)
# ์ฝ์ฌ์ธ ์ ์ฌ๋ ๊ณ์ฐ
def cosine_similarity(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(f"text1 vs text2: {cosine_similarity(embedding1, embedding2):.4f}")
print(f"text1 vs text3: {cosine_similarity(embedding1, embedding3):.4f}")
text1๊ณผ text2๋ ๊ฐ์ ์๋ฏธ๋ผ์ ์ ์ฌ๋๊ฐ ๋๊ฒ ๋์ค๊ณ , text3๋ ๋ค๋ฅธ ์ฃผ์ ๋ผ์ ๋ฎ๊ฒ ๋์ฌ ๊ฑฐ์ผ!
๐ ์ค์ ํ์ฉ ์ฌ๋ก
์ด๋ก ์ ์ถฉ๋ถํ ๋ฐฐ์ ์ผ๋, ์ค์ ๋ก ์ด๋ป๊ฒ ํ์ฉ๋๋์ง ๊ตฌ์ฒด์ ์ธ ์ฌ๋ก๋ค์ ์ดํด๋ณด์! ์ด๋ฐ ํ๋ก์ ํธ๋ค์ ๋ง๋ค๋ฉด์ ํฌํธํด๋ฆฌ์ค๋ ์์ ์ ์์ด. ๐ผ
๐ ์๋ ๋ธ๋ก๊ทธ ๊ธ ์์ฑ ๋๊ตฌ
ํค์๋๋ง ์ ๋ ฅํ๋ฉด SEO ์ต์ ํ๋ ๋ธ๋ก๊ทธ ๊ธ์ ์๋์ผ๋ก ์์ฑํด์ฃผ๋ ๋๊ตฌ:
def generate_blog_post(topic, keywords, tone="professional"):
"""๋ธ๋ก๊ทธ ๊ธ ์๋ ์์ฑ"""
system_message = f"""๋น์ ์ ์ ๋ฌธ ๋ธ๋ก๊ทธ ์๊ฐ์
๋๋ค.
๋ค์ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๊ธ์ ์์ฑํ์ธ์:
- ํค: {tone}
- SEO ์ต์ ํ๋ฅผ ์ํด ํค์๋๋ฅผ ์์ฐ์ค๋ฝ๊ฒ ํฌํจ
- ๊ตฌ์กฐ: ์๋ก , ๋ณธ๋ก (3๊ฐ ์น์
), ๊ฒฐ๋ก
- ๊ฐ ์น์
์ ์์ ๋ชฉ ํฌํจ
- ์ฝ 1000๋จ์ด ๋ถ๋
"""
user_message = f"""์ฃผ์ : {topic}
ํค์๋: {', '.join(keywords)}
์ ์ฃผ์ ๋ก ๋ธ๋ก๊ทธ ๊ธ์ ์์ฑํด์ฃผ์ธ์."""
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_message},
{"role": "user", "content": user_message}
],
temperature=0.7
)
return response.choices[0].message.content
# ์ฌ์ฉ ์์
blog_post = generate_blog_post(
topic="Python ์น ์คํฌ๋ํ ์
๋ฌธ",
keywords=["BeautifulSoup", "requests", "์น ํฌ๋กค๋ง", "๋ฐ์ดํฐ ์์ง"],
tone="์น๊ทผํ๊ณ ๊ต์ก์ ์ธ"
)
print(blog_post)
๐ฌ ๊ณ ๊ฐ ์ง์ ์ฑ๋ด
FAQ ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฐ๋๋ ๊ณ ๊ฐ ์ง์ ์ฑ๋ด:
class CustomerSupportBot:
def __init__(self, faq_data):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
self.faq_data = faq_data
# FAQ๋ฅผ ์์คํ
๋ฉ์์ง์ ํฌํจ
faq_text = "\n".join([
f"Q: {item['question']}\nA: {item['answer']}"
for item in faq_data
])
self.system_message = f"""๋น์ ์ ์น์ ํ ๊ณ ๊ฐ ์ง์ ๋ด๋น์์
๋๋ค.
๋ค์ FAQ ์ ๋ณด๋ฅผ ์ฐธ๊ณ ํ์ฌ ๋ต๋ณํ์ธ์:
{faq_text}
FAQ์ ์๋ ๋ด์ฉ์ด๋ฉด ์ ์คํ๊ฒ ์๋ด์ ์ฐ๊ฒฐ์ ์๋ดํ์ธ์."""
def answer(self, question):
response = self.client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": self.system_message},
{"role": "user", "content": question}
],
temperature=0.3 # ์ผ๊ด๋ ๋ต๋ณ์ ์ํด ๋ฎ์ temperature
)
return response.choices[0].message.content
# FAQ ๋ฐ์ดํฐ
faq_data = [
{
"question": "๋ฐฐ์ก์ ์ผ๋ง๋ ๊ฑธ๋ฆฌ๋์?",
"answer": "์ผ๋ฐ ๋ฐฐ์ก์ 2-3์ผ, ๋น ๋ฅธ ๋ฐฐ์ก์ 1์ผ ์์๋ฉ๋๋ค."
},
{
"question": "๋ฐํ์ ์ด๋ป๊ฒ ํ๋์?",
"answer": "๊ตฌ๋งค ํ 7์ผ ์ด๋ด ๋ฏธ์ฌ์ฉ ์ ํ์ ํํด ๋ฐํ ๊ฐ๋ฅํฉ๋๋ค."
}
]
bot = CustomerSupportBot(faq_data)
print(bot.answer("๋ฐฐ์ก ๊ธฐ๊ฐ์ด ๊ถ๊ธํด์"))
๐ ๋ฐ์ดํฐ ๋ถ์ ์ด์์คํดํธ
์์ฐ์ด๋ก ๋ฐ์ดํฐ ๋ถ์ ์์ฒญ์ ๋ฐ์ pandas ์ฝ๋๋ฅผ ์์ฑํ๊ณ ์คํ:
import pandas as pd
class DataAnalysisAssistant:
def __init__(self, dataframe):
self.df = dataframe
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# ๋ฐ์ดํฐํ๋ ์ ์ ๋ณด
df_info = f"""
์ปฌ๋ผ: {list(dataframe.columns)}
ํ ์: {len(dataframe)}
๋ฐ์ดํฐ ํ์
: {dataframe.dtypes.to_dict()}
"""
self.system_message = f"""๋น์ ์ ๋ฐ์ดํฐ ๋ถ์ ์ ๋ฌธ๊ฐ์
๋๋ค.
์ฌ์ฉ์์ ์์ฒญ์ pandas ์ฝ๋๋ก ๋ณํํ์ธ์.
ํ์ฌ ๋ฐ์ดํฐํ๋ ์ ์ ๋ณด:
{df_info}
์ฝ๋๋ง ์ถ๋ ฅํ๊ณ , ์ค๋ช
์ ์ฃผ์์ผ๋ก ์์ฑํ์ธ์."""
def analyze(self, request):
response = self.client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": self.system_message},
{"role": "user", "content": request}
],
temperature=0.2
)
code = response.choices[0].message.content
# ์ฝ๋ ์คํ (์ฃผ์: ์ค์ ํ๋ก๋์
์์๋ ๋ณด์ ๊ฒ์ฆ ํ์!)
try:
# ์์ ํ ์คํ ํ๊ฒฝ ์ ๊ณต
local_vars = {'df': self.df, 'pd': pd}
exec(code, {}, local_vars)
return local_vars.get('result', "๊ฒฐ๊ณผ๊ฐ ์์ต๋๋ค")
except Exception as e:
return f"์คํ ์ค๋ฅ: {e}"
# ์ฌ์ฉ ์์
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35],
'salary': [50000, 60000, 70000]
})
assistant = DataAnalysisAssistant(df)
result = assistant.analyze("ํ๊ท ๋์ด์ ๊ธ์ฌ๋ฅผ ๊ณ์ฐํด์ค")
print(result)
๐จ ์ฐฝ์ ๋์ฐ๋ฏธ
์์ค, ์๋๋ฆฌ์ค, ๊ด๊ณ ์นดํผ ๋ฑ์ ์์ฑํ๋ ์ฐฝ์ ๋์ฐ๋ฏธ:
class CreativeWriter:
def __init__(self):
self.client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def generate_story(self, genre, characters, setting, plot_points):
"""๋จํธ ์์ค ์์ฑ"""
prompt = f"""
์ฅ๋ฅด: {genre}
๋ฑ์ฅ์ธ๋ฌผ: {', '.join(characters)}
๋ฐฐ๊ฒฝ: {setting}
์ฃผ์ ํ๋กฏ: {', '.join(plot_points)}
์ ์์๋ค์ ํ์ฉํด ํฅ๋ฏธ์ง์งํ ๋จํธ ์์ค์ ์์ฑํด์ฃผ์ธ์.
"""
response = self.client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "๋น์ ์ ๋ฒ ์คํธ์
๋ฌ ์๊ฐ์
๋๋ค. ์์ํ ๋ฌ์ฌ์ ํฅ๋ฏธ๋ก์ด ์ ๊ฐ๋ก ๋
์๋ฅผ ์ฌ๋ก์ก๋ ์ด์ผ๊ธฐ๋ฅผ ์๋๋ค."
},
{"role": "user", "content": prompt}
],
temperature=0.9 # ์ฐฝ์์ฑ์ ์ํด ๋์ temperature
)
return response.choices[0].message.content
def generate_ad_copy(self, product, target_audience, key_features):
"""๊ด๊ณ ์นดํผ ์์ฑ"""
prompt = f"""
์ ํ: {product}
ํ๊ฒ: {target_audience}
์ฃผ์ ํน์ง: {', '.join(key_features)}
๋งค๋ ฅ์ ์ธ ๊ด๊ณ ์นดํผ๋ฅผ 3๊ฐ์ง ๋ฒ์ ์ผ๋ก ์์ฑํด์ฃผ์ธ์.
๊ฐ ๋ฒ์ ์ ๋ค๋ฅธ ํค์ผ๋ก ์์ฑํ์ธ์.
"""
response = self.client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "๋น์ ์ ํฌ๋ฆฌ์์ดํฐ๋ธ ๋๋ ํฐ์
๋๋ค. ๊ฐ๊ฒฐํ๊ณ ์ํฉํธ ์๋ ์นดํผ๋ฅผ ์์ฑํฉ๋๋ค."
},
{"role": "user", "content": prompt}
],
temperature=0.8
)
return response.choices[0].message.content
# ์ฌ์ฉ ์์
writer = CreativeWriter()
# ์์ค ์์ฑ
story = writer.generate_story(
genre="SF ์ค๋ฆด๋ฌ",
characters=["AI ์ฐ๊ตฌ์ ์ง์", "์๋ฌธ์ ํด์ปค"],
setting="2045๋
์์ธ",
plot_points=["AI ๋ฐ๋", "์จ๊ฒจ์ง ์ง์ค", "์์์น ๋ชปํ ๋ฐ์ "]
)
print(story)
๐ฏ ์ฌ๋ฅ๋ท์์ AI ๊ฐ๋ฐ ์ฌ๋ฅ ๊ณต์ ํ๊ธฐ
์ด์ ChatGPT API๋ฅผ ์์ ์์ฌ๋ก ๋ค๋ฃฐ ์ ์๊ฒ ๋์ด! ์ด๋ฐ ๊ธฐ์ ์ ๊ฐ์ง๊ณ ์๋ค๋ฉด ์ฌ๋ฅ๋ท์์ ๋ค๋ฅธ ์ฌ๋๋ค๊ณผ ์ฌ๋ฅ์ ๊ณต์ ํด๋ณด๋ ๊ฑด ์ด๋? ๐
์ฌ๋ฅ๋ท์ ๋ค์ํ ์ฌ๋ฅ์ ๊ฑฐ๋ํ๋ ํ๋ซํผ์ด์ผ. AI ๊ฐ๋ฐ ๋ถ์ผ์์ ์ด๋ฐ ์๋น์ค๋ค์ ์ ๊ณตํ ์ ์์ด:
โข ChatGPT API ์ฐ๋ ๊ฐ๋ฐ ๋ํ
โข ๋ง์ถคํ ์ฑ๋ด ์ ์
โข AI ๊ธฐ๋ฐ ์๋ํ ๋๊ตฌ ๊ฐ๋ฐ
โข Python + AI ํ๋ก๊ทธ๋๋ฐ ๊ณผ์ธ
โข ๋ฐ์ดํฐ ๋ถ์ ์๋ํ ์๋ฃจ์
ํนํ ์์ฆ์ AI ๊ธฐ์ ์ ๋ํ ์์๊ฐ ํญ๋ฐ์ ์ผ๋ก ์ฆ๊ฐํ๊ณ ์์ด์, ์ด๋ฐ ์ฌ๋ฅ์ ๊ฐ์ง ์ฌ๋๋ค์ด ์ ๋ง ๋ง์ด ํ์ํด. ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์ ํตํด ์์ ์ ๊ธฐ์ ์ ์์ตํํ๊ณ , ๋์์ ๋ค๋ฅธ ์ฌ๋๋ค์๊ฒ ๋์์ ์ค ์ ์์ง! ๐ช
์ค์ ๋ก ๋ง์ ๊ฐ๋ฐ์๋ค์ด ์ฌ์ด๋ ํ๋ก์ ํธ๋ก AI ๊ด๋ จ ์๋น์ค๋ฅผ ์ ๊ณตํ๋ฉด์ ์ข์ ์์
์ ์ฌ๋ฆฌ๊ณ ์์ด. ๋๋ ์ด ๊ธ์์ ๋ฐฐ์ด ๋ด์ฉ์ ๋ฐํ์ผ๋ก ์์ ๋ง์ ์๋น์ค๋ฅผ ๋ง๋ค์ด๋ณด๋ ๊ฑด ์ด๋จ๊น?
โ ๏ธ ์ฃผ์์ฌํญ๊ณผ ๋ฒ ์คํธ ํ๋ํฐ์ค
๋ง์ง๋ง์ผ๋ก ChatGPT API๋ฅผ ์ฌ์ฉํ ๋ ๊ผญ ์์์ผ ํ ์ฃผ์์ฌํญ๋ค์ ์ ๋ฆฌํด๋ณผ๊ฒ. ์ด๊ฑธ ์งํค๋ฉด ์์ ํ๊ณ ํจ์จ์ ์ผ๋ก API๋ฅผ ํ์ฉํ ์ ์์ด! ๐ก๏ธ
๐ ๋ณด์
1. API ํค ๊ด๋ฆฌ
โข ์ ๋ ์ฝ๋์ ์ง์ ํ๋์ฝ๋ฉํ์ง ๋ง ๊ฒ
โข ํ๊ฒฝ๋ณ์๋ ๋น๋ฐ ๊ด๋ฆฌ ๋๊ตฌ ์ฌ์ฉ
โข GitHub ๋ฑ์ ์ค์๋ก ์ฌ๋ฆฌ์ง ์๋๋ก .gitignore ์ค์
โข ์ ๊ธฐ์ ์ผ๋ก ํค๋ฅผ ๊ฐฑ์
2. ์ฌ์ฉ์ ์
๋ ฅ ๊ฒ์ฆ
โข ์
์์ ์ธ ํ๋กฌํํธ ์ธ์ ์
๋ฐฉ์ง
โข ์
๋ ฅ ๊ธธ์ด ์ ํ
โข ๋ฏผ๊ฐํ ์ ๋ณด ํํฐ๋ง
3. Rate Limiting
โข ๊ณผ๋ํ API ํธ์ถ ๋ฐฉ์ง
โข ์ฌ์ฉ์๋ณ ์์ฒญ ์ ํ ์ค์
โข ๋น์ฉ ํญํ ๋ฐฉ์ง
๐ก ์ฑ๋ฅ ์ต์ ํ
1. ์ ์ ํ ๋ชจ๋ธ ์ ํ
โข ์์
์ ๋ง๋ ์ต์ ์ฌ์ ๋ชจ๋ธ ์ฌ์ฉ
โข ๊ฐ๋จํ ์์
์ GPT-4 ์ฌ์ฉ ์์
2. ํ๋กฌํํธ ์ต์ ํ
โข ๋ช
ํํ๊ณ ๊ตฌ์ฒด์ ์ธ ์ง์
โข ๋ถํ์ํ ์ปจํ
์คํธ ์ ๊ฑฐ
โข ์์ ํฌํจ์ผ๋ก ์ ํ๋ ํฅ์
3. ์บ์ฑ ํ์ฉ
โข ๋ฐ๋ณต๋๋ ์์ฒญ์ ์บ์ฑ
โข ๋ฐ์ดํฐ๋ฒ ์ด์ค๋ Redis ํ์ฉ
4. ๋ฐฐ์น ์ฒ๋ฆฌ
โข ์ฌ๋ฌ ์์ฒญ์ ๋ฌถ์ด์ ์ฒ๋ฆฌ
โข ๋น๋๊ธฐ ์ฒ๋ฆฌ๋ก ์ฑ๋ฅ ํฅ์
๐ ๋ชจ๋ํฐ๋ง
1. ์ฌ์ฉ๋ ์ถ์
โข ํ ํฐ ์ฌ์ฉ๋ ๋ก๊น
โข ๋น์ฉ ๋ชจ๋ํฐ๋ง
โข ์๋ฆผ ์ค์ (์์ฐ ์ด๊ณผ ์)
2. ์๋ฌ ๋ก๊น
โข ๋ชจ๋ API ์๋ฌ ๊ธฐ๋ก
โข ์๋ฌ ํจํด ๋ถ์
โข ์๋ ์๋ฆผ ์์คํ
3. ์ฑ๋ฅ ๋ฉํธ๋ฆญ
โข ์๋ต ์๊ฐ ์ธก์
โข ์ฑ๊ณต๋ฅ ์ถ์
โข ์ฌ์ฉ์ ๋ง์กฑ๋ ์์ง
๐ฏ ์ฌ์ฉ์ ๊ฒฝํ
1. ์๋ต ์๊ฐ ๊ด๋ฆฌ
โข ์คํธ๋ฆฌ๋ฐ์ผ๋ก ์ฆ๊ฐ์ ์ธ ํผ๋๋ฐฑ
โข ๋ก๋ฉ ์ธ๋์ผ์ดํฐ ํ์
โข ํ์์์ ์ค์
2. ์๋ฌ ์ฒ๋ฆฌ
โข ์ฌ์ฉ์ ์นํ์ ์ธ ์๋ฌ ๋ฉ์์ง
โข ์ฌ์๋ ์ต์
์ ๊ณต
โข ๋์ฒด ๋ฐฉ์ ์๋ด
3. ํฌ๋ช
์ฑ
โข AI ์ฌ์ฉ ์ฌ์ค ๋ช
์
โข ํ๊ณ์ ์ค๋ช
โข ํผ๋๋ฐฑ ์์ง ๋ฉ์ปค๋์ฆ
โข ๊ฐ์ธ์ ๋ณด ๋ณดํธ๋ฒ ์ค์
โข ์ ์๊ถ ๋ฌธ์ ์ฃผ์
โข AI ์์ฑ ์ฝํ ์ธ ๋ช ์
โข ํธํฅ์ฑ๊ณผ ๊ณต์ ์ฑ ๊ณ ๋ ค
โข ์ ์ฉ ๋ฐฉ์ง ์กฐ์น
๐ ๋ ๋ฐฐ์ฐ๊ณ ์ถ๋ค๋ฉด
์ด ๊ธ์์ ChatGPT API์ ๊ธฐ์ด๋ถํฐ ์ค์ ํ์ฉ๊น์ง ๋ค๋ค์ง๋ง, AI ๋ถ์ผ๋ ์ ๋ง ๋น ๋ฅด๊ฒ ๋ฐ์ ํ๊ณ ์์ด. ๊ณ์ ํ์ตํ๊ณ ์คํํ๋ ๊ฒ ์ค์ํด! ๐
๐ ์ถ์ฒ ํ์ต ์๋ฃ
๊ณต์ ๋ฌธ์:
โข OpenAI API Documentation
โข OpenAI Cookbook (์ค์ ์์ ๋ชจ์)
โข OpenAI Community Forum
์ถ๊ฐ ํ์ต ์ฃผ์ :
โข LangChain: AI ์ ํ๋ฆฌ์ผ์ด์
ํ๋ ์์ํฌ
โข Vector Databases: ์๋ฒ ๋ฉ ์ ์ฅ ๋ฐ ๊ฒ์
โข Prompt Engineering: ํจ๊ณผ์ ์ธ ํ๋กฌํํธ ์์ฑ๋ฒ
โข Fine-tuning: ๋ชจ๋ธ ์ปค์คํฐ๋ง์ด์ง
โข RAG (Retrieval-Augmented Generation): ๋ฌธ์ ๊ธฐ๋ฐ QA ์์คํ
์ค์ต ํ๋ก์ ํธ ์์ด๋์ด:
โข ๊ฐ์ธ ๋น์ ์ฑ๋ด
โข ๋ฌธ์ ์์ฝ ๋๊ตฌ
โข ์ฝ๋ ๋ฆฌ๋ทฐ ์๋ํ
โข ์ธ์ด ํ์ต ์ฑ
โข ๊ฐ์ ๋ถ์ ๋๊ตฌ
โข ์๋ ์ด๋ฉ์ผ ์์ฑ๊ธฐ
โข ์ค์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐ ์ง์ค
โข ์ปค๋ฎค๋ํฐ์ ์ฐธ์ฌํด์ ๊ฒฝํ ๊ณต์
โข ์ต์ ์ ๋ฐ์ดํธ ๊ณ์ ํ์ธ
โข ๋ค์ํ ํ๋ผ๋ฏธํฐ๋ก ์คํํด๋ณด๊ธฐ
โข ์๋ฌ๋ฅผ ๋๋ ค์ํ์ง ๋ง๊ณ ๋๋ฒ๊น ์ฐ์ต
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์! ์ฌ๊ธฐ๊น์ง ์ฝ์๋ค๋ฉด ์ ๋ง ๋๋จํด! ๐
์ฐ๋ฆฌ๋ ChatGPT API์ ๊ธฐ์ด๋ถํฐ ์์ํด์ ์ค์ ํ๋ก์ ํธ๊น์ง ์ ๋ง ๋ง์ ๋ด์ฉ์ ๋ค๋ค์ด. API ํค ๋ฐ๊ธ๋ถํฐ ์์ํด์, ๊ธฐ๋ณธ์ ์ธ ์ฑํ
, ๋ํ ํ์คํ ๋ฆฌ ๊ด๋ฆฌ, ์คํธ๋ฆฌ๋ฐ, ์๋ฌ ์ฒ๋ฆฌ, ๋น์ฉ ์ต์ ํ, ์น ์ ํ๋ฆฌ์ผ์ด์
ํตํฉ, ๊ทธ๋ฆฌ๊ณ ๊ณ ๊ธ ๊ธฐ๋ฅ๋ค๊น์ง ๋ง์ด์ผ.
์ด์ ๋๋ Python์ผ๋ก ChatGPT API๋ฅผ ์์ ์์ฌ๋ก ๋ค๋ฃฐ ์ ์๋ ๋ฅ๋ ฅ์ ๊ฐ์ท์ด! ์ด ๊ธฐ์ ์ ์ ๋ง ๊ฐ๋ ฅํ๊ณ , ์์ผ๋ก ๋์ฑ ์ค์ํด์ง ๊ฑฐ์ผ. AI๋ ์ด์ ์ ํ์ด ์๋๋ผ ํ์๊ฐ ๋์ด๊ฐ๊ณ ์๊ฑฐ๋ . ๐
๊ฐ์ฅ ์ค์ํ ๊ฑด ์ง์ ํด๋ณด๋ ๊ฑฐ์ผ! ์ด ๊ธ์ ์ฝ๋ ๊ฒ๋ง์ผ๋ก๋ ๋ถ์กฑํด. ์ค์ ๋ก ์ฝ๋๋ฅผ ์์ฑํ๊ณ , ์๋ฌ๋ฅผ ๋ง๋๊ณ , ํด๊ฒฐํ๋ฉด์ ์ง์ง ์ค๋ ฅ์ด ๋์ด๋๋ ๊ฑฐ์ง. ์์ ํ๋ก์ ํธ๋ถํฐ ์์ํด์ ์ ์ ๋ณต์กํ ๊ฑธ ๋ง๋ค์ด๋ด.
๊ทธ๋ฆฌ๊ณ ํน์ AI ๊ฐ๋ฐ ๊ด๋ จํด์ ๋์์ด ํ์ํ๊ฑฐ๋, ์์ ์ ์ฌ๋ฅ์ ๊ณต์ ํ๊ณ ์ถ๋ค๋ฉด ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์ ํ์ฉํด๋ณด๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ด์ผ. ๋ฐฐ์ฐ๋ฉด์ ๋์์ ์์ต๋ ์ฐฝ์ถํ ์ ์์ผ๋๊น!
AI ๊ธฐ์ ์ ๊ณ์ ๋ฐ์ ํ๊ณ ์์ด. ์ค๋ ๋ฐฐ์ด ๋ด์ฉ์ด ๋ด์ผ์ด๋ฉด ๋ ์
๋ฐ์ดํธ๋ ์๋ ์์ง. ๊ทธ๋ฌ๋๊น ๊ณ์ ํ์ตํ๊ณ , ์คํํ๊ณ , ์ปค๋ฎค๋ํฐ์ ์ํตํ๋ฉด์ ์ฑ์ฅํด๋๊ฐ์! ๐ช
์ง๋ฌธ์ด๋ ๋งํ๋ ๋ถ๋ถ์ด ์์ผ๋ฉด OpenAI ๊ณต์ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ๊ฑฐ๋, ๊ฐ๋ฐ์ ์ปค๋ฎค๋ํฐ์ ๋ฌผ์ด๋ณด๋ ๊ฒ๋ ์ข์. ํผ์ ๊ณ ๋ฏผํ์ง ๋ง๊ณ ์ ๊ทน์ ์ผ๋ก ๋์์ ๊ตฌํ์!
์, ์ด์ ์ปดํจํฐ ์์ ์์์ ์ง์ ์ฝ๋ฉ์ ์์ํด๋ณผ ์๊ฐ์ด์ผ! ๋๋ง์ ๋ฉ์ง AI ์ ํ๋ฆฌ์ผ์ด์
์ ๋ง๋ค์ด๋ด. ํ์ดํ
! ๐ฅโจ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.