Skip to content

Commit

Permalink
Add simple test for run_chat_completion_with_image method
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaris committed Dec 4, 2024
1 parent 14f61c1 commit 844c312
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/test_openai_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import base64
import os
import unittest

import requests

from mira.openai import OpenAIClient


@unittest.skipIf(os.environ.get('GITHUB_ACTIONS') is not None,
reason="Meant to be run locally")
@unittest.skipIf(os.environ.get('OPENAI_API_KEY') is None,
reason="Need OPENAI_API_KEY environment variable to run")
def test_explain_image():
bananas_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9b/Cavendish_Banana_DS.jpg/640px-Cavendish_Banana_DS.jpg"
res = requests.get(bananas_url)
base64_image = base64.b64encode(res.content).decode('utf-8')

client = OpenAIClient()
response = client.run_chat_completion_with_image(
message="What is in this image?",
base64_image=base64_image,
image_format="jpeg",
)
assert "banana" in response.message.content, response.message.content

0 comments on commit 844c312

Please sign in to comment.