From 281d11802fdaaebb2c51de1cea577befabdacd04 Mon Sep 17 00:00:00 2001 From: yanli Date: Sun, 1 Dec 2024 20:20:14 +0800 Subject: [PATCH] update deps and bump version --- examples/roleplay.py | 4 +- pdm.lock | 105 +++++++++++----------------------- pyproject.toml | 9 ++- src/prompt_bottle/__init__.py | 8 +-- src/prompt_bottle/bottle.py | 4 +- 5 files changed, 49 insertions(+), 81 deletions(-) diff --git a/examples/roleplay.py b/examples/roleplay.py index 6e93cf0..4c30b52 100644 --- a/examples/roleplay.py +++ b/examples/roleplay.py @@ -10,7 +10,7 @@ from rich import print from stone_brick.llm.error import GeneratedNotValid from stone_brick.llm.utils import oai_gen_with_retry_then_validate -from stone_brick.parser.xml import tags_from_text +from stone_brick.parser import flat_xml_tags_from_text from prompt_bottle import PromptBottle @@ -190,7 +190,7 @@ async def try_generate( ) def validator(text: str): - tags = tags_from_text(text, [tag.value for tag in LogType]) + tags = flat_xml_tags_from_text(text, [tag.value for tag in LogType]) for item in tags: if isinstance(item, tuple): return LogType(item[0]), item[1] diff --git a/pdm.lock b/pdm.lock index a5bfe28..7f697b6 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:1e27341fe30165b1f1b38f1e75caa09978017cbd569e9d476ca932902b4a13de" +content_hash = "sha256:233b5ce4d9f6a5b96a5c97515beb4e58b177d62e632af49b03dbbcab638abc96" [[metadata.targets]] requires_python = ">=3.9" @@ -57,8 +57,8 @@ name = "colorama" version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." -groups = ["default", "dev"] -marker = "sys_platform == \"win32\" or platform_system == \"Windows\"" +groups = ["default"] +marker = "platform_system == \"Windows\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -80,7 +80,7 @@ name = "exceptiongroup" version = "1.2.2" requires_python = ">=3.7" summary = "Backport of PEP 654 (exception groups)" -groups = ["default", "dev"] +groups = ["default"] marker = "python_version < \"3.11\"" files = [ {file = "exceptiongroup-1.2.2-py3-none-any.whl", hash = "sha256:3111b9d131c238bec2f8f516e123e14ba243563fb135d3fe885990585aa7795b"}, @@ -145,17 +145,6 @@ files = [ {file = "idna-3.10.tar.gz", hash = "sha256:12f65c9b470abda6dc35cf8e63cc574b1c52b11df2c86030af0ac09b01b13ea9"}, ] -[[package]] -name = "iniconfig" -version = "2.0.0" -requires_python = ">=3.7" -summary = "brain-dead simple config-ini parsing" -groups = ["dev"] -files = [ - {file = "iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374"}, - {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, -] - [[package]] name = "jinja2" version = "3.1.4" @@ -356,28 +345,6 @@ files = [ {file = "openai-1.55.1.tar.gz", hash = "sha256:471324321e7739214f16a544e801947a046d3c5d516fae8719a317234e4968d3"}, ] -[[package]] -name = "packaging" -version = "24.2" -requires_python = ">=3.8" -summary = "Core utilities for Python packages" -groups = ["dev"] -files = [ - {file = "packaging-24.2-py3-none-any.whl", hash = "sha256:09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759"}, - {file = "packaging-24.2.tar.gz", hash = "sha256:c228a6dc5e932d346bc5739379109d49e8853dd8223571c7c5b55260edc0b97f"}, -] - -[[package]] -name = "pluggy" -version = "1.5.0" -requires_python = ">=3.8" -summary = "plugin and hook calling mechanisms for python" -groups = ["dev"] -files = [ - {file = "pluggy-1.5.0-py3-none-any.whl", hash = "sha256:44e1ad92c8ca002de6377e165f3e0f1be63266ab4d554740532335b9d75ea669"}, - {file = "pluggy-1.5.0.tar.gz", hash = "sha256:2cffa88e94fdc978c4c574f15f9e59b7f4201d439195c3715ca9e2486f1d0cf1"}, -] - [[package]] name = "pydantic" version = "2.9.2" @@ -495,25 +462,6 @@ files = [ {file = "pygments-2.18.0.tar.gz", hash = "sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199"}, ] -[[package]] -name = "pytest" -version = "8.3.3" -requires_python = ">=3.8" -summary = "pytest: simple powerful testing with Python" -groups = ["dev"] -dependencies = [ - "colorama; sys_platform == \"win32\"", - "exceptiongroup>=1.0.0rc8; python_version < \"3.11\"", - "iniconfig", - "packaging", - "pluggy<2,>=1.5", - "tomli>=1; python_version < \"3.11\"", -] -files = [ - {file = "pytest-8.3.3-py3-none-any.whl", hash = "sha256:a6853c7375b2663155079443d2e45de913a911a11d669df02a50814944db57b2"}, - {file = "pytest-8.3.3.tar.gz", hash = "sha256:70b98107bd648308a7952b06e6ca9a50bc660be218d53c257cc1fc94fda10181"}, -] - [[package]] name = "pyyaml" version = "6.0.2" @@ -585,6 +533,33 @@ files = [ {file = "rich-13.9.4.tar.gz", hash = "sha256:439594978a49a09530cff7ebc4b5c7103ef57baf48d5ea3184f21d9a2befa098"}, ] +[[package]] +name = "ruff" +version = "0.8.1" +requires_python = ">=3.7" +summary = "An extremely fast Python linter and code formatter, written in Rust." +groups = ["dev"] +files = [ + {file = "ruff-0.8.1-py3-none-linux_armv6l.whl", hash = "sha256:fae0805bd514066f20309f6742f6ee7904a773eb9e6c17c45d6b1600ca65c9b5"}, + {file = "ruff-0.8.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:b8a4f7385c2285c30f34b200ca5511fcc865f17578383db154e098150ce0a087"}, + {file = "ruff-0.8.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:cd054486da0c53e41e0086e1730eb77d1f698154f910e0cd9e0d64274979a209"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2029b8c22da147c50ae577e621a5bfbc5d1fed75d86af53643d7a7aee1d23871"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:2666520828dee7dfc7e47ee4ea0d928f40de72056d929a7c5292d95071d881d1"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:333c57013ef8c97a53892aa56042831c372e0bb1785ab7026187b7abd0135ad5"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:288326162804f34088ac007139488dcb43de590a5ccfec3166396530b58fb89d"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b12c39b9448632284561cbf4191aa1b005882acbc81900ffa9f9f471c8ff7e26"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:364e6674450cbac8e998f7b30639040c99d81dfb5bbc6dfad69bc7a8f916b3d1"}, + {file = "ruff-0.8.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b22346f845fec132aa39cd29acb94451d030c10874408dbf776af3aaeb53284c"}, + {file = "ruff-0.8.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:b2f2f7a7e7648a2bfe6ead4e0a16745db956da0e3a231ad443d2a66a105c04fa"}, + {file = "ruff-0.8.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:adf314fc458374c25c5c4a4a9270c3e8a6a807b1bec018cfa2813d6546215540"}, + {file = "ruff-0.8.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:a885d68342a231b5ba4d30b8c6e1b1ee3a65cf37e3d29b3c74069cdf1ee1e3c9"}, + {file = "ruff-0.8.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:d2c16e3508c8cc73e96aa5127d0df8913d2290098f776416a4b157657bee44c5"}, + {file = "ruff-0.8.1-py3-none-win32.whl", hash = "sha256:93335cd7c0eaedb44882d75a7acb7df4b77cd7cd0d2255c93b28791716e81790"}, + {file = "ruff-0.8.1-py3-none-win_amd64.whl", hash = "sha256:2954cdbe8dfd8ab359d4a30cd971b589d335a44d444b6ca2cb3d1da21b75e4b6"}, + {file = "ruff-0.8.1-py3-none-win_arm64.whl", hash = "sha256:55873cc1a473e5ac129d15eccb3c008c096b94809d693fc7053f588b67822737"}, + {file = "ruff-0.8.1.tar.gz", hash = "sha256:3583db9a6450364ed5ca3f3b4225958b24f78178908d5c4bc0f46251ccca898f"}, +] + [[package]] name = "sniffio" version = "1.3.1" @@ -598,25 +573,13 @@ files = [ [[package]] name = "stone-brick-toolkit" -version = "0.5.0" +version = "0.6.1" requires_python = ">=3.9" summary = "Stone Brick is a toolkit providing some commonly used utilities." groups = ["default"] files = [ - {file = "stone_brick_toolkit-0.5.0-py3-none-any.whl", hash = "sha256:093e512760fde14ade9abdb72b6ed055def15f3804a315d40d62e0d0ce6b2c9d"}, - {file = "stone_brick_toolkit-0.5.0.tar.gz", hash = "sha256:643803098c93aae468f248242d5304642a0735e07ff4e64e9288ba9667393e28"}, -] - -[[package]] -name = "tomli" -version = "2.1.0" -requires_python = ">=3.8" -summary = "A lil' TOML parser" -groups = ["dev"] -marker = "python_version < \"3.11\"" -files = [ - {file = "tomli-2.1.0-py3-none-any.whl", hash = "sha256:a5c57c3d1c56f5ccdf89f6523458f60ef716e210fc47c4cfb188c5ba473e0391"}, - {file = "tomli-2.1.0.tar.gz", hash = "sha256:3f646cae2aec94e17d04973e4249548320197cfabdf130015d023de4b74d8ab8"}, + {file = "stone_brick_toolkit-0.6.1-py3-none-any.whl", hash = "sha256:cfb759c14c15ce44efd96a15c7883e40a7e112d663a6362062e3a7587f7d879b"}, + {file = "stone_brick_toolkit-0.6.1.tar.gz", hash = "sha256:bd1dd12ee120c0f2f4953b32370db2f12d0e94fb0acd7a9600f9ca5bbc6a43df"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index 3a728c3..a9ef3c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "prompt_bottle" -version = "0.1.4" +version = "0.1.5" description = "LLM-targeted template engine, built upon Jinja" authors = [ {name = "Yanli",email = "mail@yanli.one"}, @@ -9,7 +9,7 @@ dependencies = [ "openai>=1.51.2", "jinja2>=3.1.4", "PyYAML>=6.0.2", - "stone-brick-toolkit~=0.5.0" + "stone-brick-toolkit>=0.6.1,<1.0.0" ] requires-python = ">=3.9" readme = "README.md" @@ -31,6 +31,11 @@ build-backend = "pdm.backend" [tool.pdm] distribution = true +[tool.pdm.dev-dependencies] +dev = [ + "rich>=13.9.4", + "ruff>=0.8.1", +] [tool.pyright] venvPath = ".venv" diff --git a/src/prompt_bottle/__init__.py b/src/prompt_bottle/__init__.py index e1f62da..b4f6c2e 100644 --- a/src/prompt_bottle/__init__.py +++ b/src/prompt_bottle/__init__.py @@ -10,12 +10,12 @@ ) __all__ = [ - "PromptBottle", - "simple_bottle", "PBTag", - "pb_tag", + "PromptBottle", + "pb_audio", "pb_img_url", "pb_mp3_audio", + "pb_tag", "pb_wav_audio", - "pb_audio", + "simple_bottle", ] diff --git a/src/prompt_bottle/bottle.py b/src/prompt_bottle/bottle.py index 70006dd..ed32898 100644 --- a/src/prompt_bottle/bottle.py +++ b/src/prompt_bottle/bottle.py @@ -21,7 +21,7 @@ from openai.types.chat.chat_completion_assistant_message_param import ( ContentArrayOfContentPart, ) -from stone_brick.parser.xml import tags_from_text +from stone_brick.parser.xml import flat_xml_tags_from_text from prompt_bottle.tags.convert_to import PB_TAG_TO_OPENAI, to_text_part from prompt_bottle.tags.tags import PBTag @@ -111,7 +111,7 @@ def render_text( text = Template(text).render(**kwargs) parts: List[ChatCompletionContentPartParam] = [] - tags = tags_from_text(text, [tag.value for tag in PBTag]) + tags = flat_xml_tags_from_text(text, [tag.value for tag in PBTag]) for tag in tags: if isinstance(tag, tuple): name, content = tag