TIL 240522

hyeo71·2024년 5월 22일
0

2024 내배캠 AI 트랙

목록 보기
99/108

시놉시스 생성하기

AI를 사용하여 소설을 만들기 위해 소설의 기본적인 배경을 생성하고 그에 맞게 소설을 생성하기 위해 시놉시스를 AI가 생성하도록 하려한다.

본인이 평소에 관심이 있는 소설과 원하는 장르를 입력하여 AI가 적당한 시놉시스를 만드는 것을 목표로 한다.

랭체인을 사용하여 example예시를 주고 AI에게 예시에 맞는 대답을 하도록 설정하고 시놉시스를 생성한다.

llm = ChatOpenAI(
    model="gpt-3.5-turbo", api_key=os.getenv("OPENAI_API_KEY"), max_tokens=800
)

examples = [
    {
        "novel": "Harry Potter",
        "genre": "fantasy",
        "answer": """
            (The answer of the AI you want)
        """,
    },
    {
        "novel": "Miracles of the Namiya General Store",
        "genre": "mystery",
        "answer": """
            (The answer of the AI you want)
        """,
    },
]

example_prompt = ChatPromptTemplate.from_messages(
    [
        (
            "human",
            "I'm going to make a new novel by referring to the novel {novel}. I'm going to make the genre {genre}. Please make a synopsis.",
        ),
        ("ai", "{answer}"),
    ]
)

example_prompt = FewShotChatMessagePromptTemplate(
    example_prompt=example_prompt,
    examples=examples,
)

final_prompt = ChatPromptTemplate.from_messages(
    [
        ("system", "You are an expert in fiction"),
        example_prompt,
        (
            "human",
            "I'm going to make a new novel by referring to the novel {novel}. I'm going to make the genre {genre}. Please make a synopsis.",
        ),
    ]
)

chain = final_prompt | llm

chain.invoke({"novel": "twilight", "genre": "Romance"})

In the small town of Moonlight Falls, a new student named Luna arrives at Moonlight High School. Luna is mysterious and keeps to herself, but she captures the attention of the popular and enigmatic student, Blake. As they get to know each other, Luna reveals that she is not entirely human - she is a descendant of a powerful supernatural bloodline that has been kept secret for generations. Blake is drawn to Luna's otherworldly charm and the two develop a deep connection despite the dangers that come with Luna's true identity. However, their forbidden love is put to the test when a rival supernatural clan threatens to expose Luna's secret and tear them apart. Luna and Blake must navigate the treacherous world of supernatural politics and fight for their love against all odds.

Moonlight Falls라는 작은 마을에서 루나라는 이름의 새로운 학생이 Moonlight High School에 도착합니다. 루나는 신비롭고 비밀에 부쳐지지만, 그녀는 인기 있고 수수께끼 같은 학생인 블레이크의 관심을 사로잡습니다. 그들이 서로에 대해 알게 되면서, 루나는 완전히 인간이 아니라는 것을 드러냅니다. 블레이크는 루나의 세속적인 매력에 매료되고, 루나의 진짜 정체성에 따르는 위험에도 불구하고 두 사람은 깊은 관계를 발전시킵니다. 그러나, 그들의 금지된 사랑은 라이벌 초자연적인 일족이 루나의 비밀을 폭로하고 그들을 찢어버리겠다고 위협할 때 시험대에 오릅니다. 루나와 블레이크는 초자연적인 정치의 위험한 세계를 탐색하고 모든 역경에 맞서 그들의 사랑을 위해 싸워야 합니다.```

0개의 댓글