94 lines
2.8 KiB
Python
94 lines
2.8 KiB
Python
from openai import AsyncOpenAI
|
|
|
|
from config import apikey_settings
|
|
|
|
|
|
class ChatgptService:
|
|
def __init__(self):
|
|
self.model = "gpt-4o"
|
|
self.client = AsyncOpenAI(api_key=apikey_settings.CHATGPT_API_KEY)
|
|
|
|
def lyrics_prompt(
|
|
self,
|
|
name,
|
|
address,
|
|
category,
|
|
description,
|
|
season,
|
|
num_of_people,
|
|
people_category,
|
|
genre,
|
|
sample_song=None,
|
|
):
|
|
prompt = f"""
|
|
반드시 한국어로 답변해주세요.
|
|
|
|
당신은 작곡가 입니다.
|
|
|
|
작곡에 대한 영감을 얻기 위해 제가 정보를 제공할게요.
|
|
|
|
업체 이름 : {name}
|
|
업체 주소 : {address}
|
|
업체 카테고리 : {category}
|
|
업체 설명 : {description}
|
|
|
|
가사는 다음 속성들을 기반하여 작곡되어야 합니다.
|
|
|
|
###
|
|
|
|
위의 정보를 토대로 작곡을 이어나가주세요.
|
|
|
|
다음은 노래에 대한 정보입니다.
|
|
|
|
노래의 길이 :
|
|
- 1분 이내입니다.
|
|
- 글자 수는 120자에서 150자 사이로 작성해주세요.
|
|
- 글자가 갑자기 끊기지 않도록 주의해주세요.
|
|
|
|
노래의 특징:
|
|
- 노래에 업체의 이름은 반드시 1번 이상 들어가야 합니다.
|
|
- 노래의 전반부는, 업체에 대한 장점과 특징을 소개하는 가사를 써주세요.
|
|
- 노래의 후반부는, 업체가 위치한 곳을 소개하는 가사를 써주세요.
|
|
|
|
답변에 [전반부], [후반부] 표시할 필요 없이, 가사만 답변해주세요.
|
|
(후크)와 같이 특정 동작에 대해 표시할 필요 없습니다.
|
|
|
|
노래를 한 마디씩 생성할 때마다 글자수를 세어보면서, 글자 수가 150자를 넘지 않도록 주의해주세요.
|
|
|
|
"""
|
|
|
|
if sample_song:
|
|
prompt += f"""
|
|
|
|
다음은 참고해야 하는 샘플 가사 정보입니다.
|
|
|
|
샘플 가사를 참고하여 작곡을 해주세요.
|
|
|
|
{sample_song}
|
|
"""
|
|
|
|
return prompt
|
|
|
|
async def generate_lyrics(self, prompt=None):
|
|
# prompt = self.lyrics_prompt(
|
|
# name,
|
|
# address,
|
|
# category,
|
|
# description,
|
|
# season,
|
|
# num_of_people,
|
|
# people_type,
|
|
# genre,
|
|
# sample_song,
|
|
# )
|
|
|
|
print("Generated Prompt: ", prompt)
|
|
completion = await self.client.chat.completions.create(
|
|
model=self.model, messages=[{"role": "user", "content": prompt}]
|
|
)
|
|
message = completion.choices[0].message.content
|
|
return message
|
|
|
|
|
|
chatgpt_api = ChatgptService()
|