import os
import langchain
import streamlit as st
from dotenv import load_dotenv
from langchain.chat_models import ChatOpenAI
from langchain.cache import InMemoryCache
from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, ChatPromptTemplate, PromptTemplate


# Config
load_dotenv(".env")
api_key = os.environ.get("key")

# Cache Config
langchain.llm_cache = InMemoryCache()
chat = ChatOpenAI(api_key=api_key, model='gpt-3.5-turbo', max_tokens=500)

st.header("🧇🥞🍳🥛 BrunchBuddy")

st.sidebar.header("Parameters")
slider_value = st.sidebar.slider("Time",  0, 120, 30)
selectbox_value = st.sidebar.selectbox("Type", ("Vegetarian", "Non-Vegetarian"))

system_message = "You are an AI recipe assistant that specialize in {brunch} dishes that can be prepared in {time}"
system_message_prompt = SystemMessagePromptTemplate.from_template(system_message)
human_template = "{recipe_request}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])

prompt_input = st.text_input("What would you like to have for brunch:")
if prompt_input:
    prompt = chat_prompt.format_prompt(time=str(slider_value) + " min", recipe_request=str(prompt_input), brunch=selectbox_value).to_messages()
    st.write(chat(prompt).content)
langchain.cache.InMemoryCache langchain.prompts.HumanMessagePromptTemplate.from_template langchain.chat_models.ChatOpenAI langchain.prompts.ChatPromptTemplate.from_messages langchain.prompts.SystemMessagePromptTemplate.from_template
[((326, 345), 'dotenv.load_dotenv', 'load_dotenv', (['""".env"""'], {}), "('.env')\n", (337, 345), False, 'from dotenv import load_dotenv\n'), ((356, 377), 'os.environ.get', 'os.environ.get', (['"""key"""'], {}), "('key')\n", (370, 377), False, 'import os\n'), ((416, 431), 'langchain.cache.InMemoryCache', 'InMemoryCache', ([], {}), '()\n', (429, 431), False, 'from langchain.cache import InMemoryCache\n'), ((439, 505), 'langchain.chat_models.ChatOpenAI', 'ChatOpenAI', ([], {'api_key': 'api_key', 'model': '"""gpt-3.5-turbo"""', 'max_tokens': '(500)'}), "(api_key=api_key, model='gpt-3.5-turbo', max_tokens=500)\n", (449, 505), False, 'from langchain.chat_models import ChatOpenAI\n'), ((507, 536), 'streamlit.header', 'st.header', (['"""🧇🥞🍳🥛 BrunchBuddy"""'], {}), "('🧇🥞🍳🥛 BrunchBuddy')\n", (516, 536), True, 'import streamlit as st\n'), ((538, 569), 'streamlit.sidebar.header', 'st.sidebar.header', (['"""Parameters"""'], {}), "('Parameters')\n", (555, 569), True, 'import streamlit as st\n'), ((585, 622), 'streamlit.sidebar.slider', 'st.sidebar.slider', (['"""Time"""', '(0)', '(120)', '(30)'], {}), "('Time', 0, 120, 30)\n", (602, 622), True, 'import streamlit as st\n'), ((642, 704), 'streamlit.sidebar.selectbox', 'st.sidebar.selectbox', (['"""Type"""', "('Vegetarian', 'Non-Vegetarian')"], {}), "('Type', ('Vegetarian', 'Non-Vegetarian'))\n", (662, 704), True, 'import streamlit as st\n'), ((846, 903), 'langchain.prompts.SystemMessagePromptTemplate.from_template', 'SystemMessagePromptTemplate.from_template', (['system_message'], {}), '(system_message)\n', (887, 903), False, 'from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, ChatPromptTemplate, PromptTemplate\n'), ((963, 1019), 'langchain.prompts.HumanMessagePromptTemplate.from_template', 'HumanMessagePromptTemplate.from_template', (['human_template'], {}), '(human_template)\n', (1003, 1019), False, 'from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, ChatPromptTemplate, PromptTemplate\n'), ((1034, 1113), 'langchain.prompts.ChatPromptTemplate.from_messages', 'ChatPromptTemplate.from_messages', (['[system_message_prompt, human_message_prompt]'], {}), '([system_message_prompt, human_message_prompt])\n', (1066, 1113), False, 'from langchain.prompts import SystemMessagePromptTemplate, HumanMessagePromptTemplate, AIMessagePromptTemplate, ChatPromptTemplate, PromptTemplate\n'), ((1130, 1186), 'streamlit.text_input', 'st.text_input', (['"""What would you like to have for brunch:"""'], {}), "('What would you like to have for brunch:')\n", (1143, 1186), True, 'import streamlit as st\n')]