This commit is contained in:
Ayman Hamed Moustafa 2025-01-24 09:23:36 +00:00 committed by GitHub
commit d89b3a3db9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 16 deletions

View file

@ -42,6 +42,7 @@ dependencies = [
"pathvalidate",
"charset-normalizer",
"openai",
"ollama"
]
[project.urls]

View file

@ -13,6 +13,7 @@ import sys
import tempfile
import traceback
import zipfile
from http.client import responses
from xml.dom import minidom
from typing import Any, Dict, List, Optional, Union
from pathlib import Path
@ -1096,7 +1097,26 @@ class ImageConverter(MediaConverter):
content_type = "image/jpeg"
image_base64 = base64.b64encode(image_file.read()).decode("utf-8")
data_uri = f"data:{content_type};base64,{image_base64}"
# check if Ollama client
if str(type(client)) == "<class 'ollama._client.Client'>":
messages = [
{
"role": "user",
"content": prompt,
'images': [local_path]
}
]
response = client.chat(
model = model,
messages = messages,
)
return response.message.content
else:# use openai
messages = [
{
"role": "user",
@ -1111,7 +1131,6 @@ class ImageConverter(MediaConverter):
],
}
]
response = client.chat.completions.create(model=model, messages=messages)
return response.choices[0].message.content