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

Limit number of frames sent to reflection #64

Merged
merged 4 commits into from
Apr 25, 2024
Merged
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion vision_agent/agent/vision_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,19 @@ def _handle_viz_tools(
return image_to_data


def sample_n_evenly_spaced(lst: Sequence, n: int) -> Sequence:
shankar-vision-eng marked this conversation as resolved.
Show resolved Hide resolved
if n <= 0:
return []

if len(lst) <= n:
return lst

interval = len(lst) // n if len(lst) % 2 == 0 else len(lst) // n + 1
indices = list(range(len(lst)))
picked_indices = sorted([indices[(i * interval) % len(lst)] for i in range(n)])
return [lst[i] for i in picked_indices]


dillonalaird marked this conversation as resolved.
Show resolved Hide resolved
def visualize_result(all_tool_results: List[Dict]) -> Sequence[Union[str, Path]]:
image_to_data: Dict[str, Dict] = {}
for tool_result in all_tool_results:
Expand Down Expand Up @@ -584,7 +597,7 @@ def chat_with_workflow(
visualized_output = visualize_result(all_tool_results)
all_tool_results.append({"visualized_output": visualized_output})
if len(visualized_output) > 0:
reflection_images = visualized_output
reflection_images = sample_n_evenly_spaced(visualized_output, 3)
elif image is not None:
reflection_images = [image]
else:
Expand Down
Loading