You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenAI and Anthropic packages both use context managers to ensure the stream for the streamed response is closed correctly. magentic should do the same!
Add a new Stream (and AsyncStream) class, that is an Iterable with an additional .close() method and ability to be used as a context manager (returning self and automatically calling .close() on exit). This should be usable as a return type on prompt-functions.
StreamedStr and StreamedResponse should also work similarly.
Maybe when the Iterable return type is used, we should return a Stream instance.
Example usage:
frommagenticimportprompt, StreamedStr@prompt("Tell me about {country}")defdescribe_country(country: str) ->StreamedStr: ...
# Print the chunks while they are being receivedwithdescribe_country("Brazil") asstream:
forchunkinstream:
print(chunk, end="")
# 'Brazil, officially known as the Federative Republic of Brazil, is ...'
The text was updated successfully, but these errors were encountered:
OpenAI and Anthropic packages both use context managers to ensure the stream for the streamed response is closed correctly. magentic should do the same!
Add a new
Stream
(andAsyncStream
) class, that is anIterable
with an additional.close()
method and ability to be used as a context manager (returning self and automatically calling.close()
on exit). This should be usable as a return type on prompt-functions.StreamedStr
andStreamedResponse
should also work similarly.Maybe when the
Iterable
return type is used, we should return aStream
instance.Example usage:
The text was updated successfully, but these errors were encountered: