Skip to content

Commit

Permalink
Merge pull request #32 from atomiechen/dev
Browse files Browse the repository at this point in the history
Bump version to 0.8.2
  • Loading branch information
atomiechen authored Jun 29, 2024
2 parents f3d7310 + 8ec2412 commit 92f77a8
Show file tree
Hide file tree
Showing 40 changed files with 383 additions and 282 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ temp*
*.flac
*.aac

# test output
.coverage*
.pytest_cache
htmlcov
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,45 @@ All notable changes to HandyLLM will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).


## [0.8.2] - 2024-06-30

### Added

- `hprompt`: load methods now support `cls` parameter for prompt type specification
- `ChatPrompt` and `CompletionsPrompt` support optional request and meta
- `ChatPrompt` :
- supports add dict
- add `add_message(...)` method
- `CompletionsPrompt`:
- add `add_text(...)` method
- `PromptConverter`: `yaml.dump` uses `allow_unicode=True` option
- move all type definitions to `_types.py`
- support for package development:
- add `requirement.txt` for development
- add `scripts/test.sh` for running tests
- add test scripts in `tests` folder

### Fixed

- `HandyPrompt.eval(...)` should not make directories for output paths
- `CompletionsPrompt._run_with_client(...)`: misplaced `run_config` param
- `PromptConverter`
- fix variable replacement for `content_array` message
- fix wrong return type of `stream_msgs2raw` and `astream_msgs2raw`
- `requestor`:
- `httpx.Response` should use `reason_phrase` to get error reason
- `acall()` fix missing brackets for await
- `_call_raw()` and `_acall_raw()` intercept and raise new exception without original one
- `_acall_raw()`: read the response first to prevent `httpx.ResponseNotRead` before getting error message
- `_utils.exception2err_msg(...)` should append error message instead of printing
- change `io.IOBase` to `IO[str]` for file descriptors (e.g. `RunConfig.output_fd`)
- fix other type hints

### Changed

- move all old files in `tests` folder to `examples` folder


## [0.8.1] - 2024-06-10

### Fixed
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "HandyLLM"
version = "0.8.1"
version = "0.8.2"
authors = [
{ name="Atomie CHEN", email="[email protected]" },
]
Expand Down Expand Up @@ -33,3 +33,8 @@ Changelog = "https://github.com/atomiechen/HandyLLM/blob/master/CHANGELOG.md"

[project.scripts]
handyllm = "handyllm.__main__:cli"

[tool.pytest.ini_options]
addopts = [
"--ignore=examples"
]
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-e .

# tests
pytest
pytest-cov
4 changes: 4 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -e
set -x

pytest --cov --cov-report=term-missing -o console_output_style=progress --cov-report=html
2 changes: 1 addition & 1 deletion src/handyllm/_str_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class StrEnumMeta(EnumMeta):
def __contains__(cls, item):
if isinstance(item, str):
return item in iter(cls)
return item in iter(cls) # type: ignore
return super().__contains__(item)


Expand Down
18 changes: 18 additions & 0 deletions src/handyllm/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys
from typing import Any, Awaitable, Callable, Dict, MutableMapping, Optional, Union
from os import PathLike


if sys.version_info >= (3, 9):
PathType = Union[str, PathLike[str]]
else:
PathType = Union[str, PathLike]

VarMapType = MutableMapping[str, str]

SyncHandlerChat = Callable[[str, Optional[str], Optional[Dict]], Any]
SyncHandlerCompletions = Callable[[str], Any]
AsyncHandlerChat = Callable[[str, Optional[str], Optional[Dict]], Awaitable[Any]]
AsyncHandlerCompletions = Callable[[str], Awaitable[Any]]
OnChunkType = Union[SyncHandlerChat, SyncHandlerCompletions, AsyncHandlerChat, AsyncHandlerCompletions]

6 changes: 3 additions & 3 deletions src/handyllm/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def exception2err_msg(exception: Exception):
err_msg = f"Exception: {type(exception).__module__}.{type(exception).__name__}"
err_msg += f"\nDetailed info: {repr(exception)}"
if exception.args:
print(f"\nException arguments: {exception.args}")
err_msg += f"\nException arguments: {exception.args}"
return err_msg

def _chat_log_response_final(logger, log_marks, kwargs, messages, start_time, role, content, err_msg=None):
Expand All @@ -91,7 +91,7 @@ def _chat_log_response(logger, log_marks, kwargs, messages, start_time, response
if logger is not None:
if stream:
if inspect.isasyncgen(response):
async def wrapper(response):
async def wrapper(response): # type: ignore
content = ''
role = ''
async for data in response:
Expand Down Expand Up @@ -155,7 +155,7 @@ def _completions_log_response(logger, log_marks, kwargs, prompt, start_time, res
if logger is not None:
if stream:
if inspect.isasyncgen(response):
async def wrapper(response):
async def wrapper(response): # type: ignore
text = ''
async for data in response:
try:
Expand Down
10 changes: 5 additions & 5 deletions src/handyllm/endpoint_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ def clear(self):
def __len__(self) -> int:
return len(self._endpoints)

def __getitem__(self, idx: int) -> Endpoint:
def __getitem__(self, idx):
return self._endpoints[idx]

def __setitem__(self, idx: int, endpoint: Endpoint):
def __setitem__(self, idx, endpoint):
self._endpoints[idx] = endpoint

def __delitem__(self, idx: int):
def __delitem__(self, idx):
del self._endpoints[idx]

def insert(self, idx: int, endpoint: Endpoint):
self._endpoints.insert(idx, endpoint)
def insert(self, index: int, value: Endpoint):
self._endpoints.insert(index, value)

def add_endpoint_by_info(self, **kwargs):
endpoint = Endpoint(**kwargs)
Expand Down
Loading

0 comments on commit 92f77a8

Please sign in to comment.