replicate/replicate-python

stream output's type

callanwu opened this issue · 1 comments

When i use the provided steam output's example code(https://github.com/replicate/replicate-python#run-a-model-and-stream-its-output), it output nothing but output blank lines.
Is this related to the type of event?
May be the code should be

import replicate

# https://replicate.com/meta/llama-2-70b-chat
model_version = "meta/llama-2-70b-chat:02e509c789964a7ea8736978a43525956ef40397be9033abf9fd2badfe68c9e3"

tokens = []
for event in replicate.stream(
    model_version,
    input={
        "prompt": "Please write a haiku about llamas.",
    },
):
    print(event.data)
    tokens.append(str(event.data))

print(" ".join(tokens))

But when I use the above code, it always output a {} at the end.
Could you provide a correct code example?

Hi @callanwu. Thanks for reporting, and sorry for any convenience. I found some bugs in the stream method that I fixed in #214. Those are now available in 0.21.1. Please let me know if you have any more issues with this.