|
38 | 38 | }, |
39 | 39 | { |
40 | 40 | "cell_type": "code", |
41 | | - "execution_count": 1, |
| 41 | + "execution_count": 39, |
42 | 42 | "metadata": {}, |
43 | 43 | "outputs": [], |
44 | 44 | "source": [ |
|
75 | 75 | }, |
76 | 76 | { |
77 | 77 | "cell_type": "code", |
78 | | - "execution_count": 2, |
| 78 | + "execution_count": 40, |
79 | 79 | "metadata": {}, |
80 | 80 | "outputs": [], |
81 | 81 | "source": [ |
82 | 82 | "from pydantic import BaseModel, Field\n", |
83 | 83 | "from guardrails.validators import BugFreePython\n", |
84 | | - "from guardrails.datatypes import PythonCode\n", |
85 | 84 | "\n", |
86 | 85 | "prompt = \"\"\"\n", |
87 | 86 | "Given the following high level leetcode problem description, write a short Python code snippet that solves the problem.\n", |
|
92 | 91 | "${gr.complete_json_suffix}\"\"\"\n", |
93 | 92 | "\n", |
94 | 93 | "class BugFreePythonCode(BaseModel):\n", |
95 | | - " python_code: PythonCode = Field(validators=[BugFreePython(on_fail=\"reask\")])\n", |
| 94 | + " python_code: str = Field(validators=[BugFreePython(on_fail=\"reask\")])\n", |
96 | 95 | "\n", |
97 | 96 | " class Config:\n", |
98 | 97 | " arbitrary_types_allowed = True" |
|
114 | 113 | }, |
115 | 114 | { |
116 | 115 | "cell_type": "code", |
117 | | - "execution_count": 3, |
| 116 | + "execution_count": 41, |
118 | 117 | "metadata": {}, |
119 | 118 | "outputs": [], |
120 | 119 | "source": [ |
|
132 | 131 | }, |
133 | 132 | { |
134 | 133 | "cell_type": "code", |
135 | | - "execution_count": 14, |
| 134 | + "execution_count": 42, |
136 | 135 | "metadata": {}, |
137 | | - "outputs": [], |
| 136 | + "outputs": [ |
| 137 | + { |
| 138 | + "name": "stderr", |
| 139 | + "output_type": "stream", |
| 140 | + "text": [ |
| 141 | + "/Users/zaydsimjee/workspace/guardrails/guardrails/validatorsattr.py:285: UserWarning: Validator bug-free-python is not valid for element pythoncode.\n", |
| 142 | + " warnings.warn(\n" |
| 143 | + ] |
| 144 | + } |
| 145 | + ], |
138 | 146 | "source": [ |
139 | 147 | "guard = gd.Guard.from_rail_string(rail_str)" |
140 | 148 | ] |
|
148 | 156 | }, |
149 | 157 | { |
150 | 158 | "cell_type": "code", |
151 | | - "execution_count": 4, |
| 159 | + "execution_count": 43, |
152 | 160 | "metadata": {}, |
153 | 161 | "outputs": [], |
154 | 162 | "source": [ |
|
165 | 173 | }, |
166 | 174 | { |
167 | 175 | "cell_type": "code", |
168 | | - "execution_count": 5, |
| 176 | + "execution_count": 44, |
169 | 177 | "metadata": {}, |
170 | 178 | "outputs": [ |
171 | 179 | { |
|
182 | 190 | "Given below is XML that describes the information to extract from this document and the tags to extract it into.\n", |
183 | 191 | "\n", |
184 | 192 | "<span style=\"font-weight: bold\"><</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff; font-weight: bold\">output</span><span style=\"color: #000000; text-decoration-color: #000000\">></span>\n", |
185 | | - "<span style=\"color: #000000; text-decoration-color: #000000\"> <pythoncode </span><span style=\"color: #808000; text-decoration-color: #808000\">name</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">\"python_code\"</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #808000; text-decoration-color: #808000\">format</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">\"bug-free-python\"</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #000000; text-decoration-color: #000000\">></span>\n", |
| 193 | + "<span style=\"color: #000000; text-decoration-color: #000000\"> <string </span><span style=\"color: #808000; text-decoration-color: #808000\">name</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">\"python_code\"</span><span style=\"color: #000000; text-decoration-color: #000000\"> </span><span style=\"color: #808000; text-decoration-color: #808000\">format</span><span style=\"color: #000000; text-decoration-color: #000000\">=</span><span style=\"color: #008000; text-decoration-color: #008000\">\"bug-free-python\"</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #000000; text-decoration-color: #000000\">></span>\n", |
186 | 194 | "<span style=\"color: #000000; text-decoration-color: #000000\"><</span><span style=\"color: #800080; text-decoration-color: #800080\">/</span><span style=\"color: #ff00ff; text-decoration-color: #ff00ff\">output</span><span style=\"color: #000000; text-decoration-color: #000000\">></span>\n", |
187 | 195 | "\n", |
188 | 196 | "\n", |
|
211 | 219 | "Given below is XML that describes the information to extract from this document and the tags to extract it into.\n", |
212 | 220 | "\n", |
213 | 221 | "\u001b[1m<\u001b[0m\u001b[1;95moutput\u001b[0m\u001b[39m>\u001b[0m\n", |
214 | | - "\u001b[39m <pythoncode \u001b[0m\u001b[33mname\u001b[0m\u001b[39m=\u001b[0m\u001b[32m\"python_code\"\u001b[0m\u001b[39m \u001b[0m\u001b[33mformat\u001b[0m\u001b[39m=\u001b[0m\u001b[32m\"bug\u001b[0m\u001b[32m-free-python\"\u001b[0m\u001b[35m/\u001b[0m\u001b[39m>\u001b[0m\n", |
| 222 | + "\u001b[39m <string \u001b[0m\u001b[33mname\u001b[0m\u001b[39m=\u001b[0m\u001b[32m\"python_code\"\u001b[0m\u001b[39m \u001b[0m\u001b[33mformat\u001b[0m\u001b[39m=\u001b[0m\u001b[32m\"bug\u001b[0m\u001b[32m-free-python\"\u001b[0m\u001b[35m/\u001b[0m\u001b[39m>\u001b[0m\n", |
215 | 223 | "\u001b[39m<\u001b[0m\u001b[35m/\u001b[0m\u001b[95moutput\u001b[0m\u001b[39m>\u001b[0m\n", |
216 | 224 | "\n", |
217 | 225 | "\n", |
|
246 | 254 | }, |
247 | 255 | { |
248 | 256 | "cell_type": "code", |
249 | | - "execution_count": 6, |
| 257 | + "execution_count": 45, |
250 | 258 | "metadata": {}, |
251 | | - "outputs": [ |
252 | | - { |
253 | | - "name": "stderr", |
254 | | - "output_type": "stream", |
255 | | - "text": [ |
256 | | - "Async event loop found, but guard was invoked synchronously.For validator parallelization, please call `validate_async` instead.\n" |
257 | | - ] |
258 | | - } |
259 | | - ], |
| 259 | + "outputs": [], |
260 | 260 | "source": [ |
261 | 261 | "import openai\n", |
262 | 262 | "\n", |
|
285 | 285 | }, |
286 | 286 | { |
287 | 287 | "cell_type": "code", |
288 | | - "execution_count": 7, |
| 288 | + "execution_count": 46, |
289 | 289 | "metadata": {}, |
290 | 290 | "outputs": [ |
291 | 291 | { |
|
326 | 326 | }, |
327 | 327 | { |
328 | 328 | "cell_type": "code", |
329 | | - "execution_count": 8, |
| 329 | + "execution_count": 47, |
330 | 330 | "metadata": {}, |
331 | 331 | "outputs": [ |
332 | 332 | { |
|
371 | 371 | }, |
372 | 372 | { |
373 | 373 | "cell_type": "code", |
374 | | - "execution_count": 9, |
| 374 | + "execution_count": 48, |
375 | 375 | "metadata": {}, |
376 | 376 | "outputs": [ |
377 | 377 | { |
|
413 | 413 | "name": "python", |
414 | 414 | "nbconvert_exporter": "python", |
415 | 415 | "pygments_lexer": "ipython3", |
416 | | - "version": "3.11.4" |
| 416 | + "version": "3.11.5" |
417 | 417 | }, |
418 | 418 | "orig_nbformat": 4, |
419 | 419 | "vscode": { |
|
0 commit comments