first commit
This commit is contained in:
commit
1ff70c7925
71 files changed
+4175
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,93 @@
|
||||
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()
|
||||
@@ -0,0 +1,24 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from config import cors_settings
|
||||
|
||||
# sys.path.append(
|
||||
# os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
# ) # root 경로 추가
|
||||
|
||||
|
||||
class CustomCORSMiddleware:
|
||||
def __init__(self, app: FastAPI):
|
||||
self.app = app
|
||||
|
||||
def configure_cors(self):
|
||||
self.app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=cors_settings.CORS_ALLOW_ORIGINS,
|
||||
allow_credentials=cors_settings.CORS_ALLOW_CREDENTIALS,
|
||||
allow_methods=cors_settings.CORS_ALLOW_METHODS,
|
||||
allow_headers=cors_settings.CORS_ALLOW_HEADERS,
|
||||
expose_headers=cors_settings.CORS_EXPOSE_HEADERS,
|
||||
max_age=cors_settings.CORS_MAX_AGE,
|
||||
)
|
||||
Reference in new issue
Block a user