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

fix: fine tune multiple times should edit original id #249

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions vision_agent/tools/meta_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,23 @@ def use_object_detection_fine_tuning(
return output_str

code = artifacts[name]
patterns = [

patterns_with_fine_tune_id = [
(
r'florence2_phrase_grounding\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)',
lambda match: f'florence2_phrase_grounding("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")',
),
(
r'owl_v2_image\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)',
lambda match: f'owl_v2_image("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")',
),
(
r'florence2_sam2_image\(\s*"([^"]+)"\s*,\s*([^,]+)(?:,\s*"[^"]+")?\s*\)',
lambda match: f'florence2_sam2_image("{match.group(1)}", {match.group(2)}, "{fine_tune_id}")',
),
]

patterns_without_fine_tune_id = [
(
r"florence2_phrase_grounding\(\s*([^\)]+)\s*\)",
lambda match: f'florence2_phrase_grounding({match.group(1)}, "{fine_tune_id}")',
Expand All @@ -659,8 +675,21 @@ def use_object_detection_fine_tuning(
]

new_code = code
for pattern, replacer in patterns:
new_code = re.sub(pattern, replacer, new_code)

for index, (pattern_with_fine_tune_id, replacer_with_fine_tune_id) in enumerate(
patterns_with_fine_tune_id
):
if re.search(pattern_with_fine_tune_id, new_code):
new_code = re.sub(
pattern_with_fine_tune_id, replacer_with_fine_tune_id, new_code
)
else:
(pattern_without_fine_tune_id, replacer_without_fine_tune_id) = (
patterns_without_fine_tune_id[index]
yzld2002 marked this conversation as resolved.
Show resolved Hide resolved
)
new_code = re.sub(
pattern_without_fine_tune_id, replacer_without_fine_tune_id, new_code
)

if new_code == code:
output_str = (
Expand Down
Loading