simile 0.2.1__py3-none-any.whl → 0.2.2__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.
Potentially problematic release.
This version of simile might be problematic. Click here for more details.
- simile/client.py +39 -17
- simile/models.py +24 -5
- simile/resources.py +83 -0
- {simile-0.2.1.dist-info → simile-0.2.2.dist-info}/METADATA +2 -2
- simile-0.2.2.dist-info/RECORD +10 -0
- simile-0.2.1.dist-info/RECORD +0 -9
- {simile-0.2.1.dist-info → simile-0.2.2.dist-info}/WHEEL +0 -0
- {simile-0.2.1.dist-info → simile-0.2.2.dist-info}/licenses/LICENSE +0 -0
- {simile-0.2.1.dist-info → simile-0.2.2.dist-info}/top_level.txt +0 -0
simile/client.py
CHANGED
|
@@ -5,10 +5,14 @@ import uuid
|
|
|
5
5
|
from pydantic import BaseModel
|
|
6
6
|
|
|
7
7
|
from .models import (
|
|
8
|
-
Population, Agent, DataItem,
|
|
8
|
+
Population, Agent as AgentModel, DataItem, DeletionResponse,
|
|
9
|
+
QualGenerationRequest, QualGenerationResponse,
|
|
10
|
+
MCGenerationRequest, MCGenerationResponse,
|
|
9
11
|
CreatePopulationPayload, CreateAgentPayload, CreateDataItemPayload, UpdateDataItemPayload,
|
|
10
|
-
|
|
12
|
+
InitialDataItemPayload,
|
|
13
|
+
SurveySessionCreateResponse
|
|
11
14
|
)
|
|
15
|
+
from .resources import Agent, SurveySession
|
|
12
16
|
from .exceptions import (
|
|
13
17
|
SimileAPIError, SimileAuthenticationError, SimileNotFoundError, SimileBadRequestError
|
|
14
18
|
)
|
|
@@ -17,7 +21,6 @@ DEFAULT_BASE_URL = "https://simile-api-3a83be7adae0.herokuapp.com/api/v1"
|
|
|
17
21
|
TIMEOUT_CONFIG = httpx.Timeout(5.0, read=30.0, write=30.0, pool=30.0)
|
|
18
22
|
|
|
19
23
|
class Simile:
|
|
20
|
-
# Make exceptions available as class attributes for convenience
|
|
21
24
|
APIError = SimileAPIError
|
|
22
25
|
AuthenticationError = SimileAuthenticationError
|
|
23
26
|
NotFoundError = SimileNotFoundError
|
|
@@ -64,7 +67,26 @@ class Simile:
|
|
|
64
67
|
except httpx.RequestError as e:
|
|
65
68
|
raise SimileAPIError(f"Request error: {e}")
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
def agent(self, agent_id: uuid.UUID) -> Agent:
|
|
71
|
+
"""Returns an Agent object to interact with a specific agent."""
|
|
72
|
+
return Agent(agent_id=agent_id, client=self)
|
|
73
|
+
|
|
74
|
+
async def create_survey_session(self, agent_id: uuid.UUID) -> SurveySession:
|
|
75
|
+
"""Creates a new survey session for the given agent and returns a SurveySession object."""
|
|
76
|
+
endpoint = "sessions/"
|
|
77
|
+
response_data = await self._request(
|
|
78
|
+
"POST",
|
|
79
|
+
endpoint,
|
|
80
|
+
json={"agent_id": str(agent_id)},
|
|
81
|
+
response_model=SurveySessionCreateResponse
|
|
82
|
+
)
|
|
83
|
+
return SurveySession(
|
|
84
|
+
id=response_data.id,
|
|
85
|
+
agent_id=response_data.agent_id,
|
|
86
|
+
status=response_data.status,
|
|
87
|
+
client=self
|
|
88
|
+
)
|
|
89
|
+
|
|
68
90
|
async def create_population(self, name: str, description: Optional[str] = None) -> Population:
|
|
69
91
|
"""Creates a new population."""
|
|
70
92
|
payload = CreatePopulationPayload(name=name, description=description)
|
|
@@ -79,27 +101,24 @@ class Simile:
|
|
|
79
101
|
response_data = await self._request("DELETE", f"populations/delete/{str(population_id)}", response_model=DeletionResponse)
|
|
80
102
|
return response_data
|
|
81
103
|
|
|
82
|
-
|
|
83
|
-
async def create_agent(self, name: str, population_id: Optional[Union[str, uuid.UUID]] = None, agent_data: Optional[List[Dict[str, Any]]] = None) -> Agent:
|
|
104
|
+
async def create_agent(self, name: str, population_id: Optional[Union[str, uuid.UUID]] = None, agent_data: Optional[List[Dict[str, Any]]] = None) -> AgentModel:
|
|
84
105
|
"""Creates a new agent, optionally within a population and with initial data items."""
|
|
85
|
-
# Ensure population_id is uuid if provided
|
|
86
106
|
pop_id_uuid: Optional[uuid.UUID] = None
|
|
87
107
|
if population_id:
|
|
88
108
|
pop_id_uuid = uuid.UUID(str(population_id)) if not isinstance(population_id, uuid.UUID) else population_id
|
|
89
109
|
|
|
90
110
|
payload = CreateAgentPayload(name=name, population_id=pop_id_uuid, agent_data=agent_data)
|
|
91
|
-
response_data = await self._request("POST", "agents/create", json=payload.model_dump(mode='json', exclude_none=True), response_model=
|
|
111
|
+
response_data = await self._request("POST", "agents/create", json=payload.model_dump(mode='json', exclude_none=True), response_model=AgentModel)
|
|
92
112
|
return response_data
|
|
93
113
|
|
|
94
|
-
async def get_agent(self, agent_id: Union[str, uuid.UUID]) ->
|
|
95
|
-
response_data = await self._request("GET", f"agents/get/{str(agent_id)}", response_model=
|
|
114
|
+
async def get_agent(self, agent_id: Union[str, uuid.UUID]) -> AgentModel:
|
|
115
|
+
response_data = await self._request("GET", f"agents/get/{str(agent_id)}", response_model=AgentModel)
|
|
96
116
|
return response_data
|
|
97
117
|
|
|
98
118
|
async def delete_agent(self, agent_id: Union[str, uuid.UUID]) -> DeletionResponse:
|
|
99
119
|
response_data = await self._request("DELETE", f"agents/delete/{str(agent_id)}", response_model=DeletionResponse)
|
|
100
120
|
return response_data
|
|
101
121
|
|
|
102
|
-
# --- Data Item Endpoints ---
|
|
103
122
|
async def create_data_item(self, agent_id: Union[str, uuid.UUID], data_type: str, content: Any) -> DataItem:
|
|
104
123
|
"""Creates a new data item for a specific agent."""
|
|
105
124
|
payload = CreateDataItemPayload(data_type=data_type, content=content)
|
|
@@ -114,7 +133,6 @@ class Simile:
|
|
|
114
133
|
params = {}
|
|
115
134
|
if data_type:
|
|
116
135
|
params["data_type"] = data_type
|
|
117
|
-
# Ensure agent_id is string for URL
|
|
118
136
|
agent_id_str = str(agent_id)
|
|
119
137
|
raw_response = await self._request("GET", f"data_item/list/{agent_id_str}", params=params)
|
|
120
138
|
return [DataItem(**item) for item in raw_response.json()]
|
|
@@ -129,11 +147,10 @@ class Simile:
|
|
|
129
147
|
response_data = await self._request("DELETE", f"data_item/delete/{str(data_item_id)}", response_model=DeletionResponse)
|
|
130
148
|
return response_data
|
|
131
149
|
|
|
132
|
-
# --- LLM Generation Methods ---
|
|
133
150
|
async def generate_qual_response(self, agent_id: uuid.UUID, question: str) -> QualGenerationResponse:
|
|
134
151
|
"""Generates a qualitative response from an agent based on a question."""
|
|
135
152
|
endpoint = f"/generation/qual/{str(agent_id)}"
|
|
136
|
-
request_payload = QualGenerationRequest(question=question)
|
|
153
|
+
request_payload = QualGenerationRequest(question=question)
|
|
137
154
|
response_data = await self._request(
|
|
138
155
|
"POST",
|
|
139
156
|
endpoint,
|
|
@@ -144,9 +161,14 @@ class Simile:
|
|
|
144
161
|
|
|
145
162
|
async def generate_mc_response(self, agent_id: uuid.UUID, question: str, options: List[str]) -> MCGenerationResponse:
|
|
146
163
|
"""Generates a multiple-choice response from an agent."""
|
|
147
|
-
endpoint = f"generation/mc/{str(agent_id)}"
|
|
148
|
-
request_payload = MCGenerationRequest(question=question, options=options)
|
|
149
|
-
response_data = await self._request(
|
|
164
|
+
endpoint = f"generation/mc/{str(agent_id)}"
|
|
165
|
+
request_payload = MCGenerationRequest(question=question, options=options)
|
|
166
|
+
response_data = await self._request(
|
|
167
|
+
"POST",
|
|
168
|
+
endpoint,
|
|
169
|
+
json=request_payload.model_dump(),
|
|
170
|
+
response_model=MCGenerationResponse
|
|
171
|
+
)
|
|
150
172
|
return response_data
|
|
151
173
|
|
|
152
174
|
async def aclose(self):
|
simile/models.py
CHANGED
|
@@ -42,7 +42,7 @@ class InitialDataItemPayload(BaseModel):
|
|
|
42
42
|
class CreateAgentPayload(BaseModel):
|
|
43
43
|
name: str
|
|
44
44
|
population_id: Optional[uuid.UUID] = None
|
|
45
|
-
agent_data: Optional[List[InitialDataItemPayload]] = None
|
|
45
|
+
agent_data: Optional[List[InitialDataItemPayload]] = None
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
class CreateDataItemPayload(BaseModel):
|
|
@@ -58,13 +58,11 @@ class DeletionResponse(BaseModel):
|
|
|
58
58
|
message: str
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
# ---
|
|
62
|
-
|
|
61
|
+
# --- Generation Operation Models ---
|
|
63
62
|
class QualGenerationRequest(BaseModel):
|
|
64
63
|
question: str
|
|
65
64
|
|
|
66
65
|
class QualGenerationResponse(BaseModel):
|
|
67
|
-
agent_id: uuid.UUID
|
|
68
66
|
question: str
|
|
69
67
|
answer: str
|
|
70
68
|
|
|
@@ -73,7 +71,28 @@ class MCGenerationRequest(BaseModel):
|
|
|
73
71
|
options: List[str]
|
|
74
72
|
|
|
75
73
|
class MCGenerationResponse(BaseModel):
|
|
76
|
-
agent_id: uuid.UUID
|
|
77
74
|
question: str
|
|
78
75
|
options: List[str]
|
|
79
76
|
chosen_option: str
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# --- Survey Session Models ---
|
|
80
|
+
class ConversationTurn(BaseModel):
|
|
81
|
+
type: str # "qual" or "mc"
|
|
82
|
+
question: str
|
|
83
|
+
options: Optional[List[str]] = None
|
|
84
|
+
answer: Optional[str] = None
|
|
85
|
+
chosen_option: Optional[str] = None
|
|
86
|
+
timestamp: datetime
|
|
87
|
+
|
|
88
|
+
class SurveySessionCreateResponse(BaseModel):
|
|
89
|
+
id: uuid.UUID # Session ID
|
|
90
|
+
agent_id: uuid.UUID
|
|
91
|
+
created_at: datetime
|
|
92
|
+
status: str
|
|
93
|
+
|
|
94
|
+
class SurveySessionCloseResponse(BaseModel):
|
|
95
|
+
id: uuid.UUID # Session ID
|
|
96
|
+
status: str
|
|
97
|
+
updated_at: datetime
|
|
98
|
+
message: Optional[str] = None
|
simile/resources.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from typing import TYPE_CHECKING, List
|
|
3
|
+
|
|
4
|
+
from .models import (
|
|
5
|
+
QualGenerationRequest,
|
|
6
|
+
QualGenerationResponse,
|
|
7
|
+
MCGenerationRequest,
|
|
8
|
+
MCGenerationResponse,
|
|
9
|
+
SurveySessionCloseResponse
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from .client import Simile
|
|
14
|
+
|
|
15
|
+
class Agent:
|
|
16
|
+
"""Represents an agent and provides methods for interacting with it directly."""
|
|
17
|
+
def __init__(self, agent_id: uuid.UUID, client: 'Simile'):
|
|
18
|
+
self._agent_id = agent_id
|
|
19
|
+
self._client = client
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def id(self) -> uuid.UUID:
|
|
23
|
+
return self._agent_id
|
|
24
|
+
|
|
25
|
+
async def generate_qual_response(self, question: str) -> QualGenerationResponse:
|
|
26
|
+
"""Generates a qualitative response from this agent based on a question."""
|
|
27
|
+
return await self._client.generate_qual_response(agent_id=self._agent_id, question=question)
|
|
28
|
+
|
|
29
|
+
async def generate_mc_response(self, question: str, options: List[str]) -> MCGenerationResponse:
|
|
30
|
+
"""Generates a multiple-choice response from this agent."""
|
|
31
|
+
return await self._client.generate_mc_response(agent_id=self._agent_id, question=question, options=options)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class SurveySession:
|
|
35
|
+
"""Represents an active survey session with an agent, allowing for contextual multi-turn generation."""
|
|
36
|
+
def __init__(self, id: uuid.UUID, agent_id: uuid.UUID, status: str, client: 'Simile'):
|
|
37
|
+
self._id = id
|
|
38
|
+
self._agent_id = agent_id
|
|
39
|
+
self._status = status
|
|
40
|
+
self._client = client
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def id(self) -> uuid.UUID:
|
|
44
|
+
return self._id
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def agent_id(self) -> uuid.UUID:
|
|
48
|
+
return self._agent_id
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def status(self) -> str:
|
|
52
|
+
return self._status
|
|
53
|
+
|
|
54
|
+
async def generate_qual_response(self, question: str) -> QualGenerationResponse:
|
|
55
|
+
"""Generates a qualitative response within this survey session."""
|
|
56
|
+
endpoint = f"sessions/{str(self._id)}/qual"
|
|
57
|
+
payload = QualGenerationRequest(question=question)
|
|
58
|
+
return await self._client._request(
|
|
59
|
+
"POST",
|
|
60
|
+
endpoint,
|
|
61
|
+
json=payload.model_dump(),
|
|
62
|
+
response_model=QualGenerationResponse
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
async def generate_mc_response(self, question: str, options: List[str]) -> MCGenerationResponse:
|
|
66
|
+
"""Generates a multiple-choice response within this survey session."""
|
|
67
|
+
endpoint = f"sessions/{str(self._id)}/mc"
|
|
68
|
+
payload = MCGenerationRequest(question=question, options=options)
|
|
69
|
+
return await self._client._request(
|
|
70
|
+
"POST",
|
|
71
|
+
endpoint,
|
|
72
|
+
json=payload.model_dump(),
|
|
73
|
+
response_model=MCGenerationResponse
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
async def close(self) -> SurveySessionCloseResponse:
|
|
77
|
+
"""Closes this survey session on the server."""
|
|
78
|
+
endpoint = f"sessions/{str(self._id)}/close"
|
|
79
|
+
return await self._client._request(
|
|
80
|
+
"POST",
|
|
81
|
+
endpoint,
|
|
82
|
+
response_model=SurveySessionCloseResponse
|
|
83
|
+
)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simile
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Package for interfacing with Simile AI agents for simulation
|
|
5
5
|
Author-email: Simile AI <cqz@simile.ai>
|
|
6
|
-
License: MIT
|
|
6
|
+
License-Expression: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/simile-team/simile-sdk
|
|
8
8
|
Keywords: api,sdk,simile,ai-agent,simulation
|
|
9
9
|
Classifier: Development Status :: 3 - Alpha
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
simile/__init__.py,sha256=2OZ1LQIkAEtSs0EI5Fzlg7QGKduCgCe_nTh9FfIuHlQ,865
|
|
2
|
+
simile/client.py,sha256=rBXGfuD1kMlzHCXaqaPNzuzoqqDe5tTWH28Szg6DMCI,8534
|
|
3
|
+
simile/exceptions.py,sha256=-rJ3KZcpvNRi9JXbDpxWDSL2lU1mEJX2piwYRZvhKmg,1406
|
|
4
|
+
simile/models.py,sha256=bdvKNT10VlZHC51S5U1vpm2i-HV-2hVVeQZFOB-5jmQ,2104
|
|
5
|
+
simile/resources.py,sha256=n6TSuqEplO0Gyim-pqhrrxg8yPqsHWcFflOcZpd-uVo,2950
|
|
6
|
+
simile-0.2.2.dist-info/licenses/LICENSE,sha256=tpxX3bpODfyOQVyEM6kCMvPHFCpkjFDj0AICRqKqOFA,1066
|
|
7
|
+
simile-0.2.2.dist-info/METADATA,sha256=MCSE0Rjd8xR-WdsU3Igz0YLY6Bvh7NM64mC6T9753AA,1256
|
|
8
|
+
simile-0.2.2.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
9
|
+
simile-0.2.2.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
|
|
10
|
+
simile-0.2.2.dist-info/RECORD,,
|
simile-0.2.1.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
simile/__init__.py,sha256=2OZ1LQIkAEtSs0EI5Fzlg7QGKduCgCe_nTh9FfIuHlQ,865
|
|
2
|
-
simile/client.py,sha256=HjIwjUlkH2qVo67gcC1lwhqKQlzzTMNeLSZIKpLy36Y,7934
|
|
3
|
-
simile/exceptions.py,sha256=-rJ3KZcpvNRi9JXbDpxWDSL2lU1mEJX2piwYRZvhKmg,1406
|
|
4
|
-
simile/models.py,sha256=BV6n1zgXT1CyNSdwWd1ASm2llknC401aybrw6EtGXqM,1617
|
|
5
|
-
simile-0.2.1.dist-info/licenses/LICENSE,sha256=tpxX3bpODfyOQVyEM6kCMvPHFCpkjFDj0AICRqKqOFA,1066
|
|
6
|
-
simile-0.2.1.dist-info/METADATA,sha256=ee9w-3KBLIaH3fukxpvY65Tayoboj4kOeRxXwoO9zzI,1245
|
|
7
|
-
simile-0.2.1.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
8
|
-
simile-0.2.1.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
|
|
9
|
-
simile-0.2.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|