shigeru saito commited on
Commit
d1165c1
·
1 Parent(s): 13cce5c

schemaをjsonから取得するように修正

Browse files
Files changed (2) hide show
  1. app.py +7 -93
  2. schema.json +95 -0
app.py CHANGED
@@ -49,6 +49,12 @@ def get_filetext(filename, cache={}):
49
  cache[filename] = text
50
  return text
51
 
 
 
 
 
 
 
52
  class StabilityAI:
53
  @classmethod
54
  def generate_image(cls, visualize_prompt):
@@ -185,99 +191,7 @@ class NajiminoAI:
185
  ,{"role": "user", "content": user_message}
186
  ]
187
 
188
- functions = [
189
- {
190
- "name": "format_recipe",
191
- "description": "どんな料理か教えてくれれば,新しいレシピを考えます",
192
- "parameters": {
193
- "type": "object",
194
- "default": {},
195
- "title": "The Schema of new recipe",
196
- "required": [
197
- "lang",
198
- "title",
199
- "description",
200
- "ingredients",
201
- "instruction",
202
- "comment_feelings_taste",
203
- "explanation_to_blind_person",
204
- "prompt_for_visual_expression_in_en"
205
- ],
206
- "properties": {
207
- "lang": {
208
- "type": "string",
209
- "default": "ja",
210
- "title": "Language Schema",
211
- "examples": [
212
- "ja"
213
- ]
214
- },
215
- "title": {
216
- "type": "string",
217
- "default": "",
218
- "title": "Title of New Recipe.",
219
- "description": "Write your title of new recipe.",
220
- "examples": [
221
- "グルテンフリーサバのお好み焼き"
222
- ]
223
- },
224
- "description": {
225
- "type": "string",
226
- "default": "",
227
- "title": "Your New Recipe",
228
- "description": "Write new recipe and brainstorm and work out the details of every aspect of the new recipe.",
229
- "examples": [
230
- "サバを使ったお好み焼きのレシピです。グルテンフリー仕様で作られているので、小麦粉を使わずに作ることができます。"
231
- ]
232
- },
233
- "ingredients": {
234
- "type": "string",
235
- "default": "",
236
- "title": "Your Ingredients",
237
- "description": "Brainstorm the ingredients needed to cook a new recipe and come up with all the ingredients for the new recipe.",
238
- "examples": [
239
- "・サバのフィレ 200g\n・卵 2個\n・キャベツ 1/4個\n・もやし 50g\n・紅しょうが(刻んだもの) 2片\n・ネギ(小口切り) 適量\n・酒大さじ2\n・しょうゆ 大さじ2\n・だし汁 100ml\n・片栗粉 大さじ2\n・サラダ油 お好みで"
240
- ]
241
- },
242
- "instruction": {
243
- "type": "string",
244
- "default": "",
245
- "title": "Your Instruction",
246
- "description": "Instruct them to cook a new recipe, brainstorming and working out every aspect and detail of the new recipe.",
247
- "examples": [
248
- "1. キャベツは粗みじん切りにし、もやしは石づきを取っておく。\n2. ボウルに卵を割り入れ、よく混ぜる。酒、しょうゆ、だし汁を加えてさらに混ぜる。\n3. キャベツ、もやし、紅しょうが、ネギを卵液に加え、さらに混ぜる。\n4. サバのフィレを食べやすい大きさに切り、片栗粉をまぶす。\n5. フライパンにサラダ油を熱し、サバを並べ入れる。両面をこんがり焼く。\n6. サバの上に卵液を流し入れ、蓋をして約5分ほど蒸し焼きにする。\n7. ひっくり返して、もう片面も蓋をして約5分ほど蒸し焼きにする。\n8. お好み焼きを取り出し、お好みでソースやマヨネーズをかけて完成です。"
249
- ]
250
- },
251
- "comment_feelings_taste": {
252
- "type": "string",
253
- "default": "",
254
- "title": "Your Comment and Feelings, taste of new recipe.",
255
- "description": "Review commnet of new recipe and brainstorm every point of new recipe to fill the details.",
256
- "examples": [
257
- "このグルテンフリーサバのお好み焼きは、サバの旨味とキャベツの甘みが絶妙にマッチしています。表面はサクサク、中はもちもちとした食感で、一度食べたらやみつきになる美味しさです。"
258
- ]
259
- },
260
- "explanation_to_blind_person": {
261
- "type": "string",
262
- "default": "",
263
- "title": "Your Explanation to Blind Person",
264
- "description": "Review commnet of new recipe here to explain to the blind people more concretely in detail. Please brainstorm every point of new recipe to fill the details.",
265
- "examples": [
266
- "このグルテンフリーサバのお好み焼きは、サバのフィレとキャベツを主な材料としています。まず、キャベツを細かく刻んでおきます。次に、卵をボウルに割り入れ、酒、しょうゆ、だし汁と一緒によく混ぜます。その後、刻んだキャベツ、もやし、紅しょうが、ネギを卵液に加えて混ぜます。サバのフィレは食べやすい大きさに切り、片栗粉をまぶしてから焼きます。フライパンにサラダ油を熱し、サバを焼きます。その上に卵液を流し入れ、蓋をして約5分蒸し焼きにします。ひっくり返して、もう片面も蓋をして約5分蒸し焼きにします。最後にお好み焼きを取り出し、ソースやマヨネーズをかけて完成です。"
267
- ]
268
- },
269
- "prompt_for_visual_expression_in_en": {
270
- "type": "string",
271
- "default": "",
272
- "title": "The Schema of prompt for visual expression in English",
273
- "examples": [
274
- "Imagine a delicious gluten-free okonomiyaki with mackerel. The okonomiyaki is crispy on the outside and chewy on the inside. It is topped with savory sauce and creamy mayonnaise, creating a mouthwatering visual. The dish is garnished with finely chopped green onions and red pickled ginger, adding a pop of color. The mackerel fillets are beautifully grilled and placed on top of the okonomiyaki, adding a touch of elegance. The dish is served on a traditional Japanese plate, completing the visual presentation."
275
- ]
276
- }
277
- }
278
- }
279
- }
280
- ]
281
 
