Skip to content

Commit

Permalink
Merge pull request #45 from atomiechen/dev
Browse files Browse the repository at this point in the history
bump version to 0.9.2
  • Loading branch information
atomiechen authored Aug 9, 2024
2 parents 456427f + 62e4251 commit d1a0415
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ 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.9.2] - 2024-08-09

### Fixed

- fix DictProxy YAML dump
- fix tool calls in stream mode: missing last tool call

### Changed

- change import behavior:
- `__init__.py`:
- use explicit imports instead of `*`
- limit imports from `utils.py`
- remove all imports from `response.py` and `types.py` (please import them directly)
- `response.py`: add missing items to `__all__`
- add `py.typed` for better IDE support


## [0.9.1] - 2024-07-28

### Added
Expand Down
2 changes: 1 addition & 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.9.1"
version = "0.9.2"
authors = [
{ name="Atomie CHEN", email="[email protected]" },
]
Expand Down
39 changes: 38 additions & 1 deletion tests/test_tool_call.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import json
from pathlib import Path
import re
from handyllm import load_from, ChatPrompt, stream_chat_all
from handyllm import load_from, ChatPrompt, stream_chat_all, RunConfig
from pytest import CaptureFixture
import pytest
import responses
import respx


tests_dir = Path(__file__).parent
Expand Down Expand Up @@ -571,3 +573,38 @@ def test_tool_call_stream(capsys: CaptureFixture[str]):
# make sure no debug prints
captured = capsys.readouterr()
assert captured.out == ""


@pytest.mark.asyncio
@respx.mock
@responses.activate
async def test_on_chunk_tool_call():
responses.add(responses.POST, url=re.compile(r".*"), body=stream_body)
respx.post(re.compile(r".*")).respond(text=stream_body)
prompt_file = tests_dir / "assets" / "chat_tool.hprompt"
prompt = load_from(prompt_file, cls=ChatPrompt)

def on_chunk(role, content, tool_call):
assert role == "assistant"
assert content is None
state.append(tool_call)

async def aon_chunk(role, content, tool_call):
assert role == "assistant"
assert content is None
state.append(tool_call)

sync_run_config = RunConfig(on_chunk=on_chunk)
async_run_config = RunConfig(on_chunk=aon_chunk)

state = []
prompt.run(run_config=sync_run_config, api_key="fake-key", stream=True)
assert len(state) == 2

state = []
await prompt.arun(run_config=sync_run_config, api_key="fake-key", stream=True)
assert len(state) == 2

state = []
await prompt.arun(run_config=async_run_config, api_key="fake-key", stream=True)
assert len(state) == 2

0 comments on commit d1a0415

Please sign in to comment.