Spaces:
Running
Running
OmPrakashSingh1704
commited on
Commit
•
3e8ab70
1
Parent(s):
a70a2ab
Update app.py
Browse files
app.py
CHANGED
@@ -56,68 +56,67 @@ def create_detailed_prompt(user_direction, exclusions, serving_size, difficulty)
|
|
56 |
|
57 |
def generate_recipe(user_inputs):
|
58 |
with st.spinner('Building the perfect recipe...'):
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
}
|
84 |
}
|
85 |
-
}
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
}
|
100 |
}
|
101 |
}
|
102 |
-
}
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
}
|
111 |
-
|
112 |
-
}
|
113 |
-
]
|
114 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
115 |
messages = [{"role": "user", "content": prompt}]
|
116 |
text = tokenizer.apply_chat_template(
|
117 |
messages,
|
118 |
tokenize=False,
|
119 |
add_generation_prompt=True,
|
120 |
-
tools=
|
121 |
)
|
122 |
|
123 |
# Tokenize and move to the correct device
|
|
|
56 |
|
57 |
def generate_recipe(user_inputs):
|
58 |
with st.spinner('Building the perfect recipe...'):
|
59 |
+
provide_recipe_schema = {
|
60 |
+
'type': 'function',
|
61 |
+
'function': {
|
62 |
+
'name': 'provide_recipe',
|
63 |
+
'description': 'Provides a detailed recipe strictly adhering to the user input/specifications, especially ingredient exclusions and the recipe difficulty',
|
64 |
+
'parameters': {
|
65 |
+
'type': 'object',
|
66 |
+
'properties': {
|
67 |
+
'name': {
|
68 |
+
'type': 'string',
|
69 |
+
'description': 'A creative name for the recipe'
|
70 |
+
},
|
71 |
+
'description': {
|
72 |
+
'type': 'string',
|
73 |
+
'description': 'a brief one-sentence description of the provided recipe'
|
74 |
+
},
|
75 |
+
'ingredients': {
|
76 |
+
'type': 'array',
|
77 |
+
'items': {
|
78 |
+
'type': 'object',
|
79 |
+
'properties': {
|
80 |
+
'name': {
|
81 |
+
'type': 'string',
|
82 |
+
'description': 'Quantity and name of the ingredient'
|
83 |
+
}
|
84 |
}
|
85 |
}
|
86 |
+
},
|
87 |
+
'instructions': {
|
88 |
+
'type': 'array',
|
89 |
+
'items': {
|
90 |
+
'type': 'object',
|
91 |
+
'properties': {
|
92 |
+
'step_number': {
|
93 |
+
'type': 'number',
|
94 |
+
'description': 'The sequence number of this step'
|
95 |
+
},
|
96 |
+
'instruction': {
|
97 |
+
'type': 'string',
|
98 |
+
'description': 'Detailed description of what to do in this step'
|
99 |
+
}
|
100 |
}
|
101 |
}
|
102 |
}
|
103 |
+
},
|
104 |
+
'required': [
|
105 |
+
'name',
|
106 |
+
'description',
|
107 |
+
'ingredients',
|
108 |
+
'instructions'
|
109 |
+
]
|
110 |
+
}
|
111 |
+
}
|
112 |
+
}
|
|
|
|
|
113 |
prompt = create_detailed_prompt(user_inputs['user_direction'], user_inputs['exclusions'], user_inputs['serving_size'], user_inputs['difficulty'])
|
114 |
messages = [{"role": "user", "content": prompt}]
|
115 |
text = tokenizer.apply_chat_template(
|
116 |
messages,
|
117 |
tokenize=False,
|
118 |
add_generation_prompt=True,
|
119 |
+
tools=[provide_recipe_schema]
|
120 |
)
|
121 |
|
122 |
# Tokenize and move to the correct device
|