-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: openai vision toolkit #269
Draft
AaronGoldsmith
wants to merge
5
commits into
block:main
Choose a base branch
from
AaronGoldsmith:aarong/feat-vision-toolkit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
62fbd06
initial commit with vision
AaronGoldsmith fc9fdde
update integration tests
AaronGoldsmith b1c0690
branch clean up
AaronGoldsmith 07f74de
fix pathing
AaronGoldsmith 3966947
feat: enhance image handling in message processing and tests
AaronGoldsmith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# import pytest | ||
import base64 | ||
from exchange.exchange import Exchange | ||
from exchange.message import Message | ||
from exchange.content import ImageUrl | ||
from exchange.providers.openai import OpenAiProvider | ||
import httpx | ||
|
||
|
||
def test_describe_image_url(): | ||
image_url = ImageUrl(url="https://picsum.photos/id/1/200/200") | ||
user_message = Message(role="user", content=["Describe the image: ", image_url]) | ||
ex = Exchange( | ||
provider=OpenAiProvider.from_env(), | ||
model="gpt-4o", | ||
system="You are a helpful assistant.", | ||
tools=[], | ||
) | ||
ex.add(user_message) | ||
res = ex.reply() | ||
assert "laptop" in res.content[0].text | ||
|
||
def test_image_comparison_url_and_data(): | ||
image_url_base64 = base64.standard_b64encode(httpx.get("https://picsum.photos/id/1/200/200").content).decode("utf-8") | ||
image_url = ImageUrl(url="https://picsum.photos/id/1/200/200") | ||
user_message = Message(role="user", content=["Are these images the same? ", image_url_base64, image_url ]) | ||
ex = Exchange( | ||
provider=OpenAiProvider.from_env(), | ||
model="gpt-4o", | ||
system="Reply with yes or no.", | ||
tools=[], | ||
) | ||
ex.add(user_message) | ||
res = ex.reply() | ||
assert "yes" in res.content[0].text.lower() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from exchange.content import ImageUrl | ||
from exchange.exchange import Exchange | ||
from exchange.message import Message | ||
from exchange.providers.openai import OpenAiProvider | ||
from goose.toolkit.base import Toolkit, tool | ||
|
||
class VisionToolkit(Toolkit): | ||
"""A toolkit for image analysis using AI capabilities.""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
@tool | ||
def describe_image(self, image: str, instructions: str="Describe the image") -> str: | ||
"""Analyze an image and return a description or other analysis based on the instructions. | ||
|
||
Args: | ||
image (ImageUrl): The URL of the image to analyze. | ||
instructions (str): Instructions for the AI on what kind of analysis to perform. | ||
""" | ||
image = ImageUrl(url=image) | ||
user_message = Message(role="user", content=[f"{instructions}: ", image]) | ||
exchange = Exchange( | ||
provider=OpenAiProvider.from_env(), | ||
model="gpt-4o-mini", | ||
system="You are a helpful assistant.", | ||
messages=[user_message], | ||
tools=[], | ||
) | ||
assistant_response = exchange.reply() | ||
return assistant_response.content[0].text | ||
|
||
def system(self) -> str: | ||
return """This toolkit allows you to visually analyze images using AI capabilities.""" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before updating
content_converter
I would get the following: