Sasha Rush commited on
Commit
2125358
1 Parent(s): 9c5cde1

update app

Browse files
Files changed (1) hide show
  1. app.py +522 -0
app.py ADDED
@@ -0,0 +1,522 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ sys.path.insert(0, "/home/srush/Projects/MiniChain/venv/lib/python3.10/site-packages")
4
+ print(sys.path)
5
+ import gradio as gr
6
+ from dataclasses import dataclass
7
+ from chalk import *
8
+ from colour import Color
9
+ import inspect
10
+ import os
11
+ import openai
12
+ from typing import List, Tuple, Optional
13
+ from enum import Enum
14
+ import io
15
+ from contextlib import redirect_stdout
16
+ import imageio
17
+ import tiktoken
18
+ import time
19
+ openai.api_key = ""
20
+ tab = " "
21
+
22
+ def start2(prompt, board, api_key):
23
+ out = ""
24
+ # for chunk in openai.ChatCompletion.create(
25
+ # model="gpt-4",
26
+ # messages=[{
27
+ # "role": "user",
28
+ # "content": prompt,
29
+
30
+ # }],
31
+ # stream=True,
32
+ # temperature= 0
33
+ # ):
34
+ board = board#Game(boundary=(9, 9), key=(1, 1), flag=(2, 2), init=(0, 0), walls=[(2, 0)])
35
+ actions = [Actions.DOWNRIGHT, Actions.RIGHT, Actions.DOWNRIGHT, Actions.PICKUP, Actions.DOWNRIGHT]
36
+ contents = example(board, actions)
37
+ print(contents)
38
+ # encoding = tiktoken.encoding_for_model("gpt-4")
39
+ # num_tokens = encoding.encode(string)
40
+
41
+ for content in contents:
42
+ time.sleep(0.005)
43
+ content = content
44
+ if content is not None:
45
+ out += content
46
+ print(content, end="")
47
+ yield out
48
+ yield out
49
+
50
+ def start(prompt, board, api_key):
51
+ out = ""
52
+ # encoding = tiktoken.encoding_for_model("gpt-4")
53
+ # num_tokens = encoding.encode(string)
54
+ content = ""
55
+ openai.api_key = api_key
56
+ for chunk in openai.ChatCompletion.create(
57
+ model="gpt-4",
58
+ messages=[{
59
+ "role": "user",
60
+ "content": prompt,
61
+
62
+ }],
63
+ stream=True,
64
+ temperature= 0
65
+ ):
66
+
67
+ # for content in contents:
68
+ time.sleep(0.005)
69
+ content = chunk["choices"][0].get("delta", {}).get("content")
70
+ if content is not None:
71
+ out += content
72
+ print(content, end="")
73
+ yield out
74
+ yield out
75
+
76
+ def num_tokens_from_string(string: str, encoding_name: str="gpt-4") -> int:
77
+ """Returns the number of tokens in a text string."""
78
+ encoding = tiktoken.encoding_for_model(encoding_name)
79
+ num_tokens = len(encoding.encode(string))
80
+ return num_tokens
81
+
82
+
83
+ # + [markdown] id="LMTjwXdD7v-I"
84
+ # ## Game Code
85
+ #
86
+ # This code creates a mini-game to play. It takes place on a hexagon. You are represented by a circle. You need to first pick up a key represented by a triangle. You finally need to make it to the cross to finish the game. The actions show each of the directions you can move.
87
+ #
88
+ #
89
+
90
+ # + id="Fv3eTRKiV2ZB" cellView="form"
91
+ #@title Game Code
92
+
93
+ # Possible Actions
94
+ class Actions(Enum):
95
+ UPRIGHT = "UR"
96
+ RIGHT = "R"
97
+ DOWNRIGHT = "DR"
98
+ DOWNLEFT = "DL"
99
+ LEFT = "L"
100
+ UPLEFT = "UL"
101
+ PICKUP = "Pickup"
102
+
103
+ # Movements
104
+ change = {
105
+ Actions.UPRIGHT : (-1, 1),
106
+ Actions.RIGHT : (0, 2),
107
+ Actions.DOWNRIGHT : (1, 1),
108
+ Actions.DOWNLEFT : (1, -1),
109
+ Actions.LEFT : (0, -2),
110
+ Actions.UPLEFT : (-1, -1),
111
+ Actions.PICKUP : (0, 0),
112
+ }
113
+ change_str = {action.value: change[action] for action in Actions}
114
+ def add(a, b):
115
+ return a[0] + b[0], a[1] + b[1]
116
+
117
+ @dataclass
118
+ class Board:
119
+ grid: List[str]
120
+ player_pos: Tuple[int, int]
121
+ flag_pos: Tuple[int, int]
122
+ wall_pos:List[Tuple[int, int]]
123
+ key_pos:Optional[Tuple[int, int]]
124
+
125
+ def move(self, action: Actions) -> 'Board':
126
+ "Move by creating a new board."
127
+ d_m = change[action]
128
+ if action == Actions.PICKUP:
129
+ if self.player_pos == self.key_pos:
130
+ return Board(self.grid, self.player_pos, self.flag_pos, self.wall_pos, None)
131
+ else:
132
+ return self
133
+
134
+ new_player_pos = add(self.player_pos, d_m)
135
+ # Out of bounds
136
+ if new_player_pos[0] < 0 or new_player_pos[0] >= len(self.grid):
137
+ return self
138
+ if new_player_pos[1] < 0 or new_player_pos[1] >= len(self.grid[0]):
139
+ return self
140
+ # Can't move through walls
141
+ if self.grid[new_player_pos[0]][new_player_pos[1]] == 'W':
142
+ return self
143
+
144
+ new_grid = [row[:] for row in self.grid] # Create a copy of the grid
145
+ new_grid[self.player_pos[0]][self.player_pos[1]] = '.'
146
+ new_grid[new_player_pos[0]][new_player_pos[1]] = '@'
147
+ return Board(new_grid, new_player_pos, self.flag_pos, self.wall_pos, self.key_pos)
148
+
149
+ def __str__(self) -> str:
150
+ return '\n'.join(''.join(row) for i, row in enumerate(self.grid))
151
+
152
+ @classmethod
153
+ def create_empty_board(cls, size: Tuple[int, int], key_pos, flag_pos, init, wall_pos) -> 'Board':
154
+ grid = [['.' if i % 2 == j % 2 else " " for i in range(size[1])] for j in range(size[0])]
155
+ player_pos = init
156
+ flag_pos = flag_pos
157
+ grid[player_pos[0]][player_pos[1]] = '@'
158
+ grid[flag_pos[0]][flag_pos[1]] = 'P'
159
+ grid[key_pos[0]][key_pos[1]] = 'K'
160
+ for pos in wall_pos:
161
+ grid[pos[0]][pos[1]] = 'W'
162
+ return cls(grid, player_pos, flag_pos, wall_pos, key_pos)
163
+
164
+ class Game:
165
+ def __init__(self, init, flag, walls, key, boundary):
166
+ "Create the version of the game that the AI sees."
167
+ self.boundary = boundary
168
+ self.board = Board.create_empty_board(boundary, key, flag, init, walls)
169
+ self.original = self.board
170
+ self.actions = []
171
+
172
+ def move(self, action):
173
+ self.board = self.board.move(action)
174
+ self.actions.append(action)
175
+
176
+ @property
177
+ def walls(self):
178
+ return self.board.wall_pos
179
+
180
+ def __repr__(self) -> str:
181
+ walls = ",".join(map(str, self.board.wall_pos))
182
+ return f"Game(init={self.board.player_pos}, flag={self.board.flag_pos}, walls={self.board.wall_pos}, boundary={self.boundary}, key={self.board.key_pos})"
183
+
184
+ # This is the version of move that the AI can see.
185
+ def move(game, action, old_pos):
186
+ # ACTIONS (must be legal)
187
+ game.move(Actions(action))
188
+ offset = change_str[action]
189
+ pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
190
+
191
+ assert 0 <= pos[0] < game.boundary[0], "Row position out of bounds"
192
+ assert 0 <= pos[1] < game.boundary[1], "Col position out of bounds"
193
+ assert pos not in game.walls, f"Walked into wall {pos}"
194
+ if action == "PU":
195
+ assert pos == game.key, f"Not over key"
196
+ return pos
197
+
198
+
199
+ # + [markdown] id="PDOcPiQq8u_Y"
200
+ # We can look at the board by drawing it.
201
+
202
+ # + colab={"base_uri": "https://localhost:8080/", "height": 221} id="Ic7WgOTi8uF1" outputId="4dc07cb9-9e5f-4d28-d4ea-470ad4b13141"
203
+ #@title Drawing code
204
+ def draw_board(grid, num=0):
205
+ hex = regular_polygon(6, 1).rotate_by(1/12).line_width(0.5).fill_color(Color("white"))
206
+ w = hex.get_envelope().width
207
+ canvas = empty()
208
+ for r, b in enumerate(grid):
209
+ def show(v):
210
+ if v == ".":
211
+ return hex
212
+ if v == "@":
213
+ return hex + circle(0.35).fill_color(Color("red"))
214
+ if v == "P":
215
+ x = rectangle(0.25, 0.7).fill_color(Color("blue")).line_width(0)
216
+ return hex + (x.rotate_by(0.25/2) + x.rotate_by(-0.25/2))
217
+ if v == "K":
218
+ return hex + triangle(0.75).fill_color(Color("purple"))
219
+ if v == "W":
220
+ return hex.fill_color(Color("black"))
221
+ if v ==" ":
222
+ return hex
223
+ row = hcat(show(v) for i, v in enumerate(b[1 if r %2 else 0::2]))
224
+ canvas += row.translate(w * 0.5 if r%2 else 0, 1.5 * r)
225
+ canvas = canvas.center_xy().frame(0.5)
226
+ canvas = rectangle(canvas.get_envelope().width, canvas.get_envelope().height).line_width(0.5).fill_color(Color("orange")) + canvas
227
+ canvas.render_svg(f"pic{num}.svg", 256)
228
+ return canvas
229
+
230
+
231
+
232
+ # + colab={"base_uri": "https://localhost:8080/", "height": 424} id="nqgPKLu0AMhU" outputId="19e4c6d0-b792-4a34-f4c4-81902974c346"
233
+ # game = Game(boundary=(5, 5), key=(0, 2), flag=(4, 4), init=(0, 0), walls=[(2, 2)])
234
+ # display(draw_board(game.board.grid))
235
+ # move(game, "DR", (0,0))
236
+ # display(draw_board(game.board.grid))
237
+
238
+
239
+ # + [markdown] id="PhqF9af5_jvh"
240
+ # ## Prompt Code
241
+ #
242
+ # The puzzle is to write prompt code to make the model accomplish this task. We have provided some scaffolding code for you. The code creates:
243
+ #
244
+ # * A header for describing the game.
245
+ # * A function `make_fun` that shows the AI how to move in code.
246
+ # * A footer to describe the final game board that you want the mode to solve.
247
+ #
248
+ # You can fill this in a watch how the model moves around.
249
+
250
+ # + id="jFf7TCOJaVHX"
251
+ #@title Make the Prompt
252
+ def make_fun(board, actions):
253
+ "This function generates python code for few-shot examples"
254
+ out = tab + "p = " + str(board.player_pos)
255
+ for i, action in enumerate(actions):
256
+ new_board = board.move(action)
257
+ out += f"""
258
+ # TODO ADD CODE
259
+ p = move(b, "{action.value}", p) # TODO ADD CODE"""
260
+ board = new_board
261
+ return out
262
+
263
+ def example(game, actions):
264
+ """
265
+ This code makes a few shot example. You don't need to edit it.
266
+ """
267
+ return f"""
268
+ def my_example():
269
+ b = {repr(game)}
270
+ {make_fun(game.board, actions)}
271
+ return b
272
+ """
273
+
274
+
275
+ ex = 0
276
+ def prompt(game):
277
+ """
278
+ You should fill these sections out to teach the AI how to play the game.
279
+
280
+ Or you may do your own thing :)
281
+ """
282
+ print(f"""
283
+ # TODO: DESCRIBE THE GAME
284
+
285
+ # TODO: DESCRIBE THE ACTIONS
286
+ change_str = {change_str}
287
+
288
+ {inspect.getsource(move)}
289
+ """)
290
+
291
+ def example(game, actions):
292
+ """
293
+ This code makes a few shot example. You don't need to edit it.
294
+ """
295
+ global ex
296
+ ex += 1
297
+ print(f"""
298
+ def example{ex}():
299
+ b = {repr(game)}
300
+ {make_fun(game.board, actions)}
301
+ return b
302
+ # ------------
303
+ """)
304
+
305
+ # Create a few shot example (you may not need this)
306
+ board = Game(boundary=(3, 3), key=(1, 1), flag=(2, 2), init=(0, 0), walls=[(2, 0)])
307
+ actions = [Actions.DOWNRIGHT, Actions.PICKUP, Actions.DOWNRIGHT]
308
+ example(board, actions)
309
+
310
+ # Test case
311
+ print(f"""
312
+ # ----
313
+ # TODO: ADD any custom example code
314
+ #---
315
+ # TODO: FINAL description.
316
+
317
+ # Contraints for this function:", {repr(game)}
318
+ # Please fill this in with code like the examples above (do not provide a description):
319
+ #
320
+ # The following function `my_example` instantiates a GameBoard called b with these constraints.
321
+
322
+ """)
323
+
324
+
325
+
326
+ # + [markdown] id="-iecyV7nAbFT"
327
+ # This code lets you make a game and see the output for a prompt for that game. There are easy, medium, and hard games.
328
+
329
+ # + colab={"base_uri": "https://localhost:8080/"} id="cOneYFok_OMe" outputId="97080186-7322-4ba9-b500-095fb39071aa"
330
+ # Easy
331
+ easy_game = Game(boundary=(3, 3), key=(1, 1), flag=(2, 2), init=(0, 0), walls=[])
332
+
333
+ # Medium
334
+ medium_game = Game(boundary=(5, 5), key=(3, 1), flag=(4, 4), init=(0, 0), walls=[(1, 1)])
335
+
336
+ # Hard (This is the main one)
337
+ hard_game = Game(boundary=(8, 15), key=(3, 1), flag=(7, 13), init=(0, 0), walls=[(2, 2), (1, 1), (5, 3), (1, 11), (5, 5), (6, 6), (6, 10), (2, 6), (4, 12)])
338
+
339
+ # Evil
340
+ evil_game = Game(boundary=(8, 15), key=(5, 1), flag=(7, 13), init=(0, 0), walls=[(2, 2), (3, 3), (4, 2), (1, 1), (2, 4), (7, 11), (5, 3), (1, 11), (5, 5), (6, 6), (6, 10), (2, 6), (4, 12)])
341
+
342
+ games = {"Easy": easy_game, "Medium": medium_game, "Hard": hard_game, "Evil": evil_game}
343
+
344
+ # Animate the outputs as a GIF
345
+ def animate(l):
346
+ images = []
347
+ for i in range(l):
348
+ images.append(imageio.v2.imread(f"pic{i}.png"))
349
+ return imageio.v2.mimsave('movie.gif', images, **{ 'duration': 0.5 })
350
+
351
+
352
+ def load(inp):
353
+ if inp in games:
354
+ board = games[inp]
355
+ else:
356
+ board = eval(inp)
357
+ draw_board(board.board.grid, 0).render_svg("tmp.svg")
358
+
359
+ return ["tmp.svg"], repr(board)
360
+
361
+ draw_board(hard_game.board.grid, 0).render_svg("hard.svg")
362
+ draw_board(easy_game.board.grid, 0).render_svg("easy.svg")
363
+ with gr.Blocks() as app:
364
+
365
+ # test = gr.Code(label="test")
366
+ # im2 = gr.Gallery()
367
+ # im2.style(preview=True)
368
+ gr.Markdown("""
369
+ # GPTWorld
370
+
371
+ GPTWorld is a prompting game. Your goal is to get an LLM to complete a maze. If you can do this successfully, it will be able to navigate itself through the world from the start (o) to the key the exit (x). In the bottom right we show you a sample target output of GPT for a maze. Your goal is to get the model to generate this from scratch for an unseen maze.
372
+
373
+
374
+ The game takes place on a hexagonal grid with walls. Even rows are labeled (0,0), (0, 2), (0,4) and odd rows are labeled (1, 1), (1, 3), (1, 5). This was done to make the puzzle a bit less common.
375
+
376
+ """)
377
+
378
+ with gr.Row():
379
+ with gr.Column():
380
+ game_desc = gr.Text(label="Game")
381
+ examples = gr.Radio(show_label=False,
382
+ choices=["Easy", "Medium", "Hard", "Evil"])
383
+ api_key = gr.Text(label="OpenAI Key", type="password",
384
+ value=os.environ.get("OPENAI_API_KEY"))
385
+ prompt = gr.Code(label="prompt", language="python", lines=40, value=f"""
386
+ # A prompt to describe this game to the GPT model.
387
+
388
+ # Ideas:
389
+ # * Describe how the game works
390
+ # * Give code examples that solve similar mazes.
391
+ # * Give examples to explain the reasoning process
392
+
393
+ # For example you might want to tell it how the moves work
394
+
395
+ change_str = {change_str}
396
+
397
+ # Or make up a clear implementation for the move function
398
+
399
+ def move(board, action, old_pos):
400
+ # ACTIONS (must be legal)
401
+ board.move(action)
402
+ offset = change_str[action]
403
+ pos = (old_pos[0] + offset[0], old_pos[1] + offset[1])
404
+ assert 0 <= pos[0] < board.boundary[0]
405
+ assert 0 <= pos[1] < board.boundary[1]
406
+ assert pos not in board.walls
407
+ if action == "Pickup":
408
+ assert pos == board.key
409
+ return pos
410
+
411
+ # You can test your code on the right side.
412
+
413
+ # Finally use %GAME% to inject the game description above.
414
+ """)
415
+ with gr.Row():
416
+ start_btn = gr.Button("Prompt >")
417
+ cancel_btn = gr.Button("Cancel")
418
+ with gr.Column():
419
+ im = gr.Gallery()
420
+ im.style(preview=True)
421
+
422
+ output = gr.Code(language="python", value="""def my_example():
423
+ b = Game(init=(0, 0), flag=(2, 2), walls= [], boundary= (3, 3), key= (1, 1))
424
+ p = (0, 0)
425
+ # This is the code you want it to generate.
426
+ p = move(b, "DR", p)
427
+ p = move(b, "Pickup", p)
428
+ p = move(b, "DL", p)
429
+ p = move(b, "R", p)
430
+ return b
431
+ """, lines=50)
432
+ msg_box = gr.Text(label="Errors")
433
+ counter = gr.Slider(label="length", minimum=0, maximum=3000)
434
+ run_btn = gr.Button("Rerun ^")
435
+
436
+
437
+
438
+ examples.change(load, inputs=[examples], outputs=[im, game_desc])
439
+ game_desc.submit(load, inputs=[game_desc], outputs=[im, game_desc])
440
+ def run(data):
441
+
442
+ board = eval(data[game_desc]) #games[data[examples]]
443
+ inp = data[prompt].replace("%GAME%", repr(board))
444
+ print(inp)
445
+ q = {}
446
+ i = 0
447
+ count = 0
448
+ im_ = [f"tmp.svg"]
449
+ yield {im: im_, counter: 0, output: "", msg_box: ""}
450
+
451
+ for prefix in start(inp, board, data[api_key]):
452
+ ps = prefix.split("\n")
453
+ count += 1
454
+
455
+ if len(ps) > 3 and not ps[-2].strip().startswith("#") and prefix.endswith("\n"):
456
+ print("rendering")
457
+ try:
458
+ exec(prefix + f"\n return b\nq['board'] = my_example({repr(board)})")
459
+ except AssertionError as e:
460
+ print("fail")
461
+ yield {im: [f"pic{j}.svg" for j in range(i)], counter: count, output: prefix, msg_box: f"You made an illegal move: {e}"}
462
+ return
463
+ draw_board(q["board"].board.grid, i).render_svg("tmp.svg")
464
+ i += 1
465
+ im_ = [f"pic{j}.svg" for j in [i-1]]
466
+ yield {im: im_, counter: count, output: prefix}
467
+ else:
468
+ yield {im: im_, counter: count, output: prefix}
469
+ yield {im: [f"pic{j}.svg" for j in range(i)], counter: count, output: prefix}
470
+ start_prompt = start_btn.click(run, inputs={prompt, game_desc, api_key}, outputs={im, output, counter, msg_box})
471
+ cancel_btn.click(None, cancels=[start_prompt])
472
+ def run2(data):
473
+ c = data[output]
474
+ print(c)
475
+ i = 0
476
+ for j in range(len(c)):
477
+ q = {}
478
+ prefix = c[:j]
479
+ ps = prefix.split("\n")
480
+ if len(ps) > 3 and not ps[-2].strip().startswith("#") and prefix.endswith("\n"):
481
+ print("rendering", prefix)
482
+ exec(prefix + "\n return b\nq['board'] = my_example()")
483
+ draw_board(q["board"].board.grid, i)
484
+ i += 1
485
+ animate(i)
486
+ out = {im: [f"pic{j}.svg" for j in range(i)]}
487
+ print(out)
488
+ return out
489
+ run_btn.click(run2, inputs={output}, outputs={im})
490
+
491
+
492
+
493
+ app.queue().launch()
494
+
495
+
496
+ # f = io.StringIO()
497
+ # with redirect_stdout(f):
498
+ # ex = 0
499
+ # prompt(game)
500
+ # my_prompt = f.getvalue()
501
+ # print(my_prompt)
502
+
503
+ # # + id="LONWUsBLjOHo" colab={"base_uri": "https://localhost:8080/", "height": 1000} outputId="472afd19-48c1-4924-cabd-639b5e2ad298"
504
+ # # Run an LLM and execute it as it runs.
505
+ # q = {}
506
+ # i = 0
507
+ # for prefix in start(my_prompt):
508
+ # ps = prefix.split("\n")
509
+ # if len(ps) > 3 and not ps[-2].strip().startswith("#") and prefix.endswith("\n"):
510
+ # exec(prefix + "\n return b\nq['board'] = my_example()")
511
+ # display(draw_board(q["board"].board.grid, i))
512
+ # i += 1
513
+
514
+
515
+ # animate(i)
516
+ # display(Image("movie.gif"))
517
+
518
+
519
+ # # Print the number of tokens used
520
+ # print("Input Tokens:", num_tokens_from_string(my_prompt))
521
+ # print("Output Tokens:", num_tokens_from_string(prefix))
522
+