우측 상단에 API Platform 들어가기

들어온 초기 화면

API KEYs 화면에서 새로운 API 키 생성

키생성 완료 주의😅키가 노출되면 지워야 함

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
파이참 -> 터미널 openai 설치

from openai import OpenAI
client = OpenAI(api_key="<API KEY>")
completions = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role':'user', 'content':'너에 대해서 자세히 설명해줘'},
],
temperature=0.2,
max_tokens=512
)
print(completions.choices[0].message.content)
안녕하세요! 저는 OpenAI가 개발한 인공지능 언어 모델인 ChatGPT입니다. 저는 자연어 처리를 기반으로 하여 다양한 질문에 답변하고, 대화를 나누며, 정보를 제공하는 데 사용됩니다. 제 주요 기능과 특징은 다음과 같습니다.
1. **언어 이해 및 생성**: 저는 다양한 주제에 대해 질문을 이해하고, 그에 맞는 답변을 생성할 수 있습니다. 이는 대규모 데이터셋을 바탕으로 학습된 언어 모델 덕분입니다.
2. **다양한 주제 지원**: 과학, 역사, 기술, 문화 등 여러 분야에 걸쳐 질문에 답변할 수 있습니다. 다만, 특정 전문 분야에 대해서는 항상 최신 정보나 전문가의 조언을 참고하는 것이 좋습니다.
3. **대화형 인터페이스**: 사용자와 자연스럽게 대화를 이어갈 수 있으며, 사용자의 요청에 따라 정보를 제공하거나 도움을 줄 수 있습니다.
4. **지속적인 학습과 개선**: 제 모델은 주기적으로 업데이트되며, 사용자 피드백을 통해 지속적으로 개선됩니다.
5. **제한 사항**: 때때로 부정확한 정보를 제공할 수 있으며, 감정이나 의식을 가진 존재는 아닙니다. 또한, 개인 정보 보호를 위해 민감한 정보를 요청하거나 저장하지 않습니다.
궁금한 점이 있으면 언제든지 물어보세요!
종료 코드 0(으)로 완료된 프로세스
from openai import OpenAI
client = OpenAI(api_key="<API KEY>")
sing_data_str = """I tried to be perfect
But nothing was worth it
I don't believe it makes me real
I thought it'd be easy
But no one believes me
I meant all the things I said
If you believe it's in my soul
I'd say all the words that I know
Just to see if it would show
That I'm trying to let you know
That I'm better off on my own
This place is so empty
My thoughts are so tempting
I don't know how it got so bad
Sometimes, it's so crazy
That nothing can save me
But it's the only thing that I have
If you believe it's in my soul
I'd say all the words that I know
Just to see if it would show
That I'm trying to let you know
That I'm better off on my own
On my own
I tried to be perfect
It just wasn't worth it
Nothing could ever be so wrong
It's hard to believe me
It never gets easy
I guess I knew that all along
If you believe it's in my soul
I'd say all the words that I know
Just to see if it would show
That I'm trying to let you know
That I'm better off on my own"""
def word_extractions(sing_data_str, temperature=1, max_tokens=1024):
prompt = f"""
아래에 노래 가사가 있어. 노래 가사에서 랜덤하게 단어 10개를 뽑아줘
노래 가사와 함께 한국어 의미를 같이 표기해줘
추출한 단어로 새로운 문장을 만들어줘
출력 포맷은 다음 JSON 포맷으로 작성해줘
'''
[
{{
"num":1,
"word": "",
"korean": "",
"synonym": "",
"example": "",
}}
]
'''
{sing_data_str}
"""
completions = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role':'user','content':prompt}
],
temperature=temperature,
max_tokens=max_tokens
)
return completions.choices[0].message.content
result = word_extractions(sing_data_str)
print(result)
```json
[
{
"num": 1,
"word": "perfect",
"korean": "완벽한",
"synonym": "flawless",
"example": "I tried to be perfect, but it wasn't worth it."
},
{
"num": 2,
"word": "believe",
"korean": "믿다",
"synonym": "trust",
"example": "I don't believe it makes me real."
},
{
"num": 3,
"word": "real",
"korean": "진짜의",
"synonym": "genuine",
"example": "I don't believe it makes me real."
},
{
"num": 4,
"word": "soul",
"korean": "영혼",
"synonym": "spirit",
"example": "If you believe it's in my soul."
},
{
"num": 5,
"word": "empty",
"korean": "비어 있는",
"synonym": "vacant",
"example": "This place is so empty."
},
{
"num": 6,
"word": "tempting",
"korean": "유혹적인",
"synonym": "enticing",
"example": "My thoughts are so tempting."
},
{
"num": 7,
"word": "crazy",
"korean": "미친",
"synonym": "insane",
"example": "Sometimes, it's so crazy."
},
{
"num": 8,
"word": "own",
"korean": "자신의",
"synonym": "personal",
"example": "I'm better off on my own."
},
{
"num": 9,
"word": "easy",
"korean": "쉬운",
"synonym": "simple",
"example": "It never gets easy."
},
{
"num": 10,
"word": "thoughts",
"korean": "생각",
"synonym": "ideas",
"example": "My thoughts are so tempting."
}
]
새로운 문장:
I believe that my own thoughts, though tempting and sometimes crazy, are part of my real soul, striving for perfection even in an empty, imperfect world.
종료 코드 0(으)로 완료된 프로세스