Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save this-josh/c3e235a785840742d28baf99bb33029a to your computer and use it in GitHub Desktop.
Save this-josh/c3e235a785840742d28baf99bb33029a to your computer and use it in GitHub Desktop.
(base)➜ tmp conda create -n guidance python=3.12 -y [13/May/24 | 10:10]
Channels:
- conda-forge
Platform: osx-arm64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /opt/homebrew/Caskroom/mambaforge/base/envs/guidance
added / updated specs:
- python=3.12
The following NEW packages will be INSTALLED:
bzip2 conda-forge/osx-arm64::bzip2-1.0.8-h93a5062_5
ca-certificates conda-forge/osx-arm64::ca-certificates-2024.2.2-hf0a4a13_0
libexpat conda-forge/osx-arm64::libexpat-2.6.2-hebf3989_0
libffi conda-forge/osx-arm64::libffi-3.4.2-h3422bc3_5
libsqlite conda-forge/osx-arm64::libsqlite-3.45.3-h091b4b1_0
libzlib conda-forge/osx-arm64::libzlib-1.2.13-h53f4e23_5
ncurses conda-forge/osx-arm64::ncurses-6.5-hb89a1cb_0
openssl conda-forge/osx-arm64::openssl-3.3.0-h0d3ecfb_0
pip conda-forge/noarch::pip-24.0-pyhd8ed1ab_0
python conda-forge/osx-arm64::python-3.12.3-h4a7b5fc_0_cpython
readline conda-forge/osx-arm64::readline-8.2-h92ec313_1
setuptools conda-forge/noarch::setuptools-69.5.1-pyhd8ed1ab_0
tk conda-forge/osx-arm64::tk-8.6.13-h5083fa2_1
tzdata conda-forge/noarch::tzdata-2024a-h0c530f3_0
wheel conda-forge/noarch::wheel-0.43.0-pyhd8ed1ab_1
xz conda-forge/osx-arm64::xz-5.2.6-h57fd34a_0
Downloading and Extracting Packages:
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate guidance
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base)➜ tmp conda activate guidance [13/May/24 | 10:11]
(guidance)➜ tmp pip install guidance --no-cache-dir [13/May/24 | 10:11]
Collecting guidance
Downloading guidance-0.1.14-cp312-cp312-macosx_11_0_arm64.whl.metadata (2.1 kB)
Collecting diskcache (from guidance)
Downloading diskcache-5.6.3-py3-none-any.whl.metadata (20 kB)
Collecting numpy (from guidance)
Downloading numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl.metadata (61 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 61.1/61.1 kB 56.1 MB/s eta 0:00:00
Collecting ordered-set (from guidance)
Downloading ordered_set-4.1.0-py3-none-any.whl.metadata (5.3 kB)
Collecting platformdirs (from guidance)
Downloading platformdirs-4.2.1-py3-none-any.whl.metadata (11 kB)
Collecting pyformlang (from guidance)
Downloading pyformlang-1.0.10-py3-none-any.whl.metadata (2.4 kB)
Collecting protobuf (from guidance)
Downloading protobuf-5.26.1-cp37-abi3-macosx_10_9_universal2.whl.metadata (592 bytes)
Collecting pydantic (from guidance)
Downloading pydantic-2.7.1-py3-none-any.whl.metadata (107 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 107.3/107.3 kB 375.6 MB/s eta 0:00:00
Collecting requests (from guidance)
Downloading requests-2.31.0-py3-none-any.whl.metadata (4.6 kB)
Collecting tiktoken>=0.3 (from guidance)
Downloading tiktoken-0.6.0-cp312-cp312-macosx_11_0_arm64.whl.metadata (6.6 kB)
Collecting regex>=2022.1.18 (from tiktoken>=0.3->guidance)
Downloading regex-2024.5.10-cp312-cp312-macosx_11_0_arm64.whl.metadata (40 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 40.9/40.9 kB 299.5 MB/s eta 0:00:00
Collecting charset-normalizer<4,>=2 (from requests->guidance)
Downloading charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl.metadata (33 kB)
Collecting idna<4,>=2.5 (from requests->guidance)
Downloading idna-3.7-py3-none-any.whl.metadata (9.9 kB)
Collecting urllib3<3,>=1.21.1 (from requests->guidance)
Downloading urllib3-2.2.1-py3-none-any.whl.metadata (6.4 kB)
Collecting certifi>=2017.4.17 (from requests->guidance)
Downloading certifi-2024.2.2-py3-none-any.whl.metadata (2.2 kB)
Collecting annotated-types>=0.4.0 (from pydantic->guidance)
Downloading annotated_types-0.6.0-py3-none-any.whl.metadata (12 kB)
Collecting pydantic-core==2.18.2 (from pydantic->guidance)
Downloading pydantic_core-2.18.2-cp312-cp312-macosx_11_0_arm64.whl.metadata (6.5 kB)
Collecting typing-extensions>=4.6.1 (from pydantic->guidance)
Downloading typing_extensions-4.11.0-py3-none-any.whl.metadata (3.0 kB)
Collecting networkx (from pyformlang->guidance)
Downloading networkx-3.3-py3-none-any.whl.metadata (5.1 kB)
Collecting pydot (from pyformlang->guidance)
Downloading pydot-2.0.0-py3-none-any.whl.metadata (9.6 kB)
Collecting pyparsing>=3 (from pydot->pyformlang->guidance)
Downloading pyparsing-3.1.2-py3-none-any.whl.metadata (5.1 kB)
Downloading guidance-0.1.14-cp312-cp312-macosx_11_0_arm64.whl (186 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 186.4/186.4 kB 216.7 MB/s eta 0:00:00
Downloading tiktoken-0.6.0-cp312-cp312-macosx_11_0_arm64.whl (922 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 922.4/922.4 kB 118.3 MB/s eta 0:00:00
Downloading requests-2.31.0-py3-none-any.whl (62 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 62.6/62.6 kB 353.9 MB/s eta 0:00:00
Downloading diskcache-5.6.3-py3-none-any.whl (45 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.5/45.5 kB 309.5 MB/s eta 0:00:00
Downloading numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl (13.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.7/13.7 MB 100.7 MB/s eta 0:00:00
Downloading ordered_set-4.1.0-py3-none-any.whl (7.6 kB)
Downloading platformdirs-4.2.1-py3-none-any.whl (17 kB)
Downloading protobuf-5.26.1-cp37-abi3-macosx_10_9_universal2.whl (404 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 404.0/404.0 kB 121.3 MB/s eta 0:00:00
Downloading pydantic-2.7.1-py3-none-any.whl (409 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 409.3/409.3 kB 168.5 MB/s eta 0:00:00
Downloading pydantic_core-2.18.2-cp312-cp312-macosx_11_0_arm64.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 123.8 MB/s eta 0:00:00
Downloading pyformlang-1.0.10-py3-none-any.whl (126 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 126.8/126.8 kB 374.5 MB/s eta 0:00:00
Downloading annotated_types-0.6.0-py3-none-any.whl (12 kB)
Downloading certifi-2024.2.2-py3-none-any.whl (163 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.8/163.8 kB 362.7 MB/s eta 0:00:00
Downloading charset_normalizer-3.3.2-cp312-cp312-macosx_11_0_arm64.whl (119 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 119.4/119.4 kB 478.4 MB/s eta 0:00:00
Downloading idna-3.7-py3-none-any.whl (66 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 66.8/66.8 kB 435.6 MB/s eta 0:00:00
Downloading regex-2024.5.10-cp312-cp312-macosx_11_0_arm64.whl (278 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 278.5/278.5 kB 138.6 MB/s eta 0:00:00
Downloading typing_extensions-4.11.0-py3-none-any.whl (34 kB)
Downloading urllib3-2.2.1-py3-none-any.whl (121 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.1/121.1 kB 469.4 MB/s eta 0:00:00
Downloading networkx-3.3-py3-none-any.whl (1.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 123.4 MB/s eta 0:00:00
Downloading pydot-2.0.0-py3-none-any.whl (22 kB)
Downloading pyparsing-3.1.2-py3-none-any.whl (103 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.2/103.2 kB 477.1 MB/s eta 0:00:00
Installing collected packages: urllib3, typing-extensions, regex, pyparsing, protobuf, platformdirs, ordered-set, numpy, networkx, idna, diskcache, charset-normalizer, certifi, annotated-types, requests, pydot, pydantic-core, tiktoken, pyformlang, pydantic, guidance
Successfully installed annotated-types-0.6.0 certifi-2024.2.2 charset-normalizer-3.3.2 diskcache-5.6.3 guidance-0.1.14 idna-3.7 networkx-3.3 numpy-1.26.4 ordered-set-4.1.0 platformdirs-4.2.1 protobuf-5.26.1 pydantic-2.7.1 pydantic-core-2.18.2 pydot-2.0.0 pyformlang-1.0.10 pyparsing-3.1.2 regex-2024.5.10 requests-2.31.0 tiktoken-0.6.0 typing-extensions-4.11.0 urllib3-2.2.1
(guidance)➜ tmp python [13/May/24 | 10:11]
Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:35:20) [Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import guidance
from guidance import select, gen^Mfrom guidance import models^M^M@guidance^Mdef character_maker(lm, id, description, valid_weapons):^M lm += f"""\^M The following is a character profile for an RPG game in JSON format.^M ```json^M {{^M "id": "{id}",^M "description": "{description}",^M "name": "{gen('name', stop='"')}",^M "age": {gen('age', regex='[0-9]+', stop=',')},^M "armor": "{select(options=['leather', 'chainmail', 'plate'], name='armor')}",^M "weapon": "{select(options=valid_weapons, name='weapon')}",^M "class": "{gen('class', stop='"')}",^M "mantra": "{gen('mantra', stop='"')}",^M "strength": {gen('strength', regex='[0-9]+', stop=',')},^M "items": ["{gen('item', list_append=True, stop='"')}", "{gen('item', list_append=True, stop='"')}", "{gen('item', list_append=True, stop='"')}"]^M }}```"""^M return lm^M>>> from guidance import select, gen
>>> from guidance import models
>>>
>>> @guidance
... def character_maker(lm, id, description, valid_weapons):
... lm += f"""\
... The following is a character profile for an RPG game in JSON format.
... ```json
... {{
... "id": "{id}",
... "description": "{description}",
... "name": "{gen('name', stop='"')}",
... "age": {gen('age', regex='[0-9]+', stop=',')},
... "armor": "{select(options=['leather', 'chainmail', 'plate'], name='armor')}",
... "weapon": "{select(options=valid_weapons, name='weapon')}",
... "class": "{gen('class', stop='"')}",
... "mantra": "{gen('mantra', stop='"')}",
... "strength": {gen('strength', regex='[0-9]+', stop=',')},
... "items": ["{gen('item', list_append=True, stop='"')}", "{gen('item', list_append=True, stop='"')}", "{gen('item', list_append=True, stop='"')}"]
... }}```"""
... return lm
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/site-packages/guidance/__init__.py", line 26, in __call__
return _decorator(
^^^^^^^^^^^
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/site-packages/guidance/_guidance.py", line 29, in _decorator
f = strip_multiline_string_indents(f)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/site-packages/guidance/_utils.py", line 95, in strip_multiline_string_indents
source = textwrap.dedent(inspect.getsource(f))
^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/inspect.py", line 1278, in getsource
lines, lnum = getsourcelines(object)
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/inspect.py", line 1260, in getsourcelines
lines, lnum = findsource(object)
^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Caskroom/mambaforge/base/envs/guidance/lib/python3.12/inspect.py", line 1089, in findsource
raise OSError('could not get source code')
OSError: could not get source code
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment