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

Minor fix and improvement #165

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions vision_agent/utils/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def __init__(self, is_main_result: bool, data: Dict[str, Any]):
self.raw = copy.deepcopy(data)

self.text = data.pop(MimeType.TEXT_PLAIN, None)
if self.text and (self.text.startswith("'") and self.text.endswith("'")):
# This is a workaround for the issue that str result is wrapped with single quotes by notebook.
# E.g. input text: "'flower'". what we want: "flower"
self.text = self.text[1:-1]

self.html = data.pop(MimeType.TEXT_HTML, None)
self.markdown = data.pop(MimeType.TEXT_MARKDOWN, None)
self.svg = data.pop(MimeType.IMAGE_SVG, None)
Expand Down
8 changes: 3 additions & 5 deletions vision_agent/utils/sim.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from functools import lru_cache
from pathlib import Path
from typing import Dict, List, Optional, Sequence, Union

Expand Down Expand Up @@ -33,11 +34,7 @@ def __init__(
model: str: The model to use for embeddings.
"""
self.df = df
if not api_key:
self.client = OpenAI()
else:
self.client = OpenAI(api_key=api_key)

self.client = OpenAI(api_key=api_key)
self.model = model
if "embs" not in df.columns and sim_key is None:
raise ValueError("key is required if no column 'embs' is present.")
Expand All @@ -57,6 +54,7 @@ def save(self, sim_file: Union[str, Path]) -> None:
df = df.drop("embs", axis=1)
df.to_csv(sim_file / "df.csv", index=False)

@lru_cache(maxsize=256)
def top_k(
self, query: str, k: int = 5, thresh: Optional[float] = None
) -> Sequence[Dict]:
Expand Down
Loading