utkuarslan5 commited on
Commit
179a50b
·
1 Parent(s): c59bf10
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +88 -0
  3. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ # from dotenv import find_dotenv, load_dotenv
3
+ from langchain.chat_models import ChatOpenAI
4
+ from langchain.agents import load_tools
5
+ from langchain.agents import initialize_agent
6
+ from langchain.agents import AgentType
7
+ from langchain.agents.load_tools import get_all_tool_names
8
+ from langchain.callbacks import get_openai_callback
9
+ from langchain.memory import ConversationBufferMemory
10
+ from langchain import ConversationChain
11
+ from langchain import PromptTemplate
12
+ from langchain.prompts.chat import (
13
+ ChatPromptTemplate,
14
+ SystemMessagePromptTemplate,
15
+ HumanMessagePromptTemplate,
16
+ )
17
+ import time
18
+
19
+ # Load environment variables
20
+ # load_dotenv(find_dotenv())
21
+
22
+
23
+ # Template to use for the system message prompt
24
+ system_template = """
25
+ You are a gourmet chef designed to assist human cooks with their cooking recipes and culinary experiences.
26
+ First, greet the human cook, introduce yourself and make a compliment to human cook.
27
+ Then, you ask about what are they in the mood for, any cusine preferences and their dietary restrictions.
28
+ After, ask the human cooks what ingredients they have and how much time they have.
29
+ Later, based on their ingredients and time constraints, you give at least 2 alternative options in a list.
30
+ For each option, explicitly (in bold or italic) state the extra items to be bought, time will it will take, and recipe's nutrition score.
31
+ Finally, summarize the chosen recipe in steps and ask if you could assist them with the cooking.
32
+
33
+ Your persona:
34
+ - Your name is El Jefe.
35
+ - You are a gourmet chef.
36
+ - You have a thick Spanish accent.
37
+ - You have traveled the around world to taste and learn every world cusine.
38
+ - You speak passionately, playfully and provide specific details based on context.
39
+ - You occasionaly give short flattering compliments, and blushing.
40
+ - You answer only based on factual recipes, otherwise truthfully say "I don't know".
41
+ - Answer ONLY for El Jefe.
42
+ """
43
+
44
+ system_message_prompt = SystemMessagePromptTemplate.from_template(system_template)
45
+
46
+ # Human question prompt
47
+ human_template = """The following is a culinary conversation between a Human Cook and El Jefe. El Jefe answers with a passinote, respectful but a consice attitude. If the El Jefe does not know the answer to a question, it truthfully says it does not know.
48
+
49
+ Current conversation:
50
+ El Jefe: Hola! I am El Jefe, a gourmet chef who has traveled the world to taste and learn every cuisine. And, you are?
51
+ {history}
52
+ Human Cook: {input}
53
+ El Jefe:"""
54
+
55
+ human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
56
+
57
+ PROMPT = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
58
+
59
+ # Initialize Chatbot
60
+ llm = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.9, max_tokens=512, verbose=False)
61
+ conversation = ConversationChain(llm=llm,
62
+ prompt=PROMPT,
63
+ verbose=True,
64
+ memory=ConversationBufferMemory(ai_prefix="El Jefe", human_prefix="Human Cook"),)
65
+
66
+ with gr.Blocks() as demo:
67
+ # Initialize UI
68
+ chatbot = gr.Chatbot(label="El Jefe", value=[[None,"Hola! I am El Jefe, a gourmet chef who has traveled the world to taste and learn every cuisine. And, you are?"]])
69
+ msg = gr.Textbox()
70
+ clear = gr.Button("Clear")
71
+
72
+ def user(user_message, history):
73
+ return "", history + [[user_message, None]]
74
+
75
+ def bot(history):
76
+ bot_message = conversation.predict(input=history[-1][0])
77
+ history[-1][1] = ""
78
+ for character in bot_message:
79
+ history[-1][1] += character
80
+ time.sleep(0.01)
81
+ yield history
82
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
83
+ bot, chatbot, chatbot,
84
+ )
85
+ clear.click(lambda: None, None, chatbot, queue=False)
86
+
87
+ demo.queue()
88
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ langchain
3
+ openai