technovangelist.videoprojects/2024-04-01-intro-dev-python/3.py
Matt Williams d0e67e52e3 reorg
Signed-off-by: Matt Williams <m@technovangelist.com>
2024-04-03 09:38:52 -07:00

15 lines
401 B
Python

import ollama
prompt = "why is the sky blue";
output = ollama.generate(model="llama2", prompt=prompt, stream=True)
# print(output)
for chunk in output:
print(chunk["response"], end='', flush=True)
if chunk["done"] == True:
tokens_per_second = chunk["eval_count"] / (chunk["eval_duration"] / 1000000000)
print("\nstats: {:.2f} tokens per second".format(tokens_per_second))