simile 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.
Potentially problematic release.
This version of simile might be problematic. Click here for more details.
- {simile-0.3.5 → simile-0.3.7}/PKG-INFO +1 -1
- {simile-0.3.5 → simile-0.3.7}/pyproject.toml +1 -1
- {simile-0.3.5 → simile-0.3.7}/simile/client.py +88 -1
- {simile-0.3.5 → simile-0.3.7}/simile.egg-info/PKG-INFO +1 -1
- {simile-0.3.5 → simile-0.3.7}/LICENSE +0 -0
- {simile-0.3.5 → simile-0.3.7}/README.md +0 -0
- {simile-0.3.5 → simile-0.3.7}/setup.cfg +0 -0
- {simile-0.3.5 → simile-0.3.7}/setup.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile/__init__.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile/auth_client.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile/exceptions.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile/models.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile/resources.py +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile.egg-info/SOURCES.txt +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile.egg-info/dependency_links.txt +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile.egg-info/requires.txt +0 -0
- {simile-0.3.5 → simile-0.3.7}/simile.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import httpx
|
|
2
2
|
from httpx import AsyncClient
|
|
3
|
-
from typing import List, Dict, Any, Optional, Union, Type
|
|
3
|
+
from typing import List, Dict, Any, Optional, Union, Type, AsyncGenerator
|
|
4
4
|
import uuid
|
|
5
5
|
from pydantic import BaseModel
|
|
6
6
|
|
|
@@ -233,6 +233,31 @@ class Simile:
|
|
|
233
233
|
)
|
|
234
234
|
return response_data
|
|
235
235
|
|
|
236
|
+
async def add_agent_to_population(
|
|
237
|
+
self, agent_id: Union[str, uuid.UUID], population_id: Union[str, uuid.UUID]
|
|
238
|
+
) -> Dict[str, str]:
|
|
239
|
+
"""Add an agent to an additional population."""
|
|
240
|
+
raw_response = await self._request(
|
|
241
|
+
"POST", f"agents/{str(agent_id)}/populations/{str(population_id)}"
|
|
242
|
+
)
|
|
243
|
+
return raw_response.json()
|
|
244
|
+
|
|
245
|
+
async def remove_agent_from_population(
|
|
246
|
+
self, agent_id: Union[str, uuid.UUID], population_id: Union[str, uuid.UUID]
|
|
247
|
+
) -> Dict[str, str]:
|
|
248
|
+
"""Remove an agent from a population."""
|
|
249
|
+
raw_response = await self._request(
|
|
250
|
+
"DELETE", f"agents/{str(agent_id)}/populations/{str(population_id)}"
|
|
251
|
+
)
|
|
252
|
+
return raw_response.json()
|
|
253
|
+
|
|
254
|
+
async def get_populations_for_agent(
|
|
255
|
+
self, agent_id: Union[str, uuid.UUID]
|
|
256
|
+
) -> Dict[str, Any]:
|
|
257
|
+
"""Get all populations an agent belongs to."""
|
|
258
|
+
raw_response = await self._request("GET", f"agents/{str(agent_id)}/populations")
|
|
259
|
+
return raw_response.json()
|
|
260
|
+
|
|
236
261
|
async def create_data_item(
|
|
237
262
|
self, agent_id: Union[str, uuid.UUID], data_type: str, content: Any, metadata: Optional[Dict[str, Any]] = None
|
|
238
263
|
) -> DataItem:
|
|
@@ -287,6 +312,68 @@ class Simile:
|
|
|
287
312
|
)
|
|
288
313
|
return response_data
|
|
289
314
|
|
|
315
|
+
async def stream_open_response(
|
|
316
|
+
self,
|
|
317
|
+
agent_id: uuid.UUID,
|
|
318
|
+
question: str,
|
|
319
|
+
data_types: Optional[List[str]] = None,
|
|
320
|
+
exclude_data_types: Optional[List[str]] = None,
|
|
321
|
+
images: Optional[Dict[str, str]] = None,
|
|
322
|
+
) -> AsyncGenerator[str, None]:
|
|
323
|
+
"""Streams an open response from an agent."""
|
|
324
|
+
endpoint = f"/generation/open-stream/{str(agent_id)}"
|
|
325
|
+
request_payload = OpenGenerationRequest(
|
|
326
|
+
question=question,
|
|
327
|
+
data_types=data_types,
|
|
328
|
+
exclude_data_types=exclude_data_types,
|
|
329
|
+
images=images,
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
url = self.base_url + endpoint # assuming self.base_url is defined
|
|
333
|
+
|
|
334
|
+
async with httpx.AsyncClient(timeout=None) as client:
|
|
335
|
+
async with client.stream("POST", url, json=request_payload.model_dump()) as response:
|
|
336
|
+
response.raise_for_status()
|
|
337
|
+
async for line in response.aiter_lines():
|
|
338
|
+
if line.strip(): # skip empty lines
|
|
339
|
+
if line.startswith("data: "): # optional, if using SSE format
|
|
340
|
+
yield line.removeprefix("data: ").strip()
|
|
341
|
+
else:
|
|
342
|
+
yield line.strip()
|
|
343
|
+
|
|
344
|
+
async def stream_closed_response(
|
|
345
|
+
self,
|
|
346
|
+
agent_id: uuid.UUID,
|
|
347
|
+
question: str,
|
|
348
|
+
options: List[str],
|
|
349
|
+
data_types: Optional[List[str]] = None,
|
|
350
|
+
exclude_data_types: Optional[List[str]] = None,
|
|
351
|
+
images: Optional[Dict[str, str]] = None,
|
|
352
|
+
) -> AsyncGenerator[str, None]:
|
|
353
|
+
"""Streams a closed response from an agent."""
|
|
354
|
+
endpoint = f"/generation/closed-stream/{str(agent_id)}"
|
|
355
|
+
|
|
356
|
+
request_payload = {
|
|
357
|
+
"question": question,
|
|
358
|
+
"options": options,
|
|
359
|
+
"data_types": data_types,
|
|
360
|
+
"exclude_data_types": exclude_data_types,
|
|
361
|
+
"images": images,
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
url = self.base_url + endpoint # assuming self.base_url is defined
|
|
365
|
+
|
|
366
|
+
async with httpx.AsyncClient(timeout=None) as client:
|
|
367
|
+
async with client.stream("POST", url, json=request_payload) as response:
|
|
368
|
+
response.raise_for_status()
|
|
369
|
+
async for line in response.aiter_lines():
|
|
370
|
+
if line.strip(): # skip empty lines
|
|
371
|
+
if line.startswith("data: "): # optional, if using SSE format
|
|
372
|
+
yield line.removeprefix("data: ").strip()
|
|
373
|
+
else:
|
|
374
|
+
yield line.strip()
|
|
375
|
+
|
|
376
|
+
|
|
290
377
|
async def generate_open_response(
|
|
291
378
|
self,
|
|
292
379
|
agent_id: uuid.UUID,
|
|
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
|