Spaces:
Runtime error
Runtime error
Commit ·
a3b0a04
1
Parent(s): 4b3eec6
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain import OpenAI, LLMChain, PromptTemplate
|
| 2 |
+
from langchain.chains import SimpleSequentialChain
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# Function to generate title and Logline from simple chaining
|
| 6 |
+
def generate_logline(prompt, creativity, api_key):
|
| 7 |
+
# Setting up OpenAI LLM
|
| 8 |
+
llm = OpenAI(temperature=creativity, openai_api_key=api_key,
|
| 9 |
+
model_name='gpt-3.5-turbo')
|
| 10 |
+
|
| 11 |
+
first_template = 'What is a good name for a story about {description}?'
|
| 12 |
+
first_prompt = PromptTemplate.from_template(first_template)
|
| 13 |
+
first_chain = LLMChain(llm=llm, prompt=first_prompt)
|
| 14 |
+
title = first_chain.run(prompt)
|
| 15 |
+
|
| 16 |
+
second_template = 'Write a logline for the following story: {story_name}'
|
| 17 |
+
second_prompt = PromptTemplate.from_template(second_template)
|
| 18 |
+
second_chain = LLMChain(llm=llm, prompt=second_prompt)
|
| 19 |
+
|
| 20 |
+
simple_chain = SimpleSequentialChain(chains=[first_chain, second_chain], verbose=True)
|
| 21 |
+
|
| 22 |
+
logline = simple_chain.run(prompt)
|
| 23 |
+
|
| 24 |
+
return title, logline
|