vision-agent 0.2.193__py3-none-any.whl → 0.2.195__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- vision_agent/.sim_tools/df.csv +640 -0
- vision_agent/.sim_tools/embs.npy +0 -0
- vision_agent/agent/__init__.py +2 -0
- vision_agent/agent/agent_utils.py +211 -3
- vision_agent/agent/vision_agent_coder.py +5 -113
- vision_agent/agent/vision_agent_coder_prompts_v2.py +119 -0
- vision_agent/agent/vision_agent_coder_v2.py +341 -0
- vision_agent/agent/vision_agent_planner.py +2 -2
- vision_agent/agent/vision_agent_planner_prompts.py +1 -1
- vision_agent/agent/vision_agent_planner_prompts_v2.py +748 -0
- vision_agent/agent/vision_agent_planner_v2.py +432 -0
- vision_agent/lmm/lmm.py +4 -0
- vision_agent/tools/__init__.py +2 -1
- vision_agent/tools/planner_tools.py +246 -0
- vision_agent/tools/tool_utils.py +65 -1
- vision_agent/tools/tools.py +76 -22
- vision_agent/utils/image_utils.py +12 -6
- vision_agent/utils/sim.py +65 -14
- {vision_agent-0.2.193.dist-info → vision_agent-0.2.195.dist-info}/METADATA +1 -1
- vision_agent-0.2.195.dist-info/RECORD +42 -0
- vision_agent-0.2.193.dist-info/RECORD +0 -35
- {vision_agent-0.2.193.dist-info → vision_agent-0.2.195.dist-info}/LICENSE +0 -0
- {vision_agent-0.2.193.dist-info → vision_agent-0.2.195.dist-info}/WHEEL +0 -0
vision_agent/utils/sim.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
import os
|
2
|
+
import platform
|
3
|
+
import shutil
|
2
4
|
from functools import lru_cache
|
5
|
+
from importlib import resources
|
3
6
|
from pathlib import Path
|
4
7
|
from typing import Callable, Dict, List, Optional, Sequence, Union
|
5
8
|
|
@@ -18,6 +21,23 @@ def get_embedding(
|
|
18
21
|
return emb_call([text])
|
19
22
|
|
20
23
|
|
24
|
+
def load_cached_sim(
|
25
|
+
tools_df: pd.DataFrame, sim_key: str = "desc", cached_dir: str = ".sim_tools"
|
26
|
+
) -> "Sim":
|
27
|
+
cached_dir_full_path = str(resources.files("vision_agent") / cached_dir)
|
28
|
+
if os.path.exists(cached_dir_full_path):
|
29
|
+
if tools_df is not None:
|
30
|
+
if Sim.check_load(cached_dir_full_path, tools_df):
|
31
|
+
# don't pass sim_key to loaded Sim object or else it will re-calculate embeddings
|
32
|
+
return Sim.load(cached_dir_full_path)
|
33
|
+
if os.path.exists(cached_dir_full_path):
|
34
|
+
shutil.rmtree(cached_dir_full_path)
|
35
|
+
|
36
|
+
sim = Sim(tools_df, sim_key=sim_key)
|
37
|
+
sim.save(cached_dir_full_path)
|
38
|
+
return sim
|
39
|
+
|
40
|
+
|
21
41
|
class Sim:
|
22
42
|
def __init__(
|
23
43
|
self,
|
@@ -33,33 +53,59 @@ class Sim:
|
|
33
53
|
df: pd.DataFrame: The dataframe to use for similarity.
|
34
54
|
sim_key: Optional[str]: The column name that you want to use to construct
|
35
55
|
the embeddings.
|
36
|
-
|
56
|
+
api_key: Optional[str]: The OpenAI API key to use for embeddings.
|
57
|
+
model: str: The model to use for embeddingshttps://github.com/landing-ai/vision-agent/pull/280.
|
37
58
|
"""
|
38
59
|
self.df = df
|
39
|
-
client = OpenAI(api_key=api_key)
|
40
|
-
self.emb_call = (
|
41
|
-
lambda text: client.embeddings.create(input=text, model=model)
|
42
|
-
.data[0]
|
43
|
-
.embedding
|
44
|
-
)
|
60
|
+
self.client = OpenAI(api_key=api_key)
|
45
61
|
self.model = model
|
46
62
|
if "embs" not in df.columns and sim_key is None:
|
47
63
|
raise ValueError("key is required if no column 'embs' is present.")
|
48
64
|
|
49
65
|
if sim_key is not None:
|
50
66
|
self.df["embs"] = self.df[sim_key].apply(
|
51
|
-
lambda x: get_embedding(
|
67
|
+
lambda x: get_embedding(
|
68
|
+
lambda text: self.client.embeddings.create(
|
69
|
+
input=text, model=self.model
|
70
|
+
)
|
71
|
+
.data[0]
|
72
|
+
.embedding,
|
73
|
+
x,
|
74
|
+
)
|
52
75
|
)
|
53
76
|
|
54
|
-
def save(self,
|
55
|
-
|
56
|
-
|
77
|
+
def save(self, save_dir: Union[str, Path]) -> None:
|
78
|
+
save_dir = Path(save_dir)
|
79
|
+
save_dir.mkdir(parents=True, exist_ok=True)
|
57
80
|
|
58
81
|
df = self.df.copy()
|
59
82
|
embs = np.array(df.embs.tolist())
|
60
|
-
np.save(
|
83
|
+
np.save(save_dir / "embs.npy", embs)
|
61
84
|
df = df.drop("embs", axis=1)
|
62
|
-
df.to_csv(
|
85
|
+
df.to_csv(save_dir / "df.csv", index=False)
|
86
|
+
|
87
|
+
@staticmethod
|
88
|
+
def load(
|
89
|
+
load_dir: Union[str, Path],
|
90
|
+
api_key: Optional[str] = None,
|
91
|
+
model: str = "text-embedding-3-small",
|
92
|
+
) -> "Sim":
|
93
|
+
load_dir = Path(load_dir)
|
94
|
+
df = pd.read_csv(load_dir / "df.csv")
|
95
|
+
embs = np.load(load_dir / "embs.npy")
|
96
|
+
df["embs"] = list(embs)
|
97
|
+
return Sim(df, api_key=api_key, model=model)
|
98
|
+
|
99
|
+
@staticmethod
|
100
|
+
def check_load(
|
101
|
+
load_dir: Union[str, Path],
|
102
|
+
df: pd.DataFrame,
|
103
|
+
) -> bool:
|
104
|
+
load_dir = Path(load_dir)
|
105
|
+
df_load = pd.read_csv(load_dir / "df.csv")
|
106
|
+
if platform.system() == "Windows":
|
107
|
+
df_load["doc"] = df_load["doc"].apply(lambda x: x.replace("\r", ""))
|
108
|
+
return df.equals(df_load) # type: ignore
|
63
109
|
|
64
110
|
@lru_cache(maxsize=256)
|
65
111
|
def top_k(
|
@@ -76,7 +122,12 @@ class Sim:
|
|
76
122
|
Sequence[Dict]: The top k most similar items.
|
77
123
|
"""
|
78
124
|
|
79
|
-
embedding = get_embedding(
|
125
|
+
embedding = get_embedding(
|
126
|
+
lambda text: self.client.embeddings.create(input=text, model=self.model)
|
127
|
+
.data[0]
|
128
|
+
.embedding,
|
129
|
+
query,
|
130
|
+
)
|
80
131
|
self.df["sim"] = self.df.embs.apply(lambda x: 1 - cosine(x, embedding))
|
81
132
|
res = self.df.sort_values("sim", ascending=False).head(k)
|
82
133
|
if thresh is not None:
|
@@ -0,0 +1,42 @@
|
|
1
|
+
vision_agent/.sim_tools/df.csv,sha256=IPYWrI8W8r7zs2-QRjGsAzlg1O3wqngGRSyz9F-BOpo,34008
|
2
|
+
vision_agent/.sim_tools/embs.npy,sha256=ItJgcBpT0--0HeZjUV30INzFXNQh-12HoUVevNY38dc,356480
|
3
|
+
vision_agent/__init__.py,sha256=EAb4-f9iyuEYkBrX4ag1syM8Syx8118_t0R6_C34M9w,57
|
4
|
+
vision_agent/agent/__init__.py,sha256=j4W3zHXKE96o93ZziY62ZBWgicLYEink1rIU3gPsfwM,548
|
5
|
+
vision_agent/agent/agent.py,sha256=2cjIOxEuSJrqbfPXYoV0qER5ihXsPFCoEFJa4jpqan0,597
|
6
|
+
vision_agent/agent/agent_utils.py,sha256=jDkvanBsT_ZH7MnPWP_Wa_ToPOy4hdy4kTw9FZytwwo,12765
|
7
|
+
vision_agent/agent/vision_agent.py,sha256=rr1P9iTbr7OsjgMYWCeIxQYI4cLwPWia3NIMJNi-9Yo,26110
|
8
|
+
vision_agent/agent/vision_agent_coder.py,sha256=waCmw_NTgsy9G-UqlRZFhsFJJVuWVrjxVnShe4Xp_lI,27743
|
9
|
+
vision_agent/agent/vision_agent_coder_prompts.py,sha256=gPLVXQMNSzYnQYpNm0wlH_5FPkOTaFDV24bqzK3jQ40,12221
|
10
|
+
vision_agent/agent/vision_agent_coder_prompts_v2.py,sha256=9v5HwbNidSzYUEFl6ZMniWWOmyLITM_moWLtKVaTen8,4845
|
11
|
+
vision_agent/agent/vision_agent_coder_v2.py,sha256=LVV5Ij-2s03Cj27VJZI11dMKios8ALYZ4_mZTpeMDJU,10863
|
12
|
+
vision_agent/agent/vision_agent_planner.py,sha256=F_5opnc0XmQmNH40rs2T7DFrai4CC6aDYe02Z8e93AM,18875
|
13
|
+
vision_agent/agent/vision_agent_planner_prompts.py,sha256=Y3jz9HRf8fz9NLUseN7cTgZqewP0RazxR7vw1sPhcn0,6691
|
14
|
+
vision_agent/agent/vision_agent_planner_prompts_v2.py,sha256=PrihfrkxbeVQNzR2Vu3UwG_PRjFsjoC9IQko3WfUqPM,33143
|
15
|
+
vision_agent/agent/vision_agent_planner_v2.py,sha256=11pCfaXXsivV9DKWI7nDcLf5dJV3IyHX0IR4Zn7UC9E,14288
|
16
|
+
vision_agent/agent/vision_agent_prompts.py,sha256=4329ll0kqCznRALIMl-rlKWGjN92p3bcRrz8R-cO744,13748
|
17
|
+
vision_agent/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
+
vision_agent/clients/http.py,sha256=k883i6M_4nl7zwwHSI-yP5sAgQZIDPM1nrKD6YFJ3Xs,2009
|
19
|
+
vision_agent/clients/landing_public_api.py,sha256=lU2ev6E8NICmR8DMUljuGcVFy5VNJQ4WQkWC8WnnJEc,1503
|
20
|
+
vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
21
|
+
vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
|
22
|
+
vision_agent/lmm/__init__.py,sha256=jyY1sJb_tYKg5-Wzs3p1lvwFkc-aUNZfMcLy3TOC4Zg,100
|
23
|
+
vision_agent/lmm/lmm.py,sha256=x_nIyDNDZwq4-pfjnJTmcyyJZ2_B7TjkA5jZp88YVO8,17103
|
24
|
+
vision_agent/lmm/types.py,sha256=ZEXR_ptBL0ZwDMTDYkgxUCmSZFmBYPQd2jreNzr_8UY,221
|
25
|
+
vision_agent/tools/__init__.py,sha256=xuNt5e4syQH28Vr6EdjLmO9ni9i00yav9yqcPMUx1oo,2878
|
26
|
+
vision_agent/tools/meta_tools.py,sha256=by7TIbH7lsLIayX_Pe2mS1iw8aeLn2T8yqAo8SkB9Kg,32074
|
27
|
+
vision_agent/tools/planner_tools.py,sha256=FROahw_6Taqvytv6pOjCHUEypOfjsi_f8Vo1c5vz6Mw,8823
|
28
|
+
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
29
|
+
vision_agent/tools/tool_utils.py,sha256=GDGOmBCo4UfYz-DJ-olREJHPsqs5mzHu0YXiAnpNE8E,10179
|
30
|
+
vision_agent/tools/tools.py,sha256=Q8QSuOUk0df_XueU856vi21GOolp2TB3_f0WvMayjIA,87835
|
31
|
+
vision_agent/tools/tools_types.py,sha256=8hYf2OZhI58gvf65KGaeGkt4EQ56nwLFqIQDPHioOBc,2339
|
32
|
+
vision_agent/utils/__init__.py,sha256=7fMgbZiEwbNS0fBOS_hJI5PuEYBblw36zLi_UjUzvj4,244
|
33
|
+
vision_agent/utils/exceptions.py,sha256=booSPSuoULF7OXRr_YbC4dtKt6gM_HyiFQHBuaW86C4,2052
|
34
|
+
vision_agent/utils/execute.py,sha256=2sIQn45llOENMyrKu3TPINVRLLbOvvZ6SVHFCB9MQUo,28028
|
35
|
+
vision_agent/utils/image_utils.py,sha256=rRWcxKggPXIRXIY_XT9rZt30ECDRq8zq7FDeXRDqQWs,11679
|
36
|
+
vision_agent/utils/sim.py,sha256=NZc9QGD6BTY5O29NVbHH7oxDePL_QMnylT1lYcDUn1Y,7437
|
37
|
+
vision_agent/utils/type_defs.py,sha256=BE12s3JNQy36QvauXHjwyeffVh5enfcvd4vTzSwvEZI,1384
|
38
|
+
vision_agent/utils/video.py,sha256=tRcGp4vEnaDycigL1hBO9k0FBPtDH35fCQciVr9GqYI,6013
|
39
|
+
vision_agent-0.2.195.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
40
|
+
vision_agent-0.2.195.dist-info/METADATA,sha256=5knYFtzYGyiX2wM-Fcchul12P7bZDh2YVl5XoQYkZkI,18067
|
41
|
+
vision_agent-0.2.195.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
42
|
+
vision_agent-0.2.195.dist-info/RECORD,,
|
@@ -1,35 +0,0 @@
|
|
1
|
-
vision_agent/__init__.py,sha256=EAb4-f9iyuEYkBrX4ag1syM8Syx8118_t0R6_C34M9w,57
|
2
|
-
vision_agent/agent/__init__.py,sha256=RRMPhH8mgm_pCtEKiVFSjJyDi4lCr4F7k05AhK01xlM,436
|
3
|
-
vision_agent/agent/agent.py,sha256=2cjIOxEuSJrqbfPXYoV0qER5ihXsPFCoEFJa4jpqan0,597
|
4
|
-
vision_agent/agent/agent_utils.py,sha256=WYJF11PfKXlRMPnogGz3s7c2TlWoxoGzuLiIptVYE1s,5524
|
5
|
-
vision_agent/agent/vision_agent.py,sha256=rr1P9iTbr7OsjgMYWCeIxQYI4cLwPWia3NIMJNi-9Yo,26110
|
6
|
-
vision_agent/agent/vision_agent_coder.py,sha256=7Ko1c41dvdDbSP_Yw2yz_SlE3sO6hhlpf_oCjW0we2w,31749
|
7
|
-
vision_agent/agent/vision_agent_coder_prompts.py,sha256=gPLVXQMNSzYnQYpNm0wlH_5FPkOTaFDV24bqzK3jQ40,12221
|
8
|
-
vision_agent/agent/vision_agent_planner.py,sha256=Hy4vKiae7zIIKVPgLetGArbsjGRNVOXlxY9xhFgW-A0,18871
|
9
|
-
vision_agent/agent/vision_agent_planner_prompts.py,sha256=JDARUzko2HZdxkBtcy6wuP9DCCmbqhK_gnVgrjr6l1k,6691
|
10
|
-
vision_agent/agent/vision_agent_prompts.py,sha256=4329ll0kqCznRALIMl-rlKWGjN92p3bcRrz8R-cO744,13748
|
11
|
-
vision_agent/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
12
|
-
vision_agent/clients/http.py,sha256=k883i6M_4nl7zwwHSI-yP5sAgQZIDPM1nrKD6YFJ3Xs,2009
|
13
|
-
vision_agent/clients/landing_public_api.py,sha256=lU2ev6E8NICmR8DMUljuGcVFy5VNJQ4WQkWC8WnnJEc,1503
|
14
|
-
vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
15
|
-
vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
|
16
|
-
vision_agent/lmm/__init__.py,sha256=jyY1sJb_tYKg5-Wzs3p1lvwFkc-aUNZfMcLy3TOC4Zg,100
|
17
|
-
vision_agent/lmm/lmm.py,sha256=B5ClgwvbybVCWkf9opDMLjTtJZemUU4KUkQoRxGh43I,16787
|
18
|
-
vision_agent/lmm/types.py,sha256=ZEXR_ptBL0ZwDMTDYkgxUCmSZFmBYPQd2jreNzr_8UY,221
|
19
|
-
vision_agent/tools/__init__.py,sha256=UrpGFB1ACOZZCAyj8vNw0IHhKm9wGp0qHOtci2cqAMU,2825
|
20
|
-
vision_agent/tools/meta_tools.py,sha256=by7TIbH7lsLIayX_Pe2mS1iw8aeLn2T8yqAo8SkB9Kg,32074
|
21
|
-
vision_agent/tools/prompts.py,sha256=V1z4YJLXZuUl_iZ5rY0M5hHc_2tmMEUKr0WocXKGt4E,1430
|
22
|
-
vision_agent/tools/tool_utils.py,sha256=VPGqGJ2ZYEJA6AW7K9X7hQv6vRlMtAQcybE4izdToCw,8196
|
23
|
-
vision_agent/tools/tools.py,sha256=gV9z8jE38JVXhIMCwmBZU1TKM16KlwAk48ZBAV0t1w8,85728
|
24
|
-
vision_agent/tools/tools_types.py,sha256=8hYf2OZhI58gvf65KGaeGkt4EQ56nwLFqIQDPHioOBc,2339
|
25
|
-
vision_agent/utils/__init__.py,sha256=7fMgbZiEwbNS0fBOS_hJI5PuEYBblw36zLi_UjUzvj4,244
|
26
|
-
vision_agent/utils/exceptions.py,sha256=booSPSuoULF7OXRr_YbC4dtKt6gM_HyiFQHBuaW86C4,2052
|
27
|
-
vision_agent/utils/execute.py,sha256=2sIQn45llOENMyrKu3TPINVRLLbOvvZ6SVHFCB9MQUo,28028
|
28
|
-
vision_agent/utils/image_utils.py,sha256=rm9GfXvD4JrjnqKrP_f2gfq4SzmqYC0IdC1kKwdn6sk,11303
|
29
|
-
vision_agent/utils/sim.py,sha256=ZuSS07TUXFGjipmiQoY8TKRmSes7XXCdtU9PI8PC1sw,5609
|
30
|
-
vision_agent/utils/type_defs.py,sha256=BE12s3JNQy36QvauXHjwyeffVh5enfcvd4vTzSwvEZI,1384
|
31
|
-
vision_agent/utils/video.py,sha256=tRcGp4vEnaDycigL1hBO9k0FBPtDH35fCQciVr9GqYI,6013
|
32
|
-
vision_agent-0.2.193.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
33
|
-
vision_agent-0.2.193.dist-info/METADATA,sha256=uDs9o-Lu4tU1jftsh-XQlcRJXyunc6VyPEoVAArGC7c,18067
|
34
|
-
vision_agent-0.2.193.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
35
|
-
vision_agent-0.2.193.dist-info/RECORD,,
|
File without changes
|
File without changes
|