Skip to content

Commit

Permalink
Test for basic async conversation, refs #632
Browse files Browse the repository at this point in the history
simonw committed Nov 14, 2024
1 parent 041730d commit 157b29d
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions llm/models.py
Original file line number Diff line number Diff line change
@@ -660,3 +660,11 @@ def _conversation_name(text):
if len(text) <= CONVERSATION_NAME_LENGTH:
return text
return text[: CONVERSATION_NAME_LENGTH - 1] + "…"


@dataclass
class Usage:
model_id: str
input_tokens: int
output_tokens: int
details: Dict[str, int]
13 changes: 13 additions & 0 deletions tests/test_async.py
Original file line number Diff line number Diff line change
@@ -15,3 +15,16 @@ async def test_async_model(async_mock_model):
text = await response.text()
assert text == "hello world"
assert isinstance(response, llm.AsyncResponse)


@pytest.mark.asyncio
async def test_async_model_conversation(async_mock_model):
async_mock_model.enqueue(["joke 1"])
conversation = async_mock_model.conversation()
response = await conversation.prompt("joke")
text = await response.text()
assert text == "joke 1"
async_mock_model.enqueue(["joke 2"])
response2 = await conversation.prompt("again")
text2 = await response2.text()
assert text2 == "joke 2"

0 comments on commit 157b29d

Please sign in to comment.