grasp_agents 0.3.5__tar.gz → 0.3.7__tar.gz
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.
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/PKG-INFO +1 -1
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/pyproject.toml +1 -1
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/cloud_llm.py +24 -16
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/openai_llm.py +9 -5
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/prompt_builder.py +15 -12
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/.gitignore +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/LICENSE.md +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/README.md +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/__init__.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/comm_processor.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/costs_dict.yaml +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/generics_utils.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/grasp_logging.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/http_client.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/llm.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/llm_agent.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/llm_agent_memory.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/llm_policy_executor.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/memory.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/message_history.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/__init__.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/completion_chunk_converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/completion_converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/content_converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/message_converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/tool_converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/packet.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/packet_pool.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/printer.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/processor.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/rate_limiting/__init__.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/rate_limiting/rate_limiter_chunked.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/rate_limiting/types.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/rate_limiting/utils.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/run_context.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/__init__.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/completion.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/completion_chunk.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/content.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/converters.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/events.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/io.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/message.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/typing/tool.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/usage_tracker.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/utils.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/workflow/__init__.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/workflow/looped_workflow.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/workflow/parallel_processor.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/workflow/sequential_workflow.py +0 -0
- {grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/workflow/workflow_processor.py +0 -0
@@ -127,21 +127,32 @@ class CloudLLM(LLM[SettingsT_co, ConvertT_co], Generic[SettingsT_co, ConvertT_co
|
|
127
127
|
)
|
128
128
|
|
129
129
|
self._model_name = model_name
|
130
|
+
model_name_parts = model_name.split(":", 1)
|
131
|
+
|
132
|
+
if len(model_name_parts) == 2 and model_name_parts[0] in PROVIDERS:
|
133
|
+
api_provider, api_model_name = model_name_parts
|
134
|
+
if api_provider not in PROVIDERS:
|
135
|
+
raise ValueError(
|
136
|
+
f"API provider '{api_provider}' is not supported. "
|
137
|
+
f"Supported providers are: {', '.join(PROVIDERS.keys())}"
|
138
|
+
)
|
130
139
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
140
|
+
self._api_provider: APIProvider | None = api_provider
|
141
|
+
self._api_model_name: str = api_model_name
|
142
|
+
self._base_url: str | None = PROVIDERS[api_provider]["base_url"]
|
143
|
+
self._api_key: str | None = PROVIDERS[api_provider]["api_key"]
|
144
|
+
self._struct_outputs_support: bool = any(
|
145
|
+
fnmatch.fnmatch(self._model_name, pat)
|
146
|
+
for pat in PROVIDERS[api_provider]["struct_outputs_support"]
|
137
147
|
)
|
138
|
-
self._api_provider: APIProvider = api_provider
|
139
|
-
self._api_model_name: str = api_model_name
|
140
148
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
149
|
+
else:
|
150
|
+
self._api_provider = None
|
151
|
+
self._api_model_name = model_name
|
152
|
+
self._base_url = None
|
153
|
+
self._api_key = None
|
154
|
+
self._struct_outputs_support = False
|
155
|
+
|
145
156
|
if (
|
146
157
|
self._llm_settings.get("use_struct_outputs")
|
147
158
|
and not self._struct_outputs_support
|
@@ -161,9 +172,6 @@ class CloudLLM(LLM[SettingsT_co, ConvertT_co], Generic[SettingsT_co, ConvertT_co
|
|
161
172
|
)
|
162
173
|
)
|
163
174
|
self.no_tqdm = no_tqdm
|
164
|
-
|
165
|
-
self._base_url: str = PROVIDERS[api_provider]["base_url"]
|
166
|
-
self._api_key: str | None = PROVIDERS[api_provider]["api_key"]
|
167
175
|
self._client: Any
|
168
176
|
|
169
177
|
self._async_http_client: httpx.AsyncClient | None = None
|
@@ -178,7 +186,7 @@ class CloudLLM(LLM[SettingsT_co, ConvertT_co], Generic[SettingsT_co, ConvertT_co
|
|
178
186
|
self.num_generation_retries = num_generation_retries
|
179
187
|
|
180
188
|
@property
|
181
|
-
def api_provider(self) -> APIProvider:
|
189
|
+
def api_provider(self) -> APIProvider | None:
|
182
190
|
return self._api_provider
|
183
191
|
|
184
192
|
@property
|
@@ -80,6 +80,7 @@ class OpenAILLM(CloudLLM[OpenAILLMSettings, OpenAIConverters]):
|
|
80
80
|
dict[str, Any] | AsyncHTTPClientParams | None
|
81
81
|
) = None,
|
82
82
|
async_openai_client_params: dict[str, Any] | None = None,
|
83
|
+
client: AsyncOpenAI | None = None,
|
83
84
|
# Rate limiting
|
84
85
|
rate_limiter: (RateLimiterC[Messages, AssistantMessage] | None) = None,
|
85
86
|
rate_limiter_rpm: float | None = None,
|
@@ -117,11 +118,14 @@ class OpenAILLM(CloudLLM[OpenAILLMSettings, OpenAIConverters]):
|
|
117
118
|
_async_openai_client_params["http_client"] = self._async_http_client
|
118
119
|
|
119
120
|
# TODO: context manager for async client
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
if client:
|
122
|
+
self._client = client
|
123
|
+
else:
|
124
|
+
self._client: AsyncOpenAI = AsyncOpenAI(
|
125
|
+
base_url=self._base_url,
|
126
|
+
api_key=self._api_key,
|
127
|
+
**_async_openai_client_params,
|
128
|
+
)
|
125
129
|
|
126
130
|
async def _get_completion(
|
127
131
|
self,
|
@@ -165,7 +165,7 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
165
165
|
if in_args is not None:
|
166
166
|
val_in_args = self._in_args_type_adapter.validate_python(in_args)
|
167
167
|
if isinstance(val_in_args, BaseModel):
|
168
|
-
|
168
|
+
has_image = self._has_image_data(val_in_args)
|
169
169
|
if has_image and self.in_prompt_template is None:
|
170
170
|
raise TypeError(
|
171
171
|
"BaseModel input arguments contain ImageData, but input prompt "
|
@@ -179,22 +179,27 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
179
179
|
|
180
180
|
return val_in_args, val_usr_args
|
181
181
|
|
182
|
+
@staticmethod
|
183
|
+
def _has_image_data(inp: BaseModel) -> bool:
|
184
|
+
contains_image_data = False
|
185
|
+
for field in type(inp).model_fields:
|
186
|
+
if isinstance(getattr(inp, field), ImageData):
|
187
|
+
contains_image_data = True
|
188
|
+
|
189
|
+
return contains_image_data
|
190
|
+
|
182
191
|
@staticmethod
|
183
192
|
def _format_pydantic_prompt_args(
|
184
193
|
inp: BaseModel,
|
185
|
-
) ->
|
194
|
+
) -> dict[str, PromptArgumentType]:
|
186
195
|
formatted_args: dict[str, PromptArgumentType] = {}
|
187
|
-
contains_image_data = False
|
188
196
|
for field in type(inp).model_fields:
|
189
197
|
if field == "selected_recipients":
|
190
198
|
continue
|
191
199
|
|
192
200
|
val = getattr(inp, field)
|
193
|
-
if isinstance(val, (int, str, bool)):
|
194
|
-
formatted_args[field] = val
|
195
|
-
elif isinstance(val, ImageData):
|
201
|
+
if isinstance(val, (int, str, bool, ImageData)):
|
196
202
|
formatted_args[field] = val
|
197
|
-
contains_image_data = True
|
198
203
|
elif isinstance(val, BaseModel):
|
199
204
|
formatted_args[field] = val.model_dump_json(indent=2, warnings="error")
|
200
205
|
else:
|
@@ -203,20 +208,18 @@ class PromptBuilder(AutoInstanceAttributesMixin, Generic[InT_contra, CtxT]):
|
|
203
208
|
"int, str, bool, BaseModel, or ImageData."
|
204
209
|
)
|
205
210
|
|
206
|
-
return formatted_args
|
211
|
+
return formatted_args
|
207
212
|
|
208
213
|
def _combine_args(
|
209
214
|
self, *, in_args: InT_contra | None, usr_args: LLMPromptArgs | None
|
210
215
|
) -> Mapping[str, PromptArgumentType] | str:
|
211
|
-
fmt_usr_args
|
212
|
-
self._format_pydantic_prompt_args(usr_args) if usr_args else ({}, False)
|
213
|
-
)
|
216
|
+
fmt_usr_args = self._format_pydantic_prompt_args(usr_args) if usr_args else {}
|
214
217
|
|
215
218
|
if in_args is None:
|
216
219
|
return fmt_usr_args
|
217
220
|
|
218
221
|
if isinstance(in_args, BaseModel):
|
219
|
-
fmt_in_args
|
222
|
+
fmt_in_args = self._format_pydantic_prompt_args(in_args)
|
220
223
|
return fmt_in_args | fmt_usr_args
|
221
224
|
|
222
225
|
combined_args_str = self._in_args_type_adapter.dump_json(
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/openai/completion_chunk_converters.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{grasp_agents-0.3.5 → grasp_agents-0.3.7}/src/grasp_agents/rate_limiting/rate_limiter_chunked.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|