lmstudio-ai / lmstudio-ai/docs
Image Input with Python Binary IO objects generate random answer
- Dominant language
- MDX
- Stars
- 172
- Forks
- 128
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Description
Python codes here:
```py
def download_image(src) -> BytesIO:
resp = req.get(src, headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"}, stream=True, timeout=10)
resp.raise_for_status()
img_data = BytesIO(resp.content)
img_data.seek(0)
return img_data
def caption_image(src, cache_dir):
model = lms.llm(config={"temperature": 0.1})
try:
img = download_image(src)
image_handle = lms.prepare_image(img)
chat = lms.Chat()
chat.add_user_message("Describe this image please ", images=[image_handle])
prediction = model.respond(chat)
return f""
except:
return f""
```
repond random answer.
but save image to temp file and `prepare_image(/path/to/temp.jpeg)` works fine.
Contributor guide
Research direction
Start at the lms.prepare_image entry point and reproduce the reported behavior with the BytesIO object returned by download_image. Compare it with the temporary-file path that works, and verify that binary IO input produces a consistent image response rather than a random answer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100