File size: 1,378 Bytes
1ac2cc0
90cf4ba
1ac2cc0
 
 
 
90cf4ba
 
 
 
 
1ac2cc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os

from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain, SequentialChain

if "OPENAI_API_KEY" not in os.environ:
    from keys import openapi_key

    os.environ["OPENAI_API_KEY"] = openapi_key

llm = OpenAI(temperature=0.7)

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 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"],
)


def generate_restaurant_name_and_items(cuisine: str) -> dict[str, str]:
    return chain({"cuisine": cuisine})
    # return {
    #     "restaurant_name": "Curry Delight",
    #     "menu_items": "Butter Chicken, Naan, Paneer Tikka, Chole Bhature, Lassi, Gulab Jamun",
    # }


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