Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update & Pin versions #74

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_language_version:
repos:
# check some basic stuff
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
# Check for files that would conflict in case-insensitive filesystems
- id: check-case-conflict
Expand All @@ -22,12 +22,12 @@ repos:
args: [--filter-files, --profile, black]
# Format the python code with black
- repo: https://github.com/psf/black
rev: 23.12.1
rev: 24.8.0
hooks:
- id: black
# Lint the python code with flake
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
# Type check the Python code with pylint
Expand All @@ -38,7 +38,7 @@ repos:
entry: pylint
language: python
types: [python]
additional_dependencies: ['pylint==3.0.3']
additional_dependencies: ['pylint==3.3.0']
args:
[
"-rn", # Only display messages
Expand All @@ -47,7 +47,7 @@ repos:
]
# Type check the Python code with MyPy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.8.0'
rev: 'v1.11.2'
hooks:
- id: mypy
verbose: true
Expand All @@ -61,4 +61,4 @@ repos:
language: node
pass_filenames: false
types: [python]
additional_dependencies: ['[email protected].345']
additional_dependencies: ['[email protected].381']
2 changes: 1 addition & 1 deletion pdl/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def accumulator(self, q):
)


def write_log( # pylint: disable=too-many-arguments
def write_log( # pylint: disable=too-many-arguments,too-many-positional-arguments
log, index, question, truth, answer, solution, document, exc
):
log.write("\n\n------------------------\n")
Expand Down
45 changes: 22 additions & 23 deletions pdl/pdl_ast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""PDL programs are represented by the Pydantic data structure defined in this file.
"""


from enum import StrEnum
from typing import Any, Literal, Optional, TypeAlias, TypedDict, Union

Expand Down Expand Up @@ -353,7 +352,7 @@ class MessageBlock(Block):
"""Create a message."""

kind: Literal[BlockKind.MESSAGE] = BlockKind.MESSAGE
role: RoleType
role: RoleType # type: ignore
"""Role of associated to the message."""
content: "BlocksType"
"""Content of the message."""
Expand Down Expand Up @@ -602,32 +601,32 @@ def set_default_granite_model_parameters(
if parameters is None:
parameters = {}
if "decoding_method" not in parameters:
parameters[
"decoding_method"
] = DECODING_METHOD # pylint: disable=attribute-defined-outside-init
parameters["decoding_method"] = (
DECODING_METHOD # pylint: disable=attribute-defined-outside-init
)
if "max_tokens" in parameters and parameters["max_tokens"] is None:
parameters[
"max_tokens"
] = MAX_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
parameters["max_tokens"] = (
MAX_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
)
if "min_new_tokens" not in parameters:
parameters[
"min_new_tokens"
] = MIN_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
parameters["min_new_tokens"] = (
MIN_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
)
if "repetition_penalty" not in parameters:
parameters[
"repetition_penalty"
] = REPETITION_PENATLY # pylint: disable=attribute-defined-outside-init
parameters["repetition_penalty"] = (
REPETITION_PENATLY # pylint: disable=attribute-defined-outside-init
)
if parameters["decoding_method"] == "sample":
if "temperature" not in parameters:
parameters[
"temperature"
] = TEMPERATURE_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["temperature"] = (
TEMPERATURE_SAMPLING # pylint: disable=attribute-defined-outside-init
)
if "top_k" not in parameters:
parameters[
"top_k"
] = TOP_K_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["top_k"] = (
TOP_K_SAMPLING # pylint: disable=attribute-defined-outside-init
)
if "top_p" not in parameters:
parameters[
"top_p"
] = TOP_P_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["top_p"] = (
TOP_P_SAMPLING # pylint: disable=attribute-defined-outside-init
)
return parameters
3 changes: 1 addition & 2 deletions pdl/pdl_compilers/to_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

class Re(ABC):
@abstractmethod
def to_re(self) -> str:
...
def to_re(self) -> str: ...


class ReEmpty(Re):
Expand Down
6 changes: 3 additions & 3 deletions pdl/pdl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def block_to_dict(block: pdl_ast.BlockType) -> int | float | str | dict[str, Any
def blocks_to_dict(
blocks: BlocksType,
) -> int | float | str | dict[str, Any] | list[int | float | str | dict[str, Any]]:
result: int | float | str | dict[str, Any] | list[
int | float | str | dict[str, Any]
]
result: (
int | float | str | dict[str, Any] | list[int | float | str | dict[str, Any]]
)
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
result = [block_to_dict(block) for block in blocks]
else:
Expand Down
4 changes: 2 additions & 2 deletions pdl/pdl_llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_model() -> BamClient:
return BamModel.bam_client

@staticmethod
def generate_text( # pylint: disable=too-many-arguments
def generate_text( # pylint: disable=too-many-arguments,too-many-positional-arguments
model_id: str,
prompt_id: Optional[str],
model_input: Optional[str],
Expand All @@ -69,7 +69,7 @@ def generate_text( # pylint: disable=too-many-arguments
return {"role": None, "content": text}

@staticmethod
def generate_text_stream( # pylint: disable=too-many-arguments
def generate_text_stream( # pylint: disable=too-many-arguments,too-many-positional-arguments
model_id: str,
prompt_id: Optional[str],
model_input: Optional[str],
Expand Down
14 changes: 7 additions & 7 deletions pdl/pdl_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def schedule(
) -> list[GeneratorReturnT]:
global _LAST_ROLE # pylint: disable= global-statement
todo: list[tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]]
todo_next: list[
tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]
] = []
todo_next: list[tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]] = (
[]
)
done: list[Optional[GeneratorReturnT]]
todo = [(i, gen, None) for i, gen in enumerate(generators)]
done = [None for _ in generators]
Expand All @@ -106,10 +106,10 @@ def schedule(
try:
msg = gen.send(v)
match msg:
case ModelYieldResultMessage(
result=result
) | CodeYieldResultMessage(result=result) | YieldResultMessage(
result=result
case (
ModelYieldResultMessage(result=result)
| CodeYieldResultMessage(result=result)
| YieldResultMessage(result=result)
):
if msg.color is None:
text = stringify(result)
Expand Down
8 changes: 5 additions & 3 deletions pdl/pdl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def messages_to_str(messages: Messages) -> str:
# TODO
return "".join(
[
msg["content"]
if msg["role"] is None
else f"<|{msg['role']}|>{msg['content']}"
(
msg["content"]
if msg["role"] is None
else f"<|{msg['role']}|>{msg['content']}"
)
for msg in messages
]
)
46 changes: 23 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ build-backend = "setuptools.build_meta"
name = "pdl"
version = "0.0.1"
dependencies = [
"pydantic",
"ibm-generative-ai",
"requests",
"python-dotenv",
"jinja2",
"PyYAML",
"jsonschema",
"litellm",
"termcolor",
"ipython"
"pydantic~=2.0",
"ibm-generative-ai~=3.0",
"requests~=2.0",
"python-dotenv~=1.0",
"jinja2~=3.0",
"PyYAML~=6.0",
"jsonschema~=4.0",
"litellm~=1.47",
"termcolor~=2.0",
"ipython~=8.0"
]
authors = [
{ name="Mandana Vaziri", email="[email protected]" },
{ name="Louis Mandel", email="[email protected]"},
{ name="Claudio Spiess" },
{ name="Claudio Spiess", email="[email protected]" },
{ name="Martin Hirzel", email="[email protected]" }
]
description = "Prompt Declaration Language"
Expand All @@ -34,22 +34,22 @@ classifiers = [

[project.optional-dependencies]
dev = [
"black",
"pre-commit",
"pytest"
"pre-commit~=3.0",
"pytest~=8.0",
"pydantic~=2.9"
]
examples = [
"wikipedia",
"textdistance",
"faiss-cpu",
"datasets",
"sympy"
"wikipedia~=1.0",
"textdistance~=4.0",
"faiss-cpu~=1.0",
"datasets>2,<4",
"sympy~=1.0"
]
docs = [
"mkdocs",
"mkdocstrings[python]",
"mkdocs-material",
"pymdown-extensions"
"mkdocs~=1.0",
"mkdocstrings[python]~=0.0",
"mkdocs-material~=9.0",
"pymdown-extensions~=10.0"
]
all = [ "pdl[dev,examples,docs]" ]

Expand Down