blaxel 0.2.31__py3-none-any.whl → 0.2.31rc120__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.
- blaxel/__init__.py +3 -3
- blaxel/core/agents/__init__.py +6 -13
- blaxel/core/authentication/__init__.py +1 -2
- blaxel/core/authentication/devicemode.py +1 -9
- blaxel/core/authentication/oauth.py +6 -13
- blaxel/core/authentication/types.py +0 -1
- blaxel/core/cache/cache.py +3 -10
- blaxel/core/client/api/agents/list_agent_revisions.py +1 -3
- blaxel/core/client/api/compute/delete_sandbox_preview_token.py +2 -6
- blaxel/core/client/api/compute/start_sandbox.py +1 -3
- blaxel/core/client/api/compute/stop_sandbox.py +1 -3
- blaxel/core/client/api/default/list_sandbox_hub_definitions.py +2 -6
- blaxel/core/client/api/functions/list_function_revisions.py +1 -3
- blaxel/core/client/api/images/cleanup_images.py +1 -3
- blaxel/core/client/api/integrations/list_integration_connections.py +2 -6
- blaxel/core/client/api/invitations/list_all_pending_invitations.py +1 -3
- blaxel/core/client/api/jobs/create_job_execution.py +1 -3
- blaxel/core/client/api/jobs/delete_job_execution.py +1 -3
- blaxel/core/client/api/jobs/get_job_execution.py +1 -3
- blaxel/core/client/api/jobs/list_job_executions.py +2 -6
- blaxel/core/client/api/jobs/list_job_revisions.py +1 -3
- blaxel/core/client/api/locations/list_locations.py +1 -3
- blaxel/core/client/api/models/list_model_revisions.py +1 -3
- blaxel/core/client/api/service_accounts/create_workspace_service_account.py +2 -6
- blaxel/core/client/api/service_accounts/delete_workspace_service_account.py +2 -6
- blaxel/core/client/api/service_accounts/get_workspace_service_accounts.py +1 -3
- blaxel/core/client/api/service_accounts/update_workspace_service_account.py +2 -6
- blaxel/core/client/api/volume_templates/list_volume_templates.py +1 -3
- blaxel/core/client/api/workspaces/accept_workspace_invitation.py +2 -6
- blaxel/core/client/api/workspaces/invite_workspace_user.py +2 -6
- blaxel/core/client/api/workspaces/update_workspace_user_role.py +2 -6
- blaxel/core/client/client.py +19 -5
- blaxel/core/client/models/agent.py +4 -11
- blaxel/core/client/models/agent_spec.py +5 -18
- blaxel/core/client/models/billable_time_metric.py +1 -0
- blaxel/core/client/models/configuration.py +1 -0
- blaxel/core/client/models/core_spec.py +3 -10
- blaxel/core/client/models/core_spec_configurations.py +1 -0
- blaxel/core/client/models/create_job_execution_request.py +1 -0
- blaxel/core/client/models/create_job_execution_response.py +1 -0
- blaxel/core/client/models/custom_domain.py +2 -5
- blaxel/core/client/models/custom_domain_metadata.py +1 -0
- blaxel/core/client/models/custom_domain_spec.py +2 -5
- blaxel/core/client/models/delete_volume_template_version_response_200.py +2 -5
- blaxel/core/client/models/entrypoint.py +1 -0
- blaxel/core/client/models/form.py +2 -5
- blaxel/core/client/models/function.py +4 -11
- blaxel/core/client/models/function_spec.py +4 -13
- blaxel/core/client/models/image.py +2 -5
- blaxel/core/client/models/image_spec.py +1 -0
- blaxel/core/client/models/integration.py +3 -10
- blaxel/core/client/models/integration_connection.py +2 -5
- blaxel/core/client/models/integration_connection_spec.py +1 -0
- blaxel/core/client/models/integration_endpoint.py +2 -5
- blaxel/core/client/models/integration_endpoints.py +2 -0
- blaxel/core/client/models/job.py +4 -11
- blaxel/core/client/models/job_execution.py +2 -5
- blaxel/core/client/models/job_execution_spec.py +1 -0
- blaxel/core/client/models/job_execution_task.py +2 -5
- blaxel/core/client/models/job_metrics.py +2 -5
- blaxel/core/client/models/job_spec.py +4 -13
- blaxel/core/client/models/jobs_network_chart.py +1 -0
- blaxel/core/client/models/jobs_success_failed_chart.py +3 -10
- blaxel/core/client/models/latency_metric.py +2 -5
- blaxel/core/client/models/location_response.py +1 -0
- blaxel/core/client/models/mcp_definition.py +2 -5
- blaxel/core/client/models/metadata.py +1 -0
- blaxel/core/client/models/metrics.py +4 -11
- blaxel/core/client/models/model.py +4 -11
- blaxel/core/client/models/model_spec.py +3 -10
- blaxel/core/client/models/pending_invitation_accept.py +2 -5
- blaxel/core/client/models/pending_invitation_render.py +3 -10
- blaxel/core/client/models/policy.py +2 -5
- blaxel/core/client/models/policy_spec.py +4 -11
- blaxel/core/client/models/preview.py +2 -5
- blaxel/core/client/models/preview_spec.py +1 -0
- blaxel/core/client/models/preview_token.py +2 -5
- blaxel/core/client/models/public_ips.py +1 -0
- blaxel/core/client/models/request_duration_over_time_metrics.py +1 -0
- blaxel/core/client/models/request_total_by_origin_metric.py +7 -16
- blaxel/core/client/models/request_total_metric.py +3 -8
- blaxel/core/client/models/resource_metrics.py +17 -58
- blaxel/core/client/models/runtime.py +1 -0
- blaxel/core/client/models/sandbox.py +4 -11
- blaxel/core/client/models/sandbox_definition.py +1 -0
- blaxel/core/client/models/sandbox_lifecycle.py +1 -0
- blaxel/core/client/models/sandbox_spec.py +6 -21
- blaxel/core/client/models/serverless_config.py +1 -0
- blaxel/core/client/models/start_sandbox.py +2 -5
- blaxel/core/client/models/stop_sandbox.py +2 -5
- blaxel/core/client/models/store_agent.py +1 -0
- blaxel/core/client/models/store_configuration.py +1 -0
- blaxel/core/client/models/template.py +1 -0
- blaxel/core/client/models/time_to_first_token_over_time_metrics.py +2 -3
- blaxel/core/client/models/token_rate_metrics.py +1 -0
- blaxel/core/client/models/trigger.py +1 -0
- blaxel/core/client/models/trigger_configuration.py +1 -0
- blaxel/core/client/models/volume.py +4 -11
- blaxel/core/client/models/volume_template.py +2 -5
- blaxel/core/client/models/workspace.py +2 -5
- blaxel/core/client/response_interceptor.py +1 -3
- blaxel/core/common/autoload.py +11 -9
- blaxel/core/common/env.py +8 -10
- blaxel/core/common/settings.py +2 -4
- blaxel/core/common/webhook.py +1 -0
- blaxel/core/jobs/__init__.py +3 -13
- blaxel/core/mcp/client.py +2 -8
- blaxel/core/mcp/server.py +2 -8
- blaxel/core/models/__init__.py +5 -6
- blaxel/core/sandbox/__init__.py +1 -1
- blaxel/core/sandbox/client/api/codegen/get_codegen_reranking_path.py +2 -6
- blaxel/core/sandbox/client/api/fastapply/put_codegen_fastapply_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_multipart_upload_id_abort.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/delete_filesystem_tree_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_content_search_path.py +1 -3
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_find_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/get_filesystem_search_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/get_watch_filesystem_path.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/post_filesystem_multipart_upload_id_complete.py +2 -6
- blaxel/core/sandbox/client/api/filesystem/put_filesystem_path.py +2 -6
- blaxel/core/sandbox/client/api/process/delete_process_identifier.py +2 -6
- blaxel/core/sandbox/client/api/process/delete_process_identifier_kill.py +2 -6
- blaxel/core/sandbox/client/api/process/get_process.py +1 -3
- blaxel/core/sandbox/client/api/process/get_process_identifier.py +2 -6
- blaxel/core/sandbox/client/api/process/get_process_identifier_logs.py +2 -6
- blaxel/core/sandbox/client/api/process/get_process_identifier_logs_stream.py +2 -6
- blaxel/core/sandbox/client/api/process/post_process.py +2 -6
- blaxel/core/sandbox/client/client.py +1 -3
- blaxel/core/sandbox/client/models/filesystem_multipart_upload_parts.py +1 -3
- blaxel/core/sandbox/default/__init__.py +1 -0
- blaxel/core/sandbox/default/action.py +3 -3
- blaxel/core/sandbox/default/codegen.py +4 -2
- blaxel/core/sandbox/default/filesystem.py +82 -38
- blaxel/core/sandbox/default/interpreter.py +10 -17
- blaxel/core/sandbox/default/preview.py +2 -6
- blaxel/core/sandbox/default/process.py +7 -25
- blaxel/core/sandbox/default/sandbox.py +2 -7
- blaxel/core/sandbox/sync/__init__.py +2 -0
- blaxel/core/sandbox/sync/action.py +3 -2
- blaxel/core/sandbox/sync/codegen.py +5 -1
- blaxel/core/sandbox/sync/filesystem.py +6 -17
- blaxel/core/sandbox/sync/interpreter.py +6 -10
- blaxel/core/sandbox/sync/network.py +2 -0
- blaxel/core/sandbox/sync/preview.py +9 -21
- blaxel/core/sandbox/sync/process.py +8 -32
- blaxel/core/sandbox/sync/sandbox.py +6 -13
- blaxel/core/sandbox/sync/session.py +4 -6
- blaxel/core/sandbox/types.py +1 -2
- blaxel/core/tools/__init__.py +6 -30
- blaxel/core/tools/common.py +1 -1
- blaxel/core/tools/types.py +1 -2
- blaxel/crewai/model.py +5 -20
- blaxel/googleadk/__init__.py +1 -1
- blaxel/googleadk/tools.py +5 -3
- blaxel/langgraph/custom/gemini.py +133 -126
- blaxel/langgraph/model.py +50 -54
- blaxel/langgraph/tools.py +3 -9
- blaxel/llamaindex/custom/cohere.py +16 -25
- blaxel/llamaindex/model.py +57 -44
- blaxel/llamaindex/tools.py +3 -2
- blaxel/pydantic/custom/gemini.py +3 -3
- blaxel/pydantic/tools.py +4 -2
- blaxel/telemetry/exporters.py +3 -10
- blaxel/telemetry/instrumentation/blaxel_langgraph.py +2 -4
- blaxel/telemetry/instrumentation/blaxel_langgraph_gemini.py +5 -22
- blaxel/telemetry/instrumentation/utils.py +3 -3
- blaxel/telemetry/log/log.py +3 -2
- blaxel/telemetry/log/logger.py +15 -21
- blaxel/telemetry/span.py +6 -10
- {blaxel-0.2.31.dist-info → blaxel-0.2.31rc120.dist-info}/METADATA +2 -2
- {blaxel-0.2.31.dist-info → blaxel-0.2.31rc120.dist-info}/RECORD +174 -174
- {blaxel-0.2.31.dist-info → blaxel-0.2.31rc120.dist-info}/WHEEL +0 -0
- {blaxel-0.2.31.dist-info → blaxel-0.2.31rc120.dist-info}/licenses/LICENSE +0 -0
blaxel/langgraph/model.py
CHANGED
|
@@ -23,69 +23,70 @@ logger = getLogger(__name__)
|
|
|
23
23
|
|
|
24
24
|
class TokenRefreshingWrapper:
|
|
25
25
|
"""Base wrapper class that refreshes token before each call."""
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
def __init__(self, model_config: dict):
|
|
28
28
|
self.model_config = model_config
|
|
29
29
|
self.wrapped_model = self._create_model()
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
def _create_model(self):
|
|
32
32
|
"""Create the model instance with current token."""
|
|
33
33
|
config = self.model_config
|
|
34
|
-
model_type = config[
|
|
35
|
-
model = config[
|
|
36
|
-
url = config[
|
|
37
|
-
kwargs = config.get(
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
model_type = config['type']
|
|
35
|
+
model = config['model']
|
|
36
|
+
url = config['url']
|
|
37
|
+
kwargs = config.get('kwargs', {})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if model_type == 'mistral':
|
|
40
41
|
return ChatOpenAI(
|
|
41
42
|
api_key=settings.auth.token,
|
|
42
43
|
model=model,
|
|
43
44
|
base_url=f"{url}/v1",
|
|
44
|
-
**kwargs
|
|
45
|
+
**kwargs
|
|
45
46
|
)
|
|
46
|
-
elif model_type ==
|
|
47
|
+
elif model_type == 'cohere':
|
|
47
48
|
return ChatCohere(
|
|
48
49
|
cohere_api_key=settings.auth.token,
|
|
49
50
|
model=model,
|
|
50
51
|
base_url=url,
|
|
51
|
-
**kwargs
|
|
52
|
+
**kwargs
|
|
52
53
|
)
|
|
53
|
-
elif model_type ==
|
|
54
|
+
elif model_type == 'xai':
|
|
54
55
|
return ChatXAI(
|
|
55
56
|
model=model,
|
|
56
57
|
api_key=settings.auth.token,
|
|
57
58
|
xai_api_base=f"{url}/v1",
|
|
58
|
-
**kwargs
|
|
59
|
+
**kwargs
|
|
59
60
|
)
|
|
60
|
-
elif model_type ==
|
|
61
|
+
elif model_type == 'deepseek':
|
|
61
62
|
return ChatDeepSeek(
|
|
62
63
|
api_key=settings.auth.token,
|
|
63
64
|
model=model,
|
|
64
65
|
api_base=f"{url}/v1",
|
|
65
|
-
**kwargs
|
|
66
|
+
**kwargs
|
|
66
67
|
)
|
|
67
|
-
elif model_type ==
|
|
68
|
+
elif model_type == 'anthropic':
|
|
68
69
|
return ChatAnthropic(
|
|
69
70
|
api_key=settings.auth.token,
|
|
70
71
|
anthropic_api_url=url,
|
|
71
72
|
model=model,
|
|
72
73
|
default_headers=settings.auth.get_headers(),
|
|
73
|
-
**kwargs
|
|
74
|
+
**kwargs
|
|
74
75
|
)
|
|
75
|
-
elif model_type ==
|
|
76
|
+
elif model_type == 'gemini':
|
|
76
77
|
return ChatGoogleGenerativeAI(
|
|
77
78
|
model=model,
|
|
78
79
|
client_options={"api_endpoint": url},
|
|
79
80
|
additional_headers=settings.auth.get_headers(),
|
|
80
81
|
transport="rest",
|
|
81
|
-
**kwargs
|
|
82
|
+
**kwargs
|
|
82
83
|
)
|
|
83
84
|
elif model_type == "cerebras":
|
|
84
85
|
return ChatCerebras(
|
|
85
86
|
api_key=settings.auth.token,
|
|
86
87
|
model=model,
|
|
87
88
|
base_url=f"{url}/v1",
|
|
88
|
-
**kwargs
|
|
89
|
+
**kwargs
|
|
89
90
|
)
|
|
90
91
|
else:
|
|
91
92
|
if model_type != "openai":
|
|
@@ -94,24 +95,24 @@ class TokenRefreshingWrapper:
|
|
|
94
95
|
api_key=settings.auth.token,
|
|
95
96
|
model=model,
|
|
96
97
|
base_url=f"{url}/v1",
|
|
97
|
-
**kwargs
|
|
98
|
+
**kwargs
|
|
98
99
|
)
|
|
99
|
-
|
|
100
|
+
|
|
100
101
|
def _refresh_token(self):
|
|
101
102
|
"""Refresh the token and recreate the model if needed."""
|
|
102
103
|
# Only refresh if using ClientCredentials (which has get_token method)
|
|
103
104
|
current_token = settings.auth.token
|
|
104
|
-
|
|
105
|
-
if hasattr(settings.auth,
|
|
105
|
+
|
|
106
|
+
if hasattr(settings.auth, 'get_token'):
|
|
106
107
|
# This will trigger token refresh if needed
|
|
107
108
|
settings.auth.get_token()
|
|
108
|
-
|
|
109
|
+
|
|
109
110
|
new_token = settings.auth.token
|
|
110
|
-
|
|
111
|
+
|
|
111
112
|
# If token changed, recreate the model
|
|
112
113
|
if current_token != new_token:
|
|
113
114
|
self.wrapped_model = self._create_model()
|
|
114
|
-
|
|
115
|
+
|
|
115
116
|
def __getattr__(self, name):
|
|
116
117
|
"""Delegate attribute access to wrapped model."""
|
|
117
118
|
return getattr(self.wrapped_model, name)
|
|
@@ -119,7 +120,7 @@ class TokenRefreshingWrapper:
|
|
|
119
120
|
|
|
120
121
|
class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
121
122
|
"""Wrapper for chat models that refreshes token before each call."""
|
|
122
|
-
|
|
123
|
+
|
|
123
124
|
async def ainvoke(
|
|
124
125
|
self,
|
|
125
126
|
input: LanguageModelInput,
|
|
@@ -131,7 +132,7 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
131
132
|
"""Async invoke with token refresh."""
|
|
132
133
|
self._refresh_token()
|
|
133
134
|
return await self.wrapped_model.ainvoke(input, config, stop=stop, **kwargs)
|
|
134
|
-
|
|
135
|
+
|
|
135
136
|
def invoke(
|
|
136
137
|
self,
|
|
137
138
|
input: LanguageModelInput,
|
|
@@ -143,7 +144,7 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
143
144
|
"""Sync invoke with token refresh."""
|
|
144
145
|
self._refresh_token()
|
|
145
146
|
return self.wrapped_model.invoke(input, config, stop=stop, **kwargs)
|
|
146
|
-
|
|
147
|
+
|
|
147
148
|
async def astream(
|
|
148
149
|
self,
|
|
149
150
|
input: LanguageModelInput,
|
|
@@ -156,7 +157,7 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
156
157
|
self._refresh_token()
|
|
157
158
|
async for chunk in self.wrapped_model.astream(input, config, stop=stop, **kwargs):
|
|
158
159
|
yield chunk
|
|
159
|
-
|
|
160
|
+
|
|
160
161
|
def stream(
|
|
161
162
|
self,
|
|
162
163
|
input: LanguageModelInput,
|
|
@@ -169,7 +170,7 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
169
170
|
self._refresh_token()
|
|
170
171
|
for chunk in self.wrapped_model.stream(input, config, stop=stop, **kwargs):
|
|
171
172
|
yield chunk
|
|
172
|
-
|
|
173
|
+
|
|
173
174
|
async def agenerate(
|
|
174
175
|
self,
|
|
175
176
|
messages: List[List[BaseMessage]],
|
|
@@ -184,15 +185,10 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
184
185
|
"""Async generate with token refresh."""
|
|
185
186
|
self._refresh_token()
|
|
186
187
|
return await self.wrapped_model.agenerate(
|
|
187
|
-
messages,
|
|
188
|
-
|
|
189
|
-
callbacks=callbacks,
|
|
190
|
-
tags=tags,
|
|
191
|
-
metadata=metadata,
|
|
192
|
-
run_name=run_name,
|
|
193
|
-
**kwargs,
|
|
188
|
+
messages, stop=stop, callbacks=callbacks, tags=tags,
|
|
189
|
+
metadata=metadata, run_name=run_name, **kwargs
|
|
194
190
|
)
|
|
195
|
-
|
|
191
|
+
|
|
196
192
|
def generate(
|
|
197
193
|
self,
|
|
198
194
|
messages: List[List[BaseMessage]],
|
|
@@ -207,26 +203,21 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
207
203
|
"""Sync generate with token refresh."""
|
|
208
204
|
self._refresh_token()
|
|
209
205
|
return self.wrapped_model.generate(
|
|
210
|
-
messages,
|
|
211
|
-
|
|
212
|
-
callbacks=callbacks,
|
|
213
|
-
tags=tags,
|
|
214
|
-
metadata=metadata,
|
|
215
|
-
run_name=run_name,
|
|
216
|
-
**kwargs,
|
|
206
|
+
messages, stop=stop, callbacks=callbacks, tags=tags,
|
|
207
|
+
metadata=metadata, run_name=run_name, **kwargs
|
|
217
208
|
)
|
|
218
|
-
|
|
209
|
+
|
|
219
210
|
async def astream_events(self, *args, **kwargs):
|
|
220
211
|
"""Async stream events with token refresh."""
|
|
221
212
|
self._refresh_token()
|
|
222
213
|
async for event in self.wrapped_model.astream_events(*args, **kwargs):
|
|
223
214
|
yield event
|
|
224
|
-
|
|
215
|
+
|
|
225
216
|
def batch(self, *args, **kwargs):
|
|
226
217
|
"""Batch with token refresh."""
|
|
227
218
|
self._refresh_token()
|
|
228
219
|
return self.wrapped_model.batch(*args, **kwargs)
|
|
229
|
-
|
|
220
|
+
|
|
230
221
|
async def abatch(self, *args, **kwargs):
|
|
231
222
|
"""Async batch with token refresh."""
|
|
232
223
|
self._refresh_token()
|
|
@@ -235,9 +226,14 @@ class TokenRefreshingChatModel(TokenRefreshingWrapper):
|
|
|
235
226
|
|
|
236
227
|
async def bl_model(name: str, **kwargs):
|
|
237
228
|
url, type, model = await bl_model_core(name).get_parameters()
|
|
238
|
-
|
|
229
|
+
|
|
239
230
|
# Store model configuration for recreation
|
|
240
|
-
model_config = {
|
|
241
|
-
|
|
231
|
+
model_config = {
|
|
232
|
+
'type': type,
|
|
233
|
+
'model': model,
|
|
234
|
+
'url': url,
|
|
235
|
+
'kwargs': kwargs
|
|
236
|
+
}
|
|
237
|
+
|
|
242
238
|
# Create and return the wrapper
|
|
243
|
-
return TokenRefreshingChatModel(model_config)
|
|
239
|
+
return TokenRefreshingChatModel(model_config)
|
blaxel/langgraph/tools.py
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
from typing import Any
|
|
2
2
|
|
|
3
3
|
from langchain_core.tools import StructuredTool
|
|
4
|
-
from mcp.types import
|
|
5
|
-
CallToolResult,
|
|
6
|
-
EmbeddedResource,
|
|
7
|
-
ImageContent,
|
|
8
|
-
TextContent,
|
|
9
|
-
)
|
|
4
|
+
from mcp.types import CallToolResult, EmbeddedResource, ImageContent, TextContent
|
|
10
5
|
|
|
11
6
|
from blaxel.core.tools import bl_tools as bl_tools_core
|
|
12
7
|
from blaxel.core.tools.types import Tool, ToolException
|
|
13
8
|
|
|
14
9
|
NonTextContent = ImageContent | EmbeddedResource
|
|
15
10
|
|
|
16
|
-
|
|
17
11
|
def get_langchain_tool(tool: Tool) -> StructuredTool:
|
|
18
12
|
async def langchain_coroutine(
|
|
19
|
-
|
|
13
|
+
**arguments: dict[str, Any],
|
|
20
14
|
) -> tuple[str | list[str], list[NonTextContent] | None]:
|
|
21
15
|
result: CallToolResult = await tool.coroutine(**arguments)
|
|
22
16
|
text_contents: list[TextContent] = []
|
|
@@ -48,4 +42,4 @@ def get_langchain_tool(tool: Tool) -> StructuredTool:
|
|
|
48
42
|
async def bl_tools(tools_names: list[str], **kwargs) -> list[StructuredTool]:
|
|
49
43
|
tools = bl_tools_core(tools_names, **kwargs)
|
|
50
44
|
await tools.initialize()
|
|
51
|
-
return [get_langchain_tool(tool) for tool in tools.get_tools()]
|
|
45
|
+
return [get_langchain_tool(tool) for tool in tools.get_tools()]
|
|
@@ -17,10 +17,7 @@ from llama_index.core.base.llms.types import (
|
|
|
17
17
|
)
|
|
18
18
|
from llama_index.core.bridge.pydantic import Field, PrivateAttr
|
|
19
19
|
from llama_index.core.callbacks import CallbackManager
|
|
20
|
-
from llama_index.core.llms.callbacks import
|
|
21
|
-
llm_chat_callback,
|
|
22
|
-
llm_completion_callback,
|
|
23
|
-
)
|
|
20
|
+
from llama_index.core.llms.callbacks import llm_chat_callback, llm_completion_callback
|
|
24
21
|
from llama_index.core.llms.function_calling import FunctionCallingLLM
|
|
25
22
|
from llama_index.core.llms.llm import ToolSelection
|
|
26
23
|
from llama_index.core.tools.types import BaseTool
|
|
@@ -59,8 +56,7 @@ class Cohere(FunctionCallingLLM):
|
|
|
59
56
|
)
|
|
60
57
|
max_retries: int = Field(default=10, description="The maximum number of API retries.")
|
|
61
58
|
additional_kwargs: Dict[str, Any] = Field(
|
|
62
|
-
default_factory=dict,
|
|
63
|
-
description="Additional kwargs for the Cohere API.",
|
|
59
|
+
default_factory=dict, description="Additional kwargs for the Cohere API."
|
|
64
60
|
)
|
|
65
61
|
max_tokens: int = Field(description="The maximum number of tokens to generate.")
|
|
66
62
|
|
|
@@ -217,9 +213,9 @@ class Cohere(FunctionCallingLLM):
|
|
|
217
213
|
|
|
218
214
|
messages, documents = remove_documents_from_messages(messages)
|
|
219
215
|
|
|
220
|
-
tool_results: List[Dict[str, Any]] | None =
|
|
221
|
-
messages
|
|
222
|
-
)
|
|
216
|
+
tool_results: List[Dict[str, Any]] | None = (
|
|
217
|
+
_messages_to_cohere_tool_results_curr_chat_turn(messages) or kwargs.get("tool_results")
|
|
218
|
+
)
|
|
223
219
|
if not tool_results:
|
|
224
220
|
tool_results = None
|
|
225
221
|
|
|
@@ -289,14 +285,12 @@ class Cohere(FunctionCallingLLM):
|
|
|
289
285
|
|
|
290
286
|
if "stream" in all_kwargs:
|
|
291
287
|
warnings.warn(
|
|
292
|
-
"Parameter `stream` is not supported by the `chat` method.
|
|
288
|
+
"Parameter `stream` is not supported by the `chat` method."
|
|
289
|
+
"Use the `stream_chat` method instead"
|
|
293
290
|
)
|
|
294
291
|
|
|
295
292
|
response = completion_with_retry(
|
|
296
|
-
client=self._client,
|
|
297
|
-
max_retries=self.max_retries,
|
|
298
|
-
chat=True,
|
|
299
|
-
**chat_request,
|
|
293
|
+
client=self._client, max_retries=self.max_retries, chat=True, **chat_request
|
|
300
294
|
)
|
|
301
295
|
if not isinstance(response, cohere.NonStreamedChatResponse):
|
|
302
296
|
tool_calls = response.get("tool_calls")
|
|
@@ -322,7 +316,8 @@ class Cohere(FunctionCallingLLM):
|
|
|
322
316
|
all_kwargs = self._get_all_kwargs(**kwargs)
|
|
323
317
|
if "stream" in all_kwargs:
|
|
324
318
|
warnings.warn(
|
|
325
|
-
"Parameter `stream` is not supported by the `chat` method.
|
|
319
|
+
"Parameter `stream` is not supported by the `chat` method."
|
|
320
|
+
"Use the `stream_chat` method instead"
|
|
326
321
|
)
|
|
327
322
|
|
|
328
323
|
response = completion_with_retry(
|
|
@@ -348,10 +343,7 @@ class Cohere(FunctionCallingLLM):
|
|
|
348
343
|
chat_request = self.get_cohere_chat_request(messages=messages, **all_kwargs)
|
|
349
344
|
|
|
350
345
|
response = completion_with_retry(
|
|
351
|
-
client=self._client,
|
|
352
|
-
max_retries=self.max_retries,
|
|
353
|
-
chat=True,
|
|
354
|
-
**chat_request,
|
|
346
|
+
client=self._client, max_retries=self.max_retries, chat=True, **chat_request
|
|
355
347
|
)
|
|
356
348
|
|
|
357
349
|
def gen() -> ChatResponseGen:
|
|
@@ -402,7 +394,8 @@ class Cohere(FunctionCallingLLM):
|
|
|
402
394
|
raise ValueError(f"{all_kwargs['model']} not supported for chat")
|
|
403
395
|
if "stream" in all_kwargs:
|
|
404
396
|
warnings.warn(
|
|
405
|
-
"Parameter `stream` is not supported by the `chat` method.
|
|
397
|
+
"Parameter `stream` is not supported by the `chat` method."
|
|
398
|
+
"Use the `stream_chat` method instead"
|
|
406
399
|
)
|
|
407
400
|
|
|
408
401
|
chat_request = self.get_cohere_chat_request(messages=messages, **all_kwargs)
|
|
@@ -450,7 +443,8 @@ class Cohere(FunctionCallingLLM):
|
|
|
450
443
|
all_kwargs = self._get_all_kwargs(**kwargs)
|
|
451
444
|
if "stream" in all_kwargs:
|
|
452
445
|
warnings.warn(
|
|
453
|
-
"Parameter `stream` is not supported by the `chat` method.
|
|
446
|
+
"Parameter `stream` is not supported by the `chat` method."
|
|
447
|
+
"Use the `stream_chat` method instead"
|
|
454
448
|
)
|
|
455
449
|
|
|
456
450
|
response = await acompletion_with_retry(
|
|
@@ -478,10 +472,7 @@ class Cohere(FunctionCallingLLM):
|
|
|
478
472
|
chat_request = self.get_cohere_chat_request(messages, **all_kwargs)
|
|
479
473
|
|
|
480
474
|
response = completion_with_retry(
|
|
481
|
-
client=self._client,
|
|
482
|
-
max_retries=self.max_retries,
|
|
483
|
-
chat=True,
|
|
484
|
-
**chat_request,
|
|
475
|
+
client=self._client, max_retries=self.max_retries, chat=True, **chat_request
|
|
485
476
|
)
|
|
486
477
|
|
|
487
478
|
async def gen() -> ChatResponseAsyncGen:
|
blaxel/llamaindex/model.py
CHANGED
|
@@ -34,35 +34,35 @@ logger = getLogger(__name__)
|
|
|
34
34
|
|
|
35
35
|
class TokenRefreshingWrapper:
|
|
36
36
|
"""Base wrapper class that refreshes token before each call."""
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
def __init__(self, model_config: dict):
|
|
39
39
|
self.model_config = model_config
|
|
40
40
|
self.wrapped_model = self._create_model()
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
def _create_model(self):
|
|
43
43
|
"""Create the model instance with current token."""
|
|
44
44
|
config = self.model_config
|
|
45
|
-
model_type = config[
|
|
46
|
-
model = config[
|
|
47
|
-
url = config[
|
|
48
|
-
kwargs = config.get(
|
|
49
|
-
|
|
50
|
-
if model_type ==
|
|
45
|
+
model_type = config['type']
|
|
46
|
+
model = config['model']
|
|
47
|
+
url = config['url']
|
|
48
|
+
kwargs = config.get('kwargs', {})
|
|
49
|
+
|
|
50
|
+
if model_type == 'anthropic':
|
|
51
51
|
return Anthropic(
|
|
52
52
|
model=model,
|
|
53
53
|
api_key=settings.auth.token,
|
|
54
54
|
base_url=url,
|
|
55
55
|
default_headers=settings.auth.get_headers(),
|
|
56
|
-
**kwargs
|
|
56
|
+
**kwargs
|
|
57
57
|
)
|
|
58
|
-
elif model_type ==
|
|
58
|
+
elif model_type == 'xai':
|
|
59
59
|
return Groq(
|
|
60
60
|
model=model,
|
|
61
61
|
api_key=settings.auth.token,
|
|
62
62
|
api_base=f"{url}/v1",
|
|
63
|
-
**kwargs
|
|
63
|
+
**kwargs
|
|
64
64
|
)
|
|
65
|
-
elif model_type ==
|
|
65
|
+
elif model_type == 'gemini':
|
|
66
66
|
return GoogleGenAI(
|
|
67
67
|
api_key=settings.auth.token,
|
|
68
68
|
model=model,
|
|
@@ -71,54 +71,62 @@ class TokenRefreshingWrapper:
|
|
|
71
71
|
base_url=url,
|
|
72
72
|
headers=settings.auth.get_headers(),
|
|
73
73
|
),
|
|
74
|
-
**kwargs
|
|
74
|
+
**kwargs
|
|
75
75
|
)
|
|
76
|
-
elif model_type ==
|
|
77
|
-
return Cohere(
|
|
78
|
-
|
|
76
|
+
elif model_type == 'cohere':
|
|
77
|
+
return Cohere(
|
|
78
|
+
model=model,
|
|
79
|
+
api_key=settings.auth.token,
|
|
80
|
+
api_base=url,
|
|
81
|
+
**kwargs
|
|
82
|
+
)
|
|
83
|
+
elif model_type == 'deepseek':
|
|
79
84
|
return DeepSeek(
|
|
80
85
|
model=model,
|
|
81
86
|
api_key=settings.auth.token,
|
|
82
87
|
api_base=f"{url}/v1",
|
|
83
|
-
**kwargs
|
|
88
|
+
**kwargs
|
|
84
89
|
)
|
|
85
|
-
elif model_type ==
|
|
86
|
-
return MistralAI(
|
|
87
|
-
|
|
90
|
+
elif model_type == 'mistral':
|
|
91
|
+
return MistralAI(
|
|
92
|
+
model=model,
|
|
93
|
+
api_key=settings.auth.token,
|
|
94
|
+
endpoint=url,
|
|
95
|
+
**kwargs
|
|
96
|
+
)
|
|
97
|
+
elif model_type == 'cerebras':
|
|
88
98
|
return Cerebras(
|
|
89
99
|
model=model,
|
|
90
100
|
api_key=settings.auth.token,
|
|
91
101
|
api_base=f"{url}/v1",
|
|
92
|
-
**kwargs
|
|
102
|
+
**kwargs
|
|
93
103
|
)
|
|
94
104
|
else:
|
|
95
105
|
if model_type != "openai":
|
|
96
|
-
logger.warning(
|
|
97
|
-
|
|
98
|
-
)
|
|
99
|
-
|
|
106
|
+
logger.warning(f"Model {model} is not supported by LlamaIndex, defaulting to OpenAI")
|
|
107
|
+
|
|
100
108
|
return OpenAI(
|
|
101
109
|
model=model,
|
|
102
110
|
api_key=settings.auth.token,
|
|
103
111
|
api_base=f"{url}/v1",
|
|
104
|
-
**kwargs
|
|
112
|
+
**kwargs
|
|
105
113
|
)
|
|
106
|
-
|
|
114
|
+
|
|
107
115
|
def _refresh_token(self):
|
|
108
116
|
"""Refresh the token and recreate the model if needed."""
|
|
109
117
|
# Only refresh if using ClientCredentials (which has get_token method)
|
|
110
118
|
current_token = settings.auth.token
|
|
111
|
-
|
|
112
|
-
if hasattr(settings.auth,
|
|
119
|
+
|
|
120
|
+
if hasattr(settings.auth, 'get_token'):
|
|
113
121
|
# This will trigger token refresh if needed
|
|
114
122
|
settings.auth.get_token()
|
|
115
|
-
|
|
123
|
+
|
|
116
124
|
new_token = settings.auth.token
|
|
117
|
-
|
|
125
|
+
|
|
118
126
|
# If token changed, recreate the model
|
|
119
127
|
if current_token != new_token:
|
|
120
128
|
self.wrapped_model = self._create_model()
|
|
121
|
-
|
|
129
|
+
|
|
122
130
|
def __getattr__(self, name):
|
|
123
131
|
"""Delegate attribute access to wrapped model."""
|
|
124
132
|
return getattr(self.wrapped_model, name)
|
|
@@ -126,7 +134,7 @@ class TokenRefreshingWrapper:
|
|
|
126
134
|
|
|
127
135
|
class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
128
136
|
"""Wrapper for LlamaIndex LLMs that refreshes token before each call."""
|
|
129
|
-
|
|
137
|
+
|
|
130
138
|
async def achat(
|
|
131
139
|
self,
|
|
132
140
|
messages: Sequence[ChatMessage],
|
|
@@ -135,7 +143,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
135
143
|
"""Async chat with token refresh."""
|
|
136
144
|
self._refresh_token()
|
|
137
145
|
return await self.wrapped_model.achat(messages, **kwargs)
|
|
138
|
-
|
|
146
|
+
|
|
139
147
|
def chat(
|
|
140
148
|
self,
|
|
141
149
|
messages: Sequence[ChatMessage],
|
|
@@ -144,7 +152,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
144
152
|
"""Sync chat with token refresh."""
|
|
145
153
|
self._refresh_token()
|
|
146
154
|
return self.wrapped_model.chat(messages, **kwargs)
|
|
147
|
-
|
|
155
|
+
|
|
148
156
|
async def astream_chat(
|
|
149
157
|
self,
|
|
150
158
|
messages: Sequence[ChatMessage],
|
|
@@ -154,7 +162,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
154
162
|
self._refresh_token()
|
|
155
163
|
async for chunk in self.wrapped_model.astream_chat(messages, **kwargs):
|
|
156
164
|
yield chunk
|
|
157
|
-
|
|
165
|
+
|
|
158
166
|
def stream_chat(
|
|
159
167
|
self,
|
|
160
168
|
messages: Sequence[ChatMessage],
|
|
@@ -164,7 +172,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
164
172
|
self._refresh_token()
|
|
165
173
|
for chunk in self.wrapped_model.stream_chat(messages, **kwargs):
|
|
166
174
|
yield chunk
|
|
167
|
-
|
|
175
|
+
|
|
168
176
|
async def acomplete(
|
|
169
177
|
self,
|
|
170
178
|
prompt: str,
|
|
@@ -173,7 +181,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
173
181
|
"""Async complete with token refresh."""
|
|
174
182
|
self._refresh_token()
|
|
175
183
|
return await self.wrapped_model.acomplete(prompt, **kwargs)
|
|
176
|
-
|
|
184
|
+
|
|
177
185
|
def complete(
|
|
178
186
|
self,
|
|
179
187
|
prompt: str,
|
|
@@ -182,7 +190,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
182
190
|
"""Sync complete with token refresh."""
|
|
183
191
|
self._refresh_token()
|
|
184
192
|
return self.wrapped_model.complete(prompt, **kwargs)
|
|
185
|
-
|
|
193
|
+
|
|
186
194
|
async def astream_complete(
|
|
187
195
|
self,
|
|
188
196
|
prompt: str,
|
|
@@ -192,7 +200,7 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
192
200
|
self._refresh_token()
|
|
193
201
|
async for chunk in self.wrapped_model.astream_complete(prompt, **kwargs):
|
|
194
202
|
yield chunk
|
|
195
|
-
|
|
203
|
+
|
|
196
204
|
def stream_complete(
|
|
197
205
|
self,
|
|
198
206
|
prompt: str,
|
|
@@ -206,9 +214,14 @@ class TokenRefreshingLLM(TokenRefreshingWrapper):
|
|
|
206
214
|
|
|
207
215
|
async def bl_model(name, **kwargs):
|
|
208
216
|
url, type, model = await bl_model_core(name).get_parameters()
|
|
209
|
-
|
|
217
|
+
|
|
210
218
|
# Store model configuration for recreation
|
|
211
|
-
model_config = {
|
|
212
|
-
|
|
219
|
+
model_config = {
|
|
220
|
+
'type': type,
|
|
221
|
+
'model': model,
|
|
222
|
+
'url': url,
|
|
223
|
+
'kwargs': kwargs
|
|
224
|
+
}
|
|
225
|
+
|
|
213
226
|
# Create and return the wrapper
|
|
214
|
-
return TokenRefreshingLLM(model_config)
|
|
227
|
+
return TokenRefreshingLLM(model_config)
|
blaxel/llamaindex/tools.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
1
3
|
from llama_index.core.tools import FunctionTool
|
|
2
4
|
from llama_index.core.tools.types import ToolMetadata
|
|
3
5
|
|
|
@@ -20,8 +22,7 @@ def get_llamaindex_tool(tool: Tool) -> FunctionTool:
|
|
|
20
22
|
),
|
|
21
23
|
)
|
|
22
24
|
|
|
23
|
-
|
|
24
25
|
async def bl_tools(tools_names: list[str], **kwargs) -> list[FunctionTool]:
|
|
25
26
|
tools = bl_tools_core(tools_names, **kwargs)
|
|
26
27
|
await tools.initialize()
|
|
27
|
-
return [get_llamaindex_tool(tool) for tool in tools.get_tools()]
|
|
28
|
+
return [get_llamaindex_tool(tool) for tool in tools.get_tools()]
|
blaxel/pydantic/custom/gemini.py
CHANGED
|
@@ -8,11 +8,11 @@ class GoogleGLAProvider(Provider[AsyncClient]):
|
|
|
8
8
|
|
|
9
9
|
@property
|
|
10
10
|
def name(self):
|
|
11
|
-
return
|
|
11
|
+
return 'google-gla'
|
|
12
12
|
|
|
13
13
|
@property
|
|
14
14
|
def base_url(self) -> str:
|
|
15
|
-
return
|
|
15
|
+
return 'https://generativelanguage.googleapis.com/v1beta/models/'
|
|
16
16
|
|
|
17
17
|
@property
|
|
18
18
|
def client(self) -> httpx.AsyncClient:
|
|
@@ -28,4 +28,4 @@ class GoogleGLAProvider(Provider[AsyncClient]):
|
|
|
28
28
|
"""
|
|
29
29
|
self._client = http_client
|
|
30
30
|
# https://cloud.google.com/docs/authentication/api-keys-use#using-with-rest
|
|
31
|
-
self._client.headers[
|
|
31
|
+
self._client.headers['X-Goog-Api-Key'] = api_key
|
blaxel/pydantic/tools.py
CHANGED
|
@@ -23,7 +23,9 @@ def get_pydantic_tool(tool: Tool) -> PydanticTool:
|
|
|
23
23
|
|
|
24
24
|
# Define the prepare function dynamically to capture the 'tool' object
|
|
25
25
|
# Assuming RunContext and ToolDefinition types based on the pydantic_ai example
|
|
26
|
-
async def prepare_tool(
|
|
26
|
+
async def prepare_tool(
|
|
27
|
+
ctx: RunContext, tool_def: ToolDefinition
|
|
28
|
+
) -> ToolDefinition | None:
|
|
27
29
|
"""Dynamically prepares the ToolDefinition using the custom Tool's attributes."""
|
|
28
30
|
tool_def.name = tool.name # Override inferred name
|
|
29
31
|
tool_def.description = tool.description # Override inferred description
|
|
@@ -46,4 +48,4 @@ def get_pydantic_tool(tool: Tool) -> PydanticTool:
|
|
|
46
48
|
async def bl_tools(tools_names: list[str], **kwargs) -> list[PydanticTool]:
|
|
47
49
|
tools = bl_tools_core(tools_names, **kwargs)
|
|
48
50
|
await tools.initialize()
|
|
49
|
-
return [get_pydantic_tool(tool) for tool in tools.get_tools()]
|
|
51
|
+
return [get_pydantic_tool(tool) for tool in tools.get_tools()]
|