Spaces:
Runtime error
Runtime error
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 |