', 'context': [], }, stream=True)r.raise_for_status()for line in r.iter_lines(): body = json.loads(line) response_part = body.get('response', '') # the response streams one token at a time, print that as we receive it print(response_part, end='', flush=True)if 'error' in body: raise Exception(body['error'])if body.get('done', False): print(body['context'])