File size: 955 Bytes
a3b0a04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from langchain import OpenAI, LLMChain, PromptTemplate
from langchain.chains import SimpleSequentialChain


# Function to generate title and Logline from simple chaining
def generate_logline(prompt, creativity, api_key):
    # Setting up OpenAI LLM
    llm = OpenAI(temperature=creativity, openai_api_key=api_key,
                 model_name='gpt-3.5-turbo')

    first_template = 'What is a good name for a story about {description}?'
    first_prompt = PromptTemplate.from_template(first_template)
    first_chain = LLMChain(llm=llm, prompt=first_prompt)
    title = first_chain.run(prompt)

    second_template = 'Write a logline for the following story: {story_name}'
    second_prompt = PromptTemplate.from_template(second_template)
    second_chain = LLMChain(llm=llm, prompt=second_prompt)

    simple_chain = SimpleSequentialChain(chains=[first_chain, second_chain], verbose=True)

    logline = simple_chain.run(prompt)

    return title, logline