반응형

OpenAI 채팅 API에서 메시지 역할(Message Roles)과 지시문 준수(Instruction Following)를 잘 따르면,
“누가”, “무엇을”, “어떻게” 말하는지를 명확하게 구분할 수 있고, LLM을 보다 통제 가능하고 예측 가능한 방식으로 사용할 수 있다.
Prompt Engineering 관련글 참고
2025.07.07 - [🎪 놀고있네/OpenAI] - [OpenAI] Prompt Engineering - instructions
[OpenAI] Prompt Engineering - instructions
어떻게 묻느냐가 AI의 무엇을, 어떻게 답할지를 결정한다. 프롬프트 엔지니어링(Prompt Engineering)이란, AI—특히 대형 언어 모델(LLM)—에게 원하는 답을 얻기 위해 “어떤 질문을, 어떤 방식으로”
miaow-miaow.tistory.com
.json 로드하기
미리 작성해둔 프롬프트 json 파일이다.

아래 코드에 추가해서 실행
import json
from openai import OpenAI
client = OpenAI()
# 프롬프트 파일 읽기
with open("prompts/weather_report.json", "r", encoding="utf-8") as f:
system_prompt_msg = json.load(f)
response = client.chat.completions.create(
model="gpt-4.1",
messages=[
system_prompt_msg,
{"role": "user", "content": "오늘 한국의 날씨를 알려줘"}
]
)
print(response) # 전체 response 를 얻어옴
print(response.choices[0].message.content) # 답변만 얻어옴
https://platform.openai.com/docs/guides/text#message-roles-and-instruction-following
https://platform.openai.com/docs/guides/text#reusable-prompts
반응형
'🎪 놀고있네 > AI' 카테고리의 다른 글
| [MCP] MCP(Model Context Protocol) 설명 (0) | 2026.01.26 |
|---|---|
| [OpenAI] Prompt 사용하기(.txt) (0) | 2025.07.21 |
| [OpenAI] instructions(지시문)과 메세지 역할 (1) | 2025.07.08 |
| [OpenAI] Prompt Engineering - instructions (0) | 2025.07.07 |
| [OpenAI] 환경세팅(with Python) (2) | 2025.07.04 |
댓글