|
2 | 2 | hide:
|
3 | 3 | - navigation
|
4 | 4 | - toc
|
| 5 | + - footer |
5 | 6 | ---
|
6 |
| -# PDL Live Viewer |
7 |
| - |
8 |
| -!!! note |
9 |
| - This is the PDL Live Document viewer. The left pane contains the final result of the program, and upon interaction, the right pane displays the code that created that part of the document, along with a breakdown of the PDL blocks on the left pane. |
10 |
| - To use the tool, upload a json using the following command: |
11 |
| - pdl --trace myresult.json myexample.pdl |
12 | 7 |
|
13 | 8 | <style>
|
14 |
| - .pdl_block { |
15 |
| - border-radius: 3px; |
16 |
| - margin: 3px; |
17 |
| - padding: 5px; |
18 |
| - margin: 2px; |
19 |
| - vertical-align: middle; |
20 |
| - display: inline-block; |
21 |
| - } |
22 |
| - .pdl_show_result_false { |
23 |
| - color: rgba(0, 0, 0, 0.5); |
24 |
| - } |
25 |
| - .pdl_string { |
26 |
| - background-color: antiquewhite; |
27 |
| - } |
28 |
| - .pdl_empty { |
29 |
| - background-color: rgb(238, 184, 112); |
30 |
| - } |
31 |
| - .pdl_text { |
32 |
| - background-color: rgb(219, 215, 250); |
33 |
| - } |
34 |
| - .pdl_model { |
35 |
| - background-color: rgb(215, 250, 224); |
36 |
| - } |
37 |
| - .pdl_code { |
38 |
| - background-color: rgb(250, 215, 225); |
39 |
| - } |
40 |
| - .pdl_api { |
41 |
| - background-color: rgb(122, 246, 113); |
42 |
| - } |
43 |
| - .pdl_get { |
44 |
| - background-color: rgb(125, 229, 243); |
45 |
| - } |
46 |
| - .pdl_data { |
47 |
| - background-color: rgb(146, 181, 245); |
48 |
| - } |
49 |
| - .pdl_if { |
50 |
| - background-color: rgb(248, 99, 141); |
51 |
| - } |
52 |
| - .pdl_repeat { |
53 |
| - background-color: rgb(251, 201, 86); |
54 |
| - } |
55 |
| - .pdl_read { |
56 |
| - background-color: rgb(243, 77, 113); |
57 |
| - } |
58 |
| - .pdl_include { |
59 |
| - background-color: rgb(245, 18, 67); |
60 |
| - } |
61 |
| - .pdl_function { |
62 |
| - background-color: rgb(77, 243, 132); |
63 |
| - } |
64 |
| - .pdl_call { |
65 |
| - background-color: rgb(80, 243, 77); |
66 |
| - } |
| 9 | +.md-typeset { |
| 10 | + margin: 0; |
| 11 | + padding: 0; |
| 12 | +} |
| 13 | +.md-grid {margin-top: 0;} |
| 14 | +.md-typeset > h1, |
| 15 | +.md-content__button { |
| 16 | + display: none; |
| 17 | +} |
| 18 | +iframe { |
| 19 | + width: 100%; |
| 20 | + min-height: 800px; /* TODO */ |
| 21 | +} |
67 | 22 | </style>
|
68 |
| -<!-- Main script --> |
69 |
| -<script src="../dist/bundle.js"></script> |
70 |
| -<!-- Multi column layout --> |
71 |
| -<link rel="stylesheet" type="text/css" href="https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.css"> |
72 |
| -<!-- Main window --> |
73 |
| -<div id="mainview"> |
74 |
| - <!-- Main window layout --> |
75 |
| - <input type="file" name="input_file" id="input_file"> |
76 |
| - <script type="text/javascript"> |
77 |
| - document.getElementById('input_file') |
78 |
| - .addEventListener('change', function () { |
79 |
| - let fr = new FileReader(); |
80 |
| - fr.onload = function () { |
81 |
| - data = JSON.parse(fr.result) |
82 |
| - pdl_viewer.replace_div('doc', pdl_viewer.show_output(data)) |
83 |
| - } |
84 |
| - fr.readAsText(this.files[0]); |
85 |
| - }) |
86 |
| - </script> |
87 |
| - <div id="layout" style="height: 900px;"></div> |
88 |
| - <script type="module"> |
89 |
| - import { w2layout } from 'https://rawgit.com/vitmalina/w2ui/master/dist/w2ui.es6.min.js' |
90 |
| - let pstyle = 'border: 1px solid #efefef; padding: 5px' |
91 |
| - new w2layout({ |
92 |
| - box: '#layout', |
93 |
| - name: 'layout', |
94 |
| - panels: [ |
95 |
| - { type: 'left', size: 600, resizable: true, style: pstyle, html: '<div id="doc"></div>' }, |
96 |
| - { type: 'main', style: pstyle, html: '<div id="code">Please click on a word on the left to get started.</div>' } |
97 |
| - ] |
98 |
| - }) |
99 |
| - </script> |
100 |
| - <script type="text/javascript"> |
101 |
| - const example = { |
102 |
| - "kind": "text", |
103 |
| - "description": "Teaching PDL", |
104 |
| - "defs": {}, |
105 |
| - "text": [{ |
106 |
| - "kind": "read", |
107 |
| - "defs": {}, |
108 |
| - "read": null, |
109 |
| - "message": null, |
110 |
| - "multiline": true, |
111 |
| - "def": "QUERY", |
112 |
| - "show_result": false, |
113 |
| - "result": "Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\n", |
114 |
| - }, { |
115 |
| - "kind": "model", |
116 |
| - "defs": {}, |
117 |
| - "model": "ibm/granite-20b-code-instruct-v2", |
118 |
| - "input": { |
119 |
| - "kind": "text", |
120 |
| - "defs": {}, |
121 |
| - "text": ["Question: Replace all arithmetic expressions by surrounding them with << >>\nBob had 5 + 2 apples. He ate all them and bought 8 * 67 skittles.\nHe wanted to distribute those among all of 10 children. So each kid\ngot a grand total of 8 * 67 / 10 skittle. Amazing!\n\nAnswer:\nBob had << 5 + 2 >> apples. He ate all them and bought << 8 * 67 >> skittles.\nHe wanted to distribute those among all of 10 children. So each kid\ngot a grand total of << 8 * 67 / 10 >> skittle. Amazing!\n\nQuestion:\nThe world contains lots of soccer balls. Each team has 5 soccer balls per kid.\nThis team has 30 kids, so the team has 5 * 30 soccer balls.\n\nAnswer:\nThe world contains lots of soccer balls. Each team has 5 soccer balls per kid.\nThis team has 30 kids, so the team has << 5 * 30 >> soccer balls.\n\nQuestion:\nWhat is 5 + 2?\n\nAnswer:\nWhat is << 5 + 2 >>?\n\nQuestion:", { |
122 |
| - "kind": "get", |
123 |
| - "defs": {}, |
124 |
| - "get": "QUERY", |
125 |
| - "result": "Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\n", |
126 |
| - }, "\n\n"], |
127 |
| - "result": "Question: Replace all arithmetic expressions by surrounding them with << >>\nBob had 5 + 2 apples. He ate all them and bought 8 * 67 skittles.\nHe wanted to distribute those among all of 10 children. So each kid\ngot a grand total of 8 * 67 / 10 skittle. Amazing!\n\nAnswer:\nBob had << 5 + 2 >> apples. He ate all them and bought << 8 * 67 >> skittles.\nHe wanted to distribute those among all of 10 children. So each kid\ngot a grand total of << 8 * 67 / 10 >> skittle. Amazing!\n\nQuestion:\nThe world contains lots of soccer balls. Each team has 5 soccer balls per kid.\nThis team has 30 kids, so the team has 5 * 30 soccer balls.\n\nAnswer:\nThe world contains lots of soccer balls. Each team has 5 soccer balls per kid.\nThis team has 30 kids, so the team has << 5 * 30 >> soccer balls.\n\nQuestion:\nWhat is 5 + 2?\n\nAnswer:\nWhat is << 5 + 2 >>?\n\nQuestion:Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\n\n\n", |
128 |
| - "parameters": { |
129 |
| - "decoding_method": "greedy", |
130 |
| - "max_new_tokens": 1024, |
131 |
| - "min_new_tokens": 1, |
132 |
| - "repetition_penalty": 1.05 |
133 |
| - }, |
134 |
| - "def": "QUERY1", |
135 |
| - "show_result": false, |
136 |
| - "result": "\nAnswer:\nBobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?", |
137 |
| - }, { |
138 |
| - "kind": "model", |
139 |
| - "defs": {}, |
140 |
| - "model": "ibm/granite-20b-code-instruct-v2", |
141 |
| - "input": { |
142 |
| - "kind": "text", |
143 |
| - "defs": {}, |
144 |
| - "text": ["Question: Write the following prompts in PDL:\nHello world!\nThis is your first prompt descriptor!\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"Hello, world!\\n\"\n- \"This is your first prompt descriptor!\\n\" \n```\n\nQuestion: Turn the code into PDL:\ncontents = []\nwhile True:\ntry:\n line = input()\nexcept EOFError:\n break\ncontents.append(line + \"\\n\")\nresult = ''.join(contents)\n\nAnswer:\n```\ndescription: Example of PDL code block\ntext:\n- lang: python\n code:\n - |\n contents = []\n while True:\n try:\n line = input()\n except EOFError:\n break\n contents.append(line + \"\\n\")\n result = ''.join(contents)\n```\n\nQuestion: Write the following in PDL where the parts in << >> are done in Python.\nHello world!\nThis is your << expr >> prompt descriptor!\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"Hello, world!\\n\"\n- \"This is your \"\n- lang: python\n code:\n - |\n result = expr\n- \" prompt descriptor!\"\n```\nQuestion: Write the following in PDL where the parts in << >> are done in Python.\nWhat is << 67+ 67 - 78 + 2 >>\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"What is \"\n- lang: python\n code:\n - |\n result = 67+ 67 - 78 + 2\n```\n\n\nQuestion: Write the following in PDL with parts << >> written in Python", { |
145 |
| - "kind": "get", |
146 |
| - "defs": {}, |
147 |
| - "get": "QUERY1", |
148 |
| - "result": "\nAnswer:\nBobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?", |
149 |
| - }, "\n\n"], |
150 |
| - "result": "Question: Write the following prompts in PDL:\nHello world!\nThis is your first prompt descriptor!\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"Hello, world!\\n\"\n- \"This is your first prompt descriptor!\\n\" \n```\n\nQuestion: Turn the code into PDL:\ncontents = []\nwhile True:\ntry:\n line = input()\nexcept EOFError:\n break\ncontents.append(line + \"\\n\")\nresult = ''.join(contents)\n\nAnswer:\n```\ndescription: Example of PDL code block\ntext:\n- lang: python\n code:\n - |\n contents = []\n while True:\n try:\n line = input()\n except EOFError:\n break\n contents.append(line + \"\\n\")\n result = ''.join(contents)\n```\n\nQuestion: Write the following in PDL where the parts in << >> are done in Python.\nHello world!\nThis is your << expr >> prompt descriptor!\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"Hello, world!\\n\"\n- \"This is your \"\n- lang: python\n code:\n - |\n result = expr\n- \" prompt descriptor!\"\n```\nQuestion: Write the following in PDL where the parts in << >> are done in Python.\nWhat is << 67+ 67 - 78 + 2 >>\n\nAnswer:\n```\ndescription: Hello world!\ntext:\n- \"What is \"\n- lang: python\n code:\n - |\n result = 67+ 67 - 78 + 2\n```\n\n\nQuestion: Write the following in PDL with parts << >> written in Python\nAnswer:\nBobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\n\n", |
151 |
| - }, |
152 |
| - "parameters": { |
153 |
| - "decoding_method": "greedy", |
154 |
| - "max_new_tokens": 1024, |
155 |
| - "min_new_tokens": 1, |
156 |
| - "repetition_penalty": 1.05 |
157 |
| - }, |
158 |
| - "def": "PDL", |
159 |
| - "show_result": false, |
160 |
| - "result": "\nAnswer:\n```\ndescription: Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\ntext:\n- \"Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\"\n```", |
161 |
| - }, { |
162 |
| - "kind": "code", |
163 |
| - "defs": {}, |
164 |
| - "lang": "python", |
165 |
| - "code": ["from pdl import pdl_ast, pdl_interpreter\nfrom pdl.pdl_ast import Program\nfrom pdl.pdl_interpreter import process_prog\nfrom pdl.pdl_interpreter import InterpreterState\nfrom pdl.pdl_interpreter import empty_scope\nimport re\nimport yaml\ns = \"\"\"'\n", { |
166 |
| - "kind": "get", |
167 |
| - "defs": {}, |
168 |
| - "get": "PDL", |
169 |
| - "result": "\nAnswer:\n```\ndescription: Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\ntext:\n- \"Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\"\n```", |
170 |
| - }, "'\"\"\"\npdl = s.split(\"```\")[1]\nobj = yaml.safe_load(pdl)\nstate = InterpreterState()\ndata = Program.model_validate(obj)\n_, result, _, _ = process_prog(state, empty_scope, data)\n"], |
171 |
| - "def": "RESULT", |
172 |
| - "result": "Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?", |
173 |
| - }, "\n", { |
174 |
| - "kind": "model", |
175 |
| - "defs": {}, |
176 |
| - "model": "ibm/granite-13b-instruct-v2", |
177 |
| - "result": "5", |
178 |
| - }], |
179 |
| - "result": "Bobby had 3 apples. He then added 2. Hence 3 + 2 = 5 How many apple did Bobby have?\n5", |
180 |
| - } |
181 |
| - window.addEventListener("load", function () { |
182 |
| - pdl_viewer.replace_div('doc', pdl_viewer.show_output(example)) |
183 |
| - }); |
184 |
| - </script> |
185 |
| -</div> |
| 23 | + |
| 24 | +<iframe src="https://pdl.s3-web.us-east.cloud-object-storage.appdomain.cloud/" frameborder="0" height="100%"></iframe> |
0 commit comments