Add image generation support (#616)
test / test (push) Has been cancelled
test / lint (push) Has been cancelled

This commit is contained in:
Jeffrey Morgan
2026-01-23 00:33:52 -08:00
committed by GitHub
parent 60e7b2f9ce
commit dbccf192ac
6 changed files with 179 additions and 2 deletions
+6
View File
@@ -78,6 +78,12 @@ Configuration to use with an MCP client:
- [multimodal-chat.py](multimodal-chat.py)
- [multimodal-generate.py](multimodal-generate.py)
### Image Generation (Experimental) - Generate images with a model
> **Note:** Image generation is experimental and currently only available on macOS.
- [generate-image.py](generate-image.py)
### Structured Outputs - Generate structured outputs with a model
- [structured-outputs.py](structured-outputs.py)
+18
View File
@@ -0,0 +1,18 @@
# Image generation is experimental and currently only available on macOS
import base64
from ollama import generate
prompt = 'a sunset over mountains'
print(f'Prompt: {prompt}')
for response in generate(model='x/z-image-turbo', prompt=prompt, stream=True):
if response.image:
# Final response contains the image
with open('output.png', 'wb') as f:
f.write(base64.b64decode(response.image))
print('\nImage saved to output.png')
elif response.total:
# Progress update
print(f'Progress: {response.completed or 0}/{response.total}', end='\r')