-
|
What is the best way to implement image input? As I'm looking at the scripts generating SVG files using
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
|
Example of the behavior I'd like to have during late sessions:
|
Beta Was this translation helpful? Give feedback.
-
|
Here's the python image input request example: #!/usr/bin/env python3
import base64
import requests
OPENAI_BASE_URL = "http://localhost:9280"
OPENAI_MODEL="qwen3.6-27b-q4-c128k"
OPENAI_API_KEY = ""
# base64 encode the file
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# Example image from
# https://en.wikipedia.org/wiki/Computer_network_diagram#/media/File:Sample-network-diagram.png
image_path = "./examples/Sample-network-diagram.png"
# base64 string
base64_image = encode_image(image_path)
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {OPENAI_API_KEY}"
}
# mimetype image/jpeg does not matter for llama.cpp llama-server
# it only reads bytes from request, so we can send PNG too.
payload = {
"model": OPENAI_MODEL,
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Describe this image."
},
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}"
}
}
]
}
],
"max_tokens": 16384
}
response = requests.post(f"{OPENAI_BASE_URL}/v1/chat/completions", headers=headers, json=payload)
if response.status_code == 200:
result = response.json()
print(result["choices"][0]["message"]["content"])
else:
print(f"Error posting request, status code {response.status_code}")$ uv run python post-image-example.py
This image is a schematic diagram illustrating a basic
computer network topology. It depicts how various hardware
components are connected to share resources and access the internet.
Here is a breakdown of the components from left to right:
- **Client Computers:** On the far left, there are three
desktop computers, each consisting of a tower case and a monitor.
- **Switch:** These three computers are connected via
black lines to a square device labeled "Switch."
- **Server:** The Switch is connected to a large, vertical
tower in the center labeled "Server." This acts as
the central hub for the local network.
- **Printer:** Connected to the top of the
Server is a device labeled "Printer."
- **Router:** To the right of the Server,
there is a device labeled "Router."
- **The Internet:** The Router is connected via a jagged line
to a cloud shape labeled "The Internet," indicating the gateway
to the outside world.
In summary, the diagram shows a local network where
three user computers connect through a switch to a central server,
which manages a printer and provides internet access through a router. |
Beta Was this translation helpful? Give feedback.
-
|
@aa956 so the codebase uses Bubbletea as its TUI framework and it does not currently support images. |
Beta Was this translation helpful? Give feedback.
-
|
@giveen, idea is not to show images to user but to upload them for checking by multimodal model. Use case: Working on a script generating SVG.
It's a very low priority but probably useful feature to have if project worked on generates images somehow (UI that can be screenshotted and reviewed by a model or like my case now, script generating SVG drawings). For now I'm just using chat UI for that (dumping entire project's sources in a single Markdown file there together with image):
|
Beta Was this translation helpful? Give feedback.
-
|
I will look into it. The issue is not necessarily passing the image to the model that is more or less trivial (as your own python script shows the oai api handles that). |
Beta Was this translation helpful? Give feedback.
-
|
@mlhher kinda long this line, i was thinking about building out a image input, but it would need to be able to detect that the local model has the mmproj . So a user would go "Heh look at /mnt/storage/path/image.png this is how I want my UI to look", and maybe have an environmental variable of VISION_SUBAGENT |
Beta Was this translation helpful? Give feedback.


I will look into it. The issue is not necessarily passing the image to the model that is more or less trivial (as your own python script shows the oai api handles that).