282
  message = OpenAI.chat_completion_with_function(prompt=user_message, messages=messages, functions=functions)
283
 
 
49
  cache[filename] = text
50
  return text
51
 
52
+ def get_functions_from_schema(filename):
53
+ schema = get_filetext(filename)
54
+ schema_json = json.loads(schema)
55
+ functions = schema_json.get("functions")
56
+ return functions
57
+
58
  class StabilityAI:
59
  @classmethod
60
  def generate_image(cls, visualize_prompt):
 
191
  ,{"role": "user", "content": user_message}
192
  ]
193
 
194
+ functions = get_functions_from_schema('schema.json')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
  message = OpenAI.chat_completion_with_function(prompt=user_message, messages=messages, functions=functions)
197
 
schema.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "functions": [
3
+ {
4
+ "name": "format_recipe",
5
+ "description": "どんな料理か教えてくれれば,新しいレシピを考えます",
6
+ "parameters": {
7
+ "type": "object",
8
+ "default": {},
9
+ "title": "The Schema of new recipe",
10
+ "required": [
11
+ "lang",
12
+ "title",
13
+ "description",
14
+ "ingredients",
15
+ "instruction",
16
+ "comment_feelings_taste",
17
+ "explanation_to_blind_person",
18
+ "prompt_for_visual_expression_in_en"
19
+ ],
20
+ "properties": {
21
+ "lang": {
22
+ "type": "string",
23
+ "default": "ja",
24
+ "title": "Language Schema",
25
+ "examples": [
26
+ "ja"
27
+ ]
28
+ },
29
+ "title": {
30
+ "type": "string",
31
+ "default": "",
32
+ "title": "Title of New Recipe.",
33
+ "description": "Write your title of new recipe.",
34
+ "examples": [
35
+ "グルテンフリーサバのお好み焼き"
36
+ ]
37
+ },
38
+ "description": {
39
+ "type": "string",
40
+ "default": "",
41
+ "title": "Your New Recipe",
42
+ "description": "Write new recipe and brainstorm and work out the details of every aspect of the new recipe.",
43
+ "examples": [
44
+ "サバを使ったお好み焼きのレシピです。グルテンフリー仕様で作られているので、小麦粉を使わずに作ることができます。"
45
+ ]
46
+ },
47
+ "ingredients": {
48
+ "type": "string",
49
+ "default": "",
50
+ "title": "Your Ingredients",
51
+ "description": "Brainstorm the ingredients needed to cook a new recipe and come up with all the ingredients for the new recipe.",
52
+ "examples": [
53
+ "・サバのフィレ 200g\n・卵 2個\n・キャベツ 1/4個\n・もやし 50g\n・紅しょうが(刻んだもの) 2片\n・ネギ(小口切り) 適量\n・酒大さじ2\n・しょうゆ 大さじ2\n・だし汁 100ml\n・片栗粉 大さじ2\n・サラダ油 お好みで"
54
+ ]
55
+ },
56
+ "instruction": {
57
+ "type": "string",
58
+ "default": "",
59
+ "title": "Your Instruction",
60
+ "description": "Instruct them to cook a new recipe, brainstorming and working out every aspect and detail of the new recipe.",
61
+ "examples": [
62
+ "1. キャベツは粗みじん切りにし、もやしは石づきを取っておく。\n2. ボウルに卵を割り入れ、よく混ぜる。酒、しょうゆ、だし汁を加えてさらに混ぜる。\n3. キャベツ、もやし、紅しょうが、ネギを卵液に加え、さらに混ぜる。\n4. サバのフィレを食べやすい大きさに切り、片栗粉をまぶす。\n5. フライパンにサラダ油を熱し、サバを並べ入れる。両面をこんがり焼く。\n6. サバの上に卵液を流し入れ、蓋をして約5分ほど蒸し焼きにする。\n7. ひっくり返して、もう片面も蓋をして約5分ほど蒸し焼きにする。\n8. お好み焼きを取り出し、お好みでソースやマヨネーズをかけて完成です。"
63
+ ]
64
+ },
65
+ "comment_feelings_taste": {
66
+ "type": "string",
67
+ "default": "",
68
+ "title": "Your Comment and Feelings, taste of new recipe.",
69
+ "description": "Review commnet of new recipe and brainstorm every point of new recipe to fill the details.",
70
+ "examples": [
71
+ "このグルテンフリーサバのお好み焼きは、サバの旨味とキャベツの甘みが絶妙にマッチしています。表面はサクサク、中はもちもちとした食感で、一度食べたらやみつきになる美味しさです。"
72
+ ]
73
+ },
74
+ "explanation_to_blind_person": {
75
+ "type": "string",
76
+ "default": "",
77
+ "title": "Your Explanation to Blind Person",
78
+ "description": "Review commnet of new recipe here to explain to the blind people more concretely in detail. Please brainstorm every point of new recipe to fill the details.",
79
+ "examples": [
80
+ "このグルテンフリーサバのお好み焼きは、サバのフィレとキャベツを主な材料としています。まず、キャベツを細かく刻んでおきます。次に、卵をボウルに割り入れ、酒、しょうゆ、だし汁と一緒によく混ぜます。その後、刻んだキャベツ、もやし、紅しょうが、ネギを卵液に加えて混ぜます。サバのフィレは食べやすい大きさに切り、片栗粉をまぶしてから焼きます。フライパンにサラダ油を熱し、サバを焼きます。その上に卵液を流し入れ、蓋をして約5分蒸し焼きにします。ひっくり返して、もう片面も蓋をして約5分蒸し焼きにします。最後にお好み焼きを取り出し、ソースやマヨネーズをかけて完成です。"
81
+ ]
82
+ },
83
+ "prompt_for_visual_expression_in_en": {
84
+ "type": "string",
85
+ "default": "",
86
+ "title": "The Schema of prompt for visual expression in English",
87
+ "examples": [
88
+ "Imagine a delicious gluten-free okonomiyaki with mackerel. The okonomiyaki is crispy on the outside and chewy on the inside. It is topped with savory sauce and creamy mayonnaise, creating a mouthwatering visual. The dish is garnished with finely chopped green onions and red pickled ginger, adding a pop of color. The mackerel fillets are beautifully grilled and placed on top of the okonomiyaki, adding a touch of elegance. The dish is served on a traditional Japanese plate, completing the visual presentation."
89
+ ]
90
+ }
91
+ }
92
+ }
93
+ }
94
+ ]
95
+ }