LiuZiyi's picture
first commit
42c06ff
from langchain_openai import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.chains import SimpleSequentialChain
from langchain.chains import SequentialChain
from secret_key import openapi_key
import os
os.environ['OPENAI_API_KEY'] = openapi_key
llm = OpenAI(temperature=0.6)
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")
prompt_template_items = PromptTemplate(
input_variables = ['restaurant_name'],
template = "Suggest some menu items for {restaurant_name}. Return it as a comma separated list. "
)
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.invoke("American")
print(response)
# {'cuisine': 'American', 'restaurant_name': '\n\n"Stateside Eats" ', 'menu_items': '\n\n1. New York-style pizza\n2. California burger\n3. Texas BBQ ribs\n4. Louisiana-style gumbo\n5. Chicago-style deep dish pizza\n6. Maine lobster roll\n7. Florida key lime pie\n8. Georgia peach cobbler\n9. Kentucky fried chicken\n10. Arizona chimichangas\n11. Tennessee hot chicken sandwich\n12. Hawaii poke bowl\n13. Wisconsin cheese curds\n14. Virginia ham biscuits\n15. Colorado green chili.'}