Validator If you pass a validator get_response will call it on the final string response and retry if it returns false up to retries times. Then it throws an exception. Total costs and retries are returned in the object but only the final passing text is accessible.
streaming_callback Called incrementally on the chunks. Useful for printing streams. print_stream is provided to reduce boilerplate.
A test for this is added. This is the first test so pytest, pytest_asyncio and WrappedTestClient is added. WrappedTestClient is a convenience WrappedClient which behaves like Openai's wrapped client except you pass in your desired output in the constructor.
Try with:
from spice import Spice, print_stream
client = Spice()
await client.get_response([{"role":"user","content":"write a random word"}],
model="gpt-3.5-turbo",
streaming_callback=print_stream,
validator=(lambda x: len(x)%4 == 1),
retries=3)
A test for this is added. This is the first test so pytest, pytest_asyncio and WrappedTestClient is added. WrappedTestClient is a convenience WrappedClient which behaves like Openai's wrapped client except you pass in your desired output in the constructor.
Try with: