Skip to content

Commit

Permalink
ollama image support works
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ulrich committed Jun 22, 2024
1 parent 4147aad commit 1ebc6aa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion source/ai
Submodule ai updated 1 files
+6 −2 llm.py
18 changes: 17 additions & 1 deletion source/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ async def handle_message_openai(room,server,message,match):
history.insert(0,{"role": "assistant", "content": event.body})
elif event.source['event_id'] == thread_rel:
history.insert(0,{"role": "user", "content": event.body})
elif isinstance(event, nio.RoomEncryptedMedia)\
or isinstance(event, nio.RoomMessageMedia):
if ('m.relates_to' in event.source['content']\
and (event.source['content']['m.relates_to']['event_id'] == thread_rel))\
or event.source['event_id'] == thread_rel:
try:
images = []
target_folder = configpath / 'files' / room.room_id[1:room.room_id.find(':')-2] / event.event_id
with open(target_folder / event.body, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
images.append(encoded_string.decode())
entry = {"role": "user", "content": "whats in this image?", "images": images}
history.insert(0,entry)
images = []
except BaseException as e:
pass
if len(history)>int(server.history_count):
break
if len(history)>0:
Expand All @@ -57,7 +73,7 @@ async def handle_message_openai(room,server,message,match):
if words == [] or words[0] != match.command():
words = [match.command()]+words
elif hasattr(message,'url'):
words = ['what','shows','this','image','?']
words = ['whats','in','this','image','?']
target_folder = configpath / 'files' / room.room_id[1:room.room_id.find(':')-2] / message.event_id
with open(target_folder / message.body, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
Expand Down

0 comments on commit 1ebc6aa

Please sign in to comment.