diff --git a/docs/python-api.md b/docs/python-api.md index 903fbcb..bf963d9 100644 --- a/docs/python-api.md +++ b/docs/python-api.md @@ -19,7 +19,13 @@ print(response.text()) ``` The `llm.get_model()` function accepts model names or aliases - so `chatgpt` would work here too. -Run this command to see a list of available models and their aliases: +The `__str__()` method of `response` also returns the text of the response, so you can do this instead: + +```python +print(response) +``` + +You can run this command to see a list of available models and their aliases: ```bash llm models diff --git a/llm/models.py b/llm/models.py index 3ebb51e..7126c5e 100644 --- a/llm/models.py +++ b/llm/models.py @@ -105,6 +105,9 @@ class Response(ABC): if not self._done: list(self) + def __str__(self) -> str: + return self.text() + def text(self) -> str: self._force() return "".join(self._chunks) diff --git a/tests/test_chat.py b/tests/test_chat.py index aa866ba..f19bcc5 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -10,6 +10,7 @@ def test_mock_model(mock_model): model = llm.get_model("mock") response = model.prompt(prompt="hello") assert response.text() == "hello world" + assert str(response) == "hello world" assert model.history[0][0].prompt == "hello" response2 = model.prompt(prompt="hello again") assert response2.text() == "second"