What's Changed
* Add streaming for string output by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/5
* Add publish github workflow by jackmpcollins in https://github.com/jackmpcollins/magentic/pull/6
**Full Changelog**: https://github.com/jackmpcollins/magentic/compare/v0.1.4...v0.2.0
---
Streaming
The `StreamedStr` (and `AsyncStreamedStr`) class can be used to stream the output of the LLM. This allows you to process the text while it is being generated, rather than receiving the whole output at once. Multiple `StreamedStr` can be created at the same time to stream LLM outputs concurrently. In the below example, generating the description for multiple countries takes approximately the same amount of time as for a single country.
python
from magentic import prompt, StreamedStr
prompt("Tell me about {country}")
def describe_country(country: str) -> StreamedStr:
...
Print the chunks while they are being received
for chunk in describe_country("Brazil"):
print(chunk, end="")
'Brazil, officially known as the Federative Republic of Brazil, is ...'
Generate text concurrently by creating the streams before consuming them
streamed_strs = [describe_country(c) for c in ["Australia", "Brazil", "Chile"]]
[str(s) for s in streamed_strs]
["Australia is a country ...", "Brazil, officially known as ...", "Chile, officially known as ..."]