from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.chat_models import ChatOpenAI
from dotenv import load_dotenv
import os
from langchain.chains import SimpleSequentialChain

# Create a .env file in the root of your project and add your OpenAI API key to it
# Load env files
load_dotenv()
openai_api_key = os.environ.get('openai_api_key')

# This is an LLMChain to generate company names given a company description.
llm = ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo")

# Create templates
template_name = """You are a company name generator. Based on a company description, it is your job to create a company name.

Company description: {company_description}

Company name:"""

prompt_template_name = PromptTemplate(input_variables=["company_description"], template=template_name)

# This is an LLMChain to generate company slogans given a company name and company description.

template_slogan = """You are a company slogan generator. Based on a company name, it is your job to create a company slogan.

Company name: {company_name}


Company slogan:"""

prompt_template_slogan = PromptTemplate(input_variables=["company_name"], template=template_slogan)

# Create chains
name_chain = LLMChain(llm=llm, prompt=prompt_template_name)
slogan_chain = LLMChain(llm=llm, prompt=prompt_template_slogan)

# This is the overall chain where we run these two chains in sequence.
overall_chain = SimpleSequentialChain(chains=[name_chain, slogan_chain], verbose=True)

slogan = overall_chain.run("We are a company that sells shoes.")

langchain.chains.LLMChain langchain.chains.SimpleSequentialChain langchain.prompts.PromptTemplate langchain.chat_models.ChatOpenAI
[((321, 334), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (332, 334), False, 'from dotenv import load_dotenv\n'), ((352, 384), 'os.environ.get', 'os.environ.get', (['"""openai_api_key"""'], {}), "('openai_api_key')\n", (366, 384), False, 'import os\n'), ((469, 524), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'temperature': '(0.7)', 'model_name': '"""gpt-3.5-turbo"""'}), "(temperature=0.7, model_name='gpt-3.5-turbo')\n", (479, 524), False, 'from langchain.chat_models import ChatOpenAI\n'), ((757, 836), 'langchain.prompts.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['company_description']", 'template': 'template_name'}), "(input_variables=['company_description'], template=template_name)\n", (771, 836), False, 'from langchain.prompts import PromptTemplate\n'), ((1137, 1211), 'langchain.prompts.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['company_name']", 'template': 'template_slogan'}), "(input_variables=['company_name'], template=template_slogan)\n", (1151, 1211), False, 'from langchain.prompts import PromptTemplate\n'), ((1242, 1288), 'langchain.chains.LLMChain', 'LLMChain', ([], {'llm': 'llm', 'prompt': 'prompt_template_name'}), '(llm=llm, prompt=prompt_template_name)\n', (1250, 1288), False, 'from langchain.chains import LLMChain\n'), ((1304, 1352), 'langchain.chains.LLMChain', 'LLMChain', ([], {'llm': 'llm', 'prompt': 'prompt_template_slogan'}), '(llm=llm, prompt=prompt_template_slogan)\n', (1312, 1352), False, 'from langchain.chains import LLMChain\n'), ((1441, 1511), 'langchain.chains.SimpleSequentialChain', 'SimpleSequentialChain', ([], {'chains': '[name_chain, slogan_chain]', 'verbose': '(True)'}), '(chains=[name_chain, slogan_chain], verbose=True)\n', (1462, 1511), False, 'from langchain.chains import SimpleSequentialChain\n')]