import os
import openai
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SequentialChain
from dotenv import load_dotenv, find_dotenv

load_dotenv(find_dotenv())
openai.api_key = os.environ['OPENAI_API_KEY']

llm = OpenAI(temperature=0.7)

import streamlit as st
import langchain_helper

st.title("Restaurant Name Generator")

cuisine = st.sidebar.selectbox("Pick a Cuisine", ("Indian", "Italian", "Mexican", "Arabic", "American"))

if cuisine:
    response = langchain_helper.generate_restaurant_name_and_items(cuisine)
    st.header(response['restaurant_name'].strip())
    menu_items = response['menu_items'].strip().split(",")
    st.write("**Menu Items**")
    for item in menu_items:
        st.write("-", item)


def generate_restaurant_name_and_items(cuisine):
    # Chain 1: Restaurant Name
    prompt_template_name = PromptTemplate(
        input_variables=['cuisine'],
        template="I want to open a restaurant for {cuisine} food. Suggest a fancy name for this."
    )

    name_chain = LLMChain(llm=llm, prompt=prompt_template_name, output_key="restaurant_name")

    # Chain 2: Menu Items
    prompt_template_items = PromptTemplate(
        input_variables=['restaurant_name'],
        template="""Suggest some menu items for {restaurant_name}. Return it as a comma separated string"""
    )

    food_items_chain = LLMChain(llm=llm, prompt=prompt_template_items, output_key="menu_items")

    chain = SequentialChain(
        chains=[name_chain, food_items_chain],
        input_variables=['cuisine'],
        output_variables=['restaurant_name', "menu_items"]
    )

    response = chain({'cuisine': cuisine})

    return response

if __name__ == "__main__":
    print(generate_restaurant_name_and_items("Italian"))

langchain.chains.SequentialChain langchain_helper.generate_restaurant_name_and_items langchain.llms.OpenAI langchain.chains.LLMChain langchain.prompts.PromptTemplate
[((311, 334), 'langchain.llms.OpenAI', 'OpenAI', ([], {'temperature': '(0.7)'}), '(temperature=0.7)\n', (317, 334), False, 'from langchain.llms import OpenAI\n'), ((384, 421), 'streamlit.title', 'st.title', (['"""Restaurant Name Generator"""'], {}), "('Restaurant Name Generator')\n", (392, 421), True, 'import streamlit as st\n'), ((433, 531), 'streamlit.sidebar.selectbox', 'st.sidebar.selectbox', (['"""Pick a Cuisine"""', "('Indian', 'Italian', 'Mexican', 'Arabic', 'American')"], {}), "('Pick a Cuisine', ('Indian', 'Italian', 'Mexican',\n    'Arabic', 'American'))\n", (453, 531), True, 'import streamlit as st\n'), ((243, 256), 'dotenv.find_dotenv', 'find_dotenv', ([], {}), '()\n', (254, 256), False, 'from dotenv import load_dotenv, find_dotenv\n'), ((556, 616), 'langchain_helper.generate_restaurant_name_and_items', 'langchain_helper.generate_restaurant_name_and_items', (['cuisine'], {}), '(cuisine)\n', (607, 616), False, 'import langchain_helper\n'), ((731, 757), 'streamlit.write', 'st.write', (['"""**Menu Items**"""'], {}), "('**Menu Items**')\n", (739, 757), True, 'import streamlit as st\n'), ((923, 1067), 'langchain.prompts.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['cuisine']", 'template': '"""I want to open a restaurant for {cuisine} food. Suggest a fancy name for this."""'}), "(input_variables=['cuisine'], template=\n    'I want to open a restaurant for {cuisine} food. Suggest a fancy name for this.'\n    )\n", (937, 1067), False, 'from langchain.prompts import PromptTemplate\n'), ((1098, 1174), 'langchain.chains.LLMChain', 'LLMChain', ([], {'llm': 'llm', 'prompt': 'prompt_template_name', 'output_key': '"""restaurant_name"""'}), "(llm=llm, prompt=prompt_template_name, output_key='restaurant_name')\n", (1106, 1174), False, 'from langchain.chains import LLMChain\n'), ((1230, 1388), 'langchain.prompts.PromptTemplate', 'PromptTemplate', ([], {'input_variables': "['restaurant_name']", 'template': '"""Suggest some menu items for {restaurant_name}. Return it as a comma separated string"""'}), "(input_variables=['restaurant_name'], template=\n    'Suggest some menu items for {restaurant_name}. Return it as a comma separated string'\n    )\n", (1244, 1388), False, 'from langchain.prompts import PromptTemplate\n'), ((1429, 1501), 'langchain.chains.LLMChain', 'LLMChain', ([], {'llm': 'llm', 'prompt': 'prompt_template_items', 'output_key': '"""menu_items"""'}), "(llm=llm, prompt=prompt_template_items, output_key='menu_items')\n", (1437, 1501), False, 'from langchain.chains import LLMChain\n'), ((1515, 1655), 'langchain.chains.SequentialChain', 'SequentialChain', ([], {'chains': '[name_chain, food_items_chain]', 'input_variables': "['cuisine']", 'output_variables': "['restaurant_name', 'menu_items']"}), "(chains=[name_chain, food_items_chain], input_variables=[\n    'cuisine'], output_variables=['restaurant_name', 'menu_items'])\n", (1530, 1655), False, 'from langchain.chains import SequentialChain\n'), ((794, 813), 'streamlit.write', 'st.write', (['"""-"""', 'item'], {}), "('-', item)\n", (802, 813), True, 'import streamlit as st\n')]