Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ollama images #59

Merged
merged 7 commits into from
Jul 29, 2024
Merged

Ollama images #59

merged 7 commits into from
Jul 29, 2024

Conversation

ccreutzi
Copy link
Member

@ccreutzi ccreutzi commented Jul 25, 2024

  • Refactor messageHistory to be agnostic of the image encoding.
  • Add backend encoding of images to openAIChat, azureChat, and ollamaChat.
  • Add image test points to the test files.

As for the image encoding, Azure expects messages like this:

{ 
    "messages": [ 
        { "role": "system", "content": "You are a helpful assistant." }, 
        { "role": "user", "content": [  
            { 
                "type": "text", 
                "text": "Describe this picture:" 
            },
            { 
                "type": "image_url",
                "image_url": {
                    "url": "<image URL>"
                }
            }
        ] } 
    ], 
    "max_tokens": 2000 
} 

where <image URL> can be a “normal” URL like "https://somewhere.tld/filepath.png" or an inline URL like "data:image/jpeg;base64,{base64_image}".

Multiple images can be in the same "content" array or in multiple "user" messages, experiments say. With this change, we are sending them in one "user" message.

The image encoding for OpenAI is the same as for Azure.

Ollama wants to get images in a different format:

{
  "model": "llava",
  "messages": [
    {
      "role": "user",
      "content": "what is in this image?",
      "images": ["{base64_image}"]
    }
  ]
}

ccreutzi added 4 commits July 25, 2024 12:45
* Refactor `messageHistory` to be agnostic of the image encoding.
* Add backend encoding of images to `openAIChat`, `azureChat`, and `ollamaChat`.
* Add image test points to the test files.

Open question: Can we reliably detect which Ollama models support vision?
Preinstall bakllava, to have a vision model
tests/topenAIChat.m Show resolved Hide resolved
doc/Ollama.md Outdated Show resolved Hide resolved
Co-authored-by: MiriamScharnke <[email protected]>
doc/Ollama.md Outdated Show resolved Hide resolved
@ccreutzi ccreutzi requested a review from MiriamScharnke July 29, 2024 13:48
@ccreutzi ccreutzi merged commit c3bec04 into main Jul 29, 2024
1 check failed
@ccreutzi ccreutzi deleted the ollama-images branch July 29, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants