botrun-flow-lang 5.10.82__py3-none-any.whl → 5.10.131__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- botrun_flow_lang/langgraph_agents/agents/langgraph_react_agent.py +91 -42
- {botrun_flow_lang-5.10.82.dist-info → botrun_flow_lang-5.10.131.dist-info}/METADATA +3 -2
- {botrun_flow_lang-5.10.82.dist-info → botrun_flow_lang-5.10.131.dist-info}/RECORD +4 -4
- {botrun_flow_lang-5.10.82.dist-info → botrun_flow_lang-5.10.131.dist-info}/WHEEL +0 -0
|
@@ -83,6 +83,11 @@ from langchain_anthropic import ChatAnthropic
|
|
|
83
83
|
from langchain.tools import StructuredTool # 或 langchain_core.tools
|
|
84
84
|
from langchain_mcp_adapters.client import MultiServerMCPClient
|
|
85
85
|
|
|
86
|
+
# ========
|
|
87
|
+
# for Vertex AI
|
|
88
|
+
from google.oauth2 import service_account
|
|
89
|
+
from langchain_google_vertexai.model_garden import ChatAnthropicVertex
|
|
90
|
+
|
|
86
91
|
load_dotenv()
|
|
87
92
|
|
|
88
93
|
# logger = default_logger
|
|
@@ -135,61 +140,105 @@ def get_react_agent_model_name(model_name: str = ""):
|
|
|
135
140
|
|
|
136
141
|
|
|
137
142
|
ANTHROPIC_MAX_TOKENS = 64000
|
|
143
|
+
GEMINI_MAX_TOKENS = 32000
|
|
138
144
|
|
|
139
145
|
|
|
140
146
|
def get_react_agent_model(model_name: str = ""):
|
|
141
147
|
final_model_name = get_react_agent_model_name(model_name)
|
|
142
148
|
if final_model_name.startswith("gemini-"):
|
|
143
|
-
|
|
144
|
-
|
|
149
|
+
model = ChatGoogleGenerativeAI(
|
|
150
|
+
model=final_model_name, temperature=0, max_tokens=GEMINI_MAX_TOKENS
|
|
151
|
+
)
|
|
145
152
|
logger.info(f"model ChatGoogleGenerativeAI {final_model_name}")
|
|
146
153
|
elif final_model_name.startswith("claude-"):
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
154
|
+
# use_vertex_ai = os.getenv("USE_VERTEX_AI", "false").lower() in ("true", "1", "yes")
|
|
155
|
+
vertex_location = os.getenv("VERTEX_AI_LANGCHAIN_LOCATION", "")
|
|
156
|
+
vertex_model = os.getenv("VERTEX_AI_LANGCHAIN_MODEL", "")
|
|
157
|
+
vertex_sa_path = os.getenv(
|
|
158
|
+
"VERTEX_AI_LANGCHAIN_GOOGLE_APPLICATION_CREDENTIALS", ""
|
|
159
|
+
)
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
161
|
+
if vertex_location and vertex_model and vertex_sa_path:
|
|
162
|
+
# 從環境變數讀取設定
|
|
163
|
+
|
|
164
|
+
# 驗證 service account
|
|
165
|
+
credentials = None
|
|
166
|
+
if vertex_sa_path and os.path.exists(vertex_sa_path):
|
|
167
|
+
# 加入 Vertex AI 需要的 scopes
|
|
168
|
+
SCOPES = [
|
|
169
|
+
"https://www.googleapis.com/auth/cloud-platform",
|
|
170
|
+
"https://www.googleapis.com/auth/cloudplatformprojects.readonly",
|
|
171
|
+
]
|
|
172
|
+
credentials = service_account.Credentials.from_service_account_file(
|
|
173
|
+
vertex_sa_path, scopes=SCOPES
|
|
174
|
+
)
|
|
175
|
+
logger.info(f"Using Vertex AI service account from {vertex_sa_path}")
|
|
176
|
+
else:
|
|
177
|
+
logger.warning(
|
|
178
|
+
"VERTEX_AI_GOOGLE_APPLICATION_CREDENTIALS not set or file not found. Using ADC if available."
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
# 初始化 ChatAnthropicVertex
|
|
182
|
+
model = ChatAnthropicVertex(
|
|
183
|
+
model=vertex_model,
|
|
184
|
+
location=vertex_location,
|
|
185
|
+
credentials=credentials,
|
|
169
186
|
temperature=0,
|
|
170
187
|
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
171
|
-
model_kwargs={
|
|
172
|
-
# "headers": {
|
|
173
|
-
# "HTTP-Referer": getenv("YOUR_SITE_URL"),
|
|
174
|
-
# "X-Title": getenv("YOUR_SITE_NAME"),
|
|
175
|
-
# }
|
|
176
|
-
},
|
|
177
188
|
)
|
|
178
|
-
logger.info(f"model
|
|
189
|
+
logger.info(f"model ChatAnthropicVertex {vertex_model} @ {vertex_location}")
|
|
190
|
+
|
|
179
191
|
else:
|
|
192
|
+
anthropic_api_keys_str = os.getenv("ANTHROPIC_API_KEYS", "")
|
|
193
|
+
anthropic_api_keys = [
|
|
194
|
+
key.strip() for key in anthropic_api_keys_str.split(",") if key.strip()
|
|
195
|
+
]
|
|
196
|
+
if anthropic_api_keys:
|
|
197
|
+
|
|
198
|
+
model = RotatingChatAnthropic(
|
|
199
|
+
model_name=final_model_name,
|
|
200
|
+
keys=anthropic_api_keys,
|
|
201
|
+
temperature=0,
|
|
202
|
+
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
203
|
+
)
|
|
204
|
+
logger.info(f"model RotatingChatAnthropic {final_model_name}")
|
|
205
|
+
elif os.getenv("OPENROUTER_API_KEY") and os.getenv("OPENROUTER_BASE_URL"):
|
|
206
|
+
|
|
207
|
+
openrouter_model_name = "anthropic/claude-sonnet-4.5"
|
|
208
|
+
# openrouter_model_name = "openai/o4-mini-high"
|
|
209
|
+
# openrouter_model_name = "openai/gpt-4.1"
|
|
210
|
+
model = ChatOpenAI(
|
|
211
|
+
openai_api_key=os.getenv("OPENROUTER_API_KEY"),
|
|
212
|
+
openai_api_base=os.getenv("OPENROUTER_BASE_URL"),
|
|
213
|
+
model_name=openrouter_model_name,
|
|
214
|
+
temperature=0,
|
|
215
|
+
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
216
|
+
model_kwargs={
|
|
217
|
+
# "headers": {
|
|
218
|
+
# "HTTP-Referer": getenv("YOUR_SITE_URL"),
|
|
219
|
+
# "X-Title": getenv("YOUR_SITE_NAME"),
|
|
220
|
+
# }
|
|
221
|
+
},
|
|
222
|
+
)
|
|
223
|
+
logger.info(f"model OpenRouter {openrouter_model_name}")
|
|
224
|
+
else:
|
|
225
|
+
|
|
226
|
+
model = ChatAnthropic(
|
|
227
|
+
model=final_model_name,
|
|
228
|
+
temperature=0,
|
|
229
|
+
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
230
|
+
# model_kwargs={
|
|
231
|
+
# "extra_headers": {
|
|
232
|
+
# "anthropic-beta": "token-efficient-tools-2025-02-19",
|
|
233
|
+
# "anthropic-beta": "output-128k-2025-02-19",
|
|
234
|
+
# }
|
|
235
|
+
# },
|
|
236
|
+
)
|
|
237
|
+
logger.info(f"model ChatAnthropic {final_model_name}")
|
|
238
|
+
|
|
239
|
+
else:
|
|
240
|
+
raise ValueError(f"Unknown model name prefix: {final_model_name}")
|
|
180
241
|
|
|
181
|
-
model = ChatAnthropic(
|
|
182
|
-
model=final_model_name,
|
|
183
|
-
temperature=0,
|
|
184
|
-
max_tokens=ANTHROPIC_MAX_TOKENS,
|
|
185
|
-
# model_kwargs={
|
|
186
|
-
# "extra_headers": {
|
|
187
|
-
# "anthropic-beta": "token-efficient-tools-2025-02-19",
|
|
188
|
-
# "anthropic-beta": "output-128k-2025-02-19",
|
|
189
|
-
# }
|
|
190
|
-
# },
|
|
191
|
-
)
|
|
192
|
-
logger.info(f"model ChatAnthropic {final_model_name}")
|
|
193
242
|
return model
|
|
194
243
|
|
|
195
244
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: botrun-flow-lang
|
|
3
|
-
Version: 5.10.
|
|
3
|
+
Version: 5.10.131
|
|
4
4
|
Summary: A flow language for botrun
|
|
5
5
|
Author-email: sebastian-hsu <sebastian.hsu@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -23,7 +23,7 @@ Requires-Dist: google-auth>=2.40.3
|
|
|
23
23
|
Requires-Dist: google-cloud-discoveryengine>=0.13.3
|
|
24
24
|
Requires-Dist: google-cloud-firestore>=2.21.0
|
|
25
25
|
Requires-Dist: google-cloud-logging>=3.11.4
|
|
26
|
-
Requires-Dist: google-cloud-storage
|
|
26
|
+
Requires-Dist: google-cloud-storage<3,>=2.18
|
|
27
27
|
Requires-Dist: google-genai>=1.28.0
|
|
28
28
|
Requires-Dist: jinja2>=3.1.6
|
|
29
29
|
Requires-Dist: langchain-anthropic>=0.3.10
|
|
@@ -32,6 +32,7 @@ Requires-Dist: langchain-community>=0.3.27
|
|
|
32
32
|
Requires-Dist: langchain-core>=0.3.72
|
|
33
33
|
Requires-Dist: langchain-google-community>=2.0.3
|
|
34
34
|
Requires-Dist: langchain-google-genai>=2.0.9
|
|
35
|
+
Requires-Dist: langchain-google-vertexai<3.0.0,>=2.1.2
|
|
35
36
|
Requires-Dist: langchain-mcp-adapters>=0.1.7
|
|
36
37
|
Requires-Dist: langchain-openai>=0.3.28
|
|
37
38
|
Requires-Dist: langchain>=0.3.27
|
|
@@ -24,7 +24,7 @@ botrun_flow_lang/api/youtube_api.py,sha256=R384jNRheMKnDyzvlLnbzackipZhiLYTZl4w4
|
|
|
24
24
|
botrun_flow_lang/langgraph_agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
25
25
|
botrun_flow_lang/langgraph_agents/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
26
|
botrun_flow_lang/langgraph_agents/agents/agent_runner.py,sha256=fOZgHDsCA_EDTTGQFBmhGUhpfLB3m_N6YW2UHgMpKBg,6241
|
|
27
|
-
botrun_flow_lang/langgraph_agents/agents/langgraph_react_agent.py,sha256=
|
|
27
|
+
botrun_flow_lang/langgraph_agents/agents/langgraph_react_agent.py,sha256=vkx9BeV0QvlTxn9zTQrnVGiPd0HQyfEITfy1YkoEAMI,24869
|
|
28
28
|
botrun_flow_lang/langgraph_agents/agents/search_agent_graph.py,sha256=6fz-ewLQGacEx-uqGfF3-go9FdiioiMzW_sfANzYTcI,31182
|
|
29
29
|
botrun_flow_lang/langgraph_agents/agents/agent_tools/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
30
|
botrun_flow_lang/langgraph_agents/agents/agent_tools/step_planner.py,sha256=CgEhfGR28Rq7ui9cKxj_DczfNfjJNXIP9DXQNIwBLv0,2350
|
|
@@ -94,6 +94,6 @@ botrun_flow_lang/utils/yaml_utils.py,sha256=1A6PSEE8TM0HSD_6l-fhUsjYnXJcrEKuPgot
|
|
|
94
94
|
botrun_flow_lang/utils/clients/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
95
95
|
botrun_flow_lang/utils/clients/rate_limit_client.py,sha256=TRpA56OKrfYsoLoJ-TPYlC7Znp9s267-u6CX6BLyVko,8349
|
|
96
96
|
botrun_flow_lang/utils/clients/token_verify_client.py,sha256=BtrfLvMe-DtS8UKeDhaIkVKDZHphZVP7kyqXn9jhXEc,5740
|
|
97
|
-
botrun_flow_lang-5.10.
|
|
98
|
-
botrun_flow_lang-5.10.
|
|
99
|
-
botrun_flow_lang-5.10.
|
|
97
|
+
botrun_flow_lang-5.10.131.dist-info/METADATA,sha256=5tQGiu-lOzSlJqIvClnHhUACGT8gxaUysLlNIKxLWFY,6420
|
|
98
|
+
botrun_flow_lang-5.10.131.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
99
|
+
botrun_flow_lang-5.10.131.dist-info/RECORD,,
|
|
File without changes
|