Skip to content

Commit

Permalink
Handle cases with no available image by sending text-only messages to…
Browse files Browse the repository at this point in the history
… the Ollama model
  • Loading branch information
healthonrails committed Nov 14, 2024
1 parent 104f618 commit e7d9437
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions annolid/gui/widgets/caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,21 @@ def run(self):
import ollama

prompt = f"Improve or rewrite the following caption, considering the image:\n\n{self.current_caption}"
response = ollama.chat(
model='llama3.2-vision',
messages=[{
if self.image_path and os.path.exists(self.image_path):
messages = [{
'role': 'user',
'content': prompt,
'images': [self.image_path]
}]
else:
messages = [{
'role': 'user',
'content': prompt,
}]

response = ollama.chat(
model='llama3.2-vision',
messages=messages
)

if "message" in response and "content" in response["message"]:
Expand Down Expand Up @@ -556,7 +564,7 @@ def run(self):
import ollama

messages = [{'role': 'user', 'content': self.prompt}]
if self.image_path:
if self.image_path and os.path.exists(self.image_path):
# Attach the image if provided
messages[0]['images'] = [self.image_path]

Expand Down

0 comments on commit e7d9437

Please sign in to comment.