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

[Bug] Fix regex for urls in image function #928

Merged
merged 7 commits into from
Jul 12, 2024

Conversation

kklemon
Copy link
Contributor

@kklemon kklemon commented Jun 25, 2024

The regex for matching urls in the image function starts with a $ character (ref), i.e. the "match end of string"-metacharacter, which seems to be wrong. I guess the intention was to match against the start of the string, which could be achieved with a ^ character, but since re.match matches against the start of a string already, this can also be omitted in this specific case.

This led to the situation that urls are generally not recognized and can't be used with the image function. This PR attempts to fix this issue by modifying the aforementioned regex and additionally providing tests for the _image module to prevent such problems in the future.

@kklemon kklemon changed the title Fix regex for matching urls in image function Fix regex for urls in image function Jun 25, 2024
@riedgar-ms
Copy link
Collaborator

Tag @nking-1

@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.43%. Comparing base (4ae2ea6) to head (370c830).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #928      +/-   ##
==========================================
+ Coverage   56.43%   61.43%   +4.99%     
==========================================
  Files          63       63              
  Lines        4791     4792       +1     
==========================================
+ Hits         2704     2944     +240     
+ Misses       2087     1848     -239     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@nking-1
Copy link
Contributor

nking-1 commented Jul 8, 2024

This looks like a solid fix with tests. We'll probably be changing the internals of how images are stored and serialized in the model, but at a high level it shouldn't impact the fixes here. I think we can go ahead and take this change, and if any further work is needed I can do it as part of the upcoming multimodal support feature

@riedgar-ms
Copy link
Collaborator

@kklemon , I think you may be hitting this issue in the tests:
https://stackoverflow.com/questions/6416782/what-is-namedtemporaryfile-useful-for-on-windows
It may be simpler to create a temporary directory within the test fixture, and yield that. Then create the image as a regular file within that.

@riedgar-ms riedgar-ms changed the title Fix regex for urls in image function [Bug] Fix regex for urls in image function Jul 12, 2024
@riedgar-ms riedgar-ms merged commit 052d1f5 into guidance-ai:main Jul 12, 2024
104 checks passed
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.

4 participants