simile 0.2.15__py3-none-any.whl → 0.3.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/__init__.py CHANGED
@@ -4,10 +4,10 @@ from .models import (
4
4
  Population, Agent, DataItem,
5
5
  CreatePopulationPayload, CreateAgentPayload, CreateDataItemPayload, UpdateDataItemPayload,
6
6
  DeletionResponse,
7
- QualGenerationRequest,
8
- QualGenerationResponse,
9
- MCGenerationRequest,
10
- MCGenerationResponse
7
+ OpenGenerationRequest,
8
+ OpenGenerationResponse,
9
+ ClosedGenerationRequest,
10
+ ClosedGenerationResponse
11
11
  )
12
12
  from .exceptions import (
13
13
  SimileAPIError,
@@ -22,9 +22,9 @@ __all__ = [
22
22
  "Population", "Agent", "DataItem",
23
23
  "CreatePopulationPayload", "CreateAgentPayload", "CreateDataItemPayload", "UpdateDataItemPayload",
24
24
  "DeletionResponse",
25
- "QualGenerationRequest", "QualGenerationResponse",
26
- "MCGenerationRequest", "MCGenerationResponse",
25
+ "OpenGenerationRequest", "OpenGenerationResponse",
26
+ "ClosedGenerationRequest", "ClosedGenerationResponse",
27
27
  "SimileAPIError", "SimileAuthenticationError", "SimileNotFoundError", "SimileBadRequestError"
28
28
  ]
29
29
 
30
- __version__ = "0.2.13"
30
+ __version__ = "0.2.15"
simile/client.py CHANGED
@@ -9,10 +9,10 @@ from .models import (
9
9
  Agent as AgentModel,
10
10
  DataItem,
11
11
  DeletionResponse,
12
- QualGenerationRequest,
13
- QualGenerationResponse,
14
- MCGenerationRequest,
15
- MCGenerationResponse,
12
+ OpenGenerationRequest,
13
+ OpenGenerationResponse,
14
+ ClosedGenerationRequest,
15
+ ClosedGenerationResponse,
16
16
  CreatePopulationPayload,
17
17
  CreateAgentPayload,
18
18
  CreateDataItemPayload,
@@ -279,17 +279,17 @@ class Simile:
279
279
  )
280
280
  return response_data
281
281
 
282
- async def generate_qual_response(
282
+ async def generate_open_response(
283
283
  self,
284
284
  agent_id: uuid.UUID,
285
285
  question: str,
286
286
  data_types: Optional[List[str]] = None,
287
287
  exclude_data_types: Optional[List[str]] = None,
288
288
  images: Optional[Dict[str, str]] = None,
289
- ) -> QualGenerationResponse:
290
- """Generates a qualitative response from an agent based on a question."""
291
- endpoint = f"/generation/qual/{str(agent_id)}"
292
- request_payload = QualGenerationRequest(
289
+ ) -> OpenGenerationResponse:
290
+ """Generates an open response from an agent based on a question."""
291
+ endpoint = f"/generation/open/{str(agent_id)}"
292
+ request_payload = OpenGenerationRequest(
293
293
  question=question,
294
294
  data_types=data_types,
295
295
  exclude_data_types=exclude_data_types,
@@ -299,11 +299,11 @@ class Simile:
299
299
  "POST",
300
300
  endpoint,
301
301
  json=request_payload.model_dump(),
302
- response_model=QualGenerationResponse,
302
+ response_model=OpenGenerationResponse,
303
303
  )
304
304
  return response_data
305
305
 
306
- async def generate_mc_response(
306
+ async def generate_closed_response(
307
307
  self,
308
308
  agent_id: uuid.UUID,
309
309
  question: str,
@@ -311,10 +311,10 @@ class Simile:
311
311
  data_types: Optional[List[str]] = None,
312
312
  exclude_data_types: Optional[List[str]] = None,
313
313
  images: Optional[Dict[str, str]] = None,
314
- ) -> MCGenerationResponse:
315
- """Generates a multiple-choice response from an agent."""
316
- endpoint = f"generation/mc/{str(agent_id)}"
317
- request_payload = MCGenerationRequest(
314
+ ) -> ClosedGenerationResponse:
315
+ """Generates a closed response from an agent."""
316
+ endpoint = f"generation/closed/{str(agent_id)}"
317
+ request_payload = ClosedGenerationRequest(
318
318
  question=question,
319
319
  options=options,
320
320
  data_types=data_types,
@@ -325,7 +325,7 @@ class Simile:
325
325
  "POST",
326
326
  endpoint,
327
327
  json=request_payload.model_dump(),
328
- response_model=MCGenerationResponse,
328
+ response_model=ClosedGenerationResponse,
329
329
  )
330
330
  return response_data
331
331
 
simile/models.py CHANGED
@@ -61,7 +61,7 @@ class DeletionResponse(BaseModel):
61
61
 
62
62
 
63
63
  # --- Generation Operation Models ---
64
- class QualGenerationRequest(BaseModel):
64
+ class OpenGenerationRequest(BaseModel):
65
65
  question: str
66
66
  data_types: Optional[List[str]] = None
67
67
  exclude_data_types: Optional[List[str]] = None
@@ -70,12 +70,12 @@ class QualGenerationRequest(BaseModel):
70
70
  )
71
71
 
72
72
 
73
- class QualGenerationResponse(BaseModel):
73
+ class OpenGenerationResponse(BaseModel):
74
74
  question: str
75
75
  answer: str
76
76
 
77
77
 
78
- class MCGenerationRequest(BaseModel):
78
+ class ClosedGenerationRequest(BaseModel):
79
79
  question: str
80
80
  options: List[str]
81
81
  data_types: Optional[List[str]] = None
@@ -83,10 +83,10 @@ class MCGenerationRequest(BaseModel):
83
83
  images: Optional[Dict[str, str]] = None
84
84
 
85
85
 
86
- class MCGenerationResponse(BaseModel):
86
+ class ClosedGenerationResponse(BaseModel):
87
87
  question: str
88
88
  options: List[str]
89
- chosen_option: str
89
+ response: str
90
90
 
91
91
 
92
92
  class AddContextRequest(BaseModel):
@@ -104,8 +104,8 @@ class TurnType(str, Enum):
104
104
 
105
105
  CONTEXT = "context"
106
106
  IMAGE = "image"
107
- QUALITATIVE_QUESTION = "qualitative_question"
108
- MULTIPLE_CHOICE_QUESTION = "multiple_choice_question"
107
+ OPEN_QUESTION = "open_question"
108
+ CLOSED_QUESTION = "closed_question"
109
109
 
110
110
 
111
111
  class BaseTurn(BaseModel):
@@ -133,48 +133,48 @@ class ImageTurn(BaseTurn):
133
133
  caption: Optional[str] = None
134
134
 
135
135
 
136
- class QualitativeQuestionTurn(BaseTurn):
137
- """A qualitative question-answer turn."""
136
+ class OpenQuestionTurn(BaseTurn):
137
+ """An open question-answer turn."""
138
138
 
139
- type: Literal[TurnType.QUALITATIVE_QUESTION] = TurnType.QUALITATIVE_QUESTION
139
+ type: Literal[TurnType.OPEN_QUESTION] = TurnType.OPEN_QUESTION
140
140
  user_question: str
141
141
  user_images: Optional[Dict[str, str]] = None
142
142
  llm_response: Optional[str] = None
143
143
 
144
144
 
145
- class MultipleChoiceQuestionTurn(BaseTurn):
146
- """A multiple choice question-answer turn."""
145
+ class ClosedQuestionTurn(BaseTurn):
146
+ """A closed question-answer turn."""
147
147
 
148
- type: Literal[TurnType.MULTIPLE_CHOICE_QUESTION] = TurnType.MULTIPLE_CHOICE_QUESTION
148
+ type: Literal[TurnType.CLOSED_QUESTION] = TurnType.CLOSED_QUESTION
149
149
  user_question: str
150
150
  user_options: List[str]
151
151
  user_images: Optional[Dict[str, str]] = None
152
- llm_chosen_option: Optional[str] = None
152
+ llm_response: Optional[str] = None
153
153
 
154
154
  @validator("user_options")
155
155
  def validate_options(cls, v):
156
156
  if not v:
157
- raise ValueError("Multiple choice questions must have at least one option")
157
+ raise ValueError("Closed questions must have at least one option")
158
158
  if len(v) < 2:
159
159
  raise ValueError(
160
- "Multiple choice questions should have at least two options"
160
+ "Closed questions should have at least two options"
161
161
  )
162
162
  return v
163
163
 
164
- @validator("llm_chosen_option")
165
- def validate_chosen_option(cls, v, values):
164
+ @validator("llm_response")
165
+ def validate_response(cls, v, values):
166
166
  if (
167
167
  v is not None
168
168
  and "user_options" in values
169
169
  and v not in values["user_options"]
170
170
  ):
171
- raise ValueError(f"Chosen option '{v}' must be one of the provided options")
171
+ raise ValueError(f"Response '{v}' must be one of the provided options")
172
172
  return v
173
173
 
174
174
 
175
175
  # Union type for all possible turn types
176
176
  SurveySessionTurn = Union[
177
- ContextTurn, ImageTurn, QualitativeQuestionTurn, MultipleChoiceQuestionTurn
177
+ ContextTurn, ImageTurn, OpenQuestionTurn, ClosedQuestionTurn
178
178
  ]
179
179
 
180
180
 
simile/resources.py CHANGED
@@ -2,14 +2,15 @@ import uuid
2
2
  from typing import TYPE_CHECKING, List, Optional, Dict
3
3
 
4
4
  from .models import (
5
- QualGenerationRequest,
6
- QualGenerationResponse,
7
- MCGenerationRequest,
8
- MCGenerationResponse,
5
+ OpenGenerationRequest,
6
+ OpenGenerationResponse,
7
+ ClosedGenerationRequest,
8
+ ClosedGenerationResponse,
9
9
  SurveySessionCloseResponse,
10
10
  AddContextRequest,
11
11
  AddContextResponse,
12
12
  SurveySessionDetailResponse,
13
+ SurveySessionCreateResponse,
13
14
  )
14
15
 
15
16
  if TYPE_CHECKING:
@@ -27,15 +28,15 @@ class Agent:
27
28
  def id(self) -> uuid.UUID:
28
29
  return self._agent_id
29
30
 
30
- async def generate_qual_response(
31
+ async def generate_open_response(
31
32
  self,
32
33
  question: str,
33
34
  data_types: Optional[List[str]] = None,
34
35
  exclude_data_types: Optional[List[str]] = None,
35
36
  images: Optional[Dict[str, str]] = None,
36
- ) -> QualGenerationResponse:
37
- """Generates a qualitative response from this agent based on a question."""
38
- return await self._client.generate_qual_response(
37
+ ) -> OpenGenerationResponse:
38
+ """Generates an open response from this agent based on a question."""
39
+ return await self._client.generate_open_response(
39
40
  agent_id=self._agent_id,
40
41
  question=question,
41
42
  data_types=data_types,
@@ -43,16 +44,16 @@ class Agent:
43
44
  images=images,
44
45
  )
45
46
 
46
- async def generate_mc_response(
47
+ async def generate_closed_response(
47
48
  self,
48
49
  question: str,
49
50
  options: List[str],
50
51
  data_types: Optional[List[str]] = None,
51
52
  exclude_data_types: Optional[List[str]] = None,
52
53
  images: Optional[Dict[str, str]] = None,
53
- ) -> MCGenerationResponse:
54
- """Generates a multiple-choice response from this agent."""
55
- return await self._client.generate_mc_response(
54
+ ) -> ClosedGenerationResponse:
55
+ """Generates a closed response from this agent."""
56
+ return await self._client.generate_closed_response(
56
57
  agent_id=self._agent_id,
57
58
  question=question,
58
59
  options=options,
@@ -88,17 +89,21 @@ class SurveySession:
88
89
  async def get_details(self) -> SurveySessionDetailResponse:
89
90
  """Retrieves detailed information about this survey session including typed conversation history."""
90
91
  return await self._client.get_survey_session_details(self._id)
92
+
93
+ async def view(self) -> SurveySessionDetailResponse:
94
+ """Alias for get_details() - retrieves all turns in this session."""
95
+ return await self.get_details()
91
96
 
92
- async def generate_qual_response(
97
+ async def generate_open_response(
93
98
  self,
94
99
  question: str,
95
100
  data_types: Optional[List[str]] = None,
96
101
  exclude_data_types: Optional[List[str]] = None,
97
102
  images: Optional[Dict[str, str]] = None,
98
- ) -> QualGenerationResponse:
99
- """Generates a qualitative response within this survey session."""
100
- endpoint = f"sessions/{str(self._id)}/qual"
101
- payload = QualGenerationRequest(
103
+ ) -> OpenGenerationResponse:
104
+ """Generates an open response within this survey session."""
105
+ endpoint = f"sessions/{str(self._id)}/open"
106
+ payload = OpenGenerationRequest(
102
107
  question=question,
103
108
  data_types=data_types,
104
109
  exclude_data_types=exclude_data_types,
@@ -108,20 +113,20 @@ class SurveySession:
108
113
  "POST",
109
114
  endpoint,
110
115
  json=payload.model_dump(),
111
- response_model=QualGenerationResponse,
116
+ response_model=OpenGenerationResponse,
112
117
  )
113
118
 
114
- async def generate_mc_response(
119
+ async def generate_closed_response(
115
120
  self,
116
121
  question: str,
117
122
  options: List[str],
118
123
  data_types: Optional[List[str]] = None,
119
124
  exclude_data_types: Optional[List[str]] = None,
120
125
  images: Optional[Dict[str, str]] = None,
121
- ) -> MCGenerationResponse:
122
- """Generates a multiple-choice response within this survey session."""
123
- endpoint = f"sessions/{str(self._id)}/mc"
124
- payload = MCGenerationRequest(
126
+ ) -> ClosedGenerationResponse:
127
+ """Generates a closed response within this survey session."""
128
+ endpoint = f"sessions/{str(self._id)}/closed"
129
+ payload = ClosedGenerationRequest(
125
130
  question=question,
126
131
  options=options,
127
132
  data_types=data_types,
@@ -132,7 +137,7 @@ class SurveySession:
132
137
  "POST",
133
138
  endpoint,
134
139
  json=payload.model_dump(),
135
- response_model=MCGenerationResponse,
140
+ response_model=ClosedGenerationResponse,
136
141
  )
137
142
 
138
143
  async def add_context(self, ctx: str) -> AddContextResponse:
@@ -146,6 +151,98 @@ class SurveySession:
146
151
  response_model=AddContextResponse,
147
152
  )
148
153
 
154
+ async def add_context_with_timestamp(
155
+ self,
156
+ context_text: str,
157
+ timestamp: str,
158
+ ) -> Dict:
159
+ """Adds context to this session with a specific timestamp.
160
+
161
+ This is a lower-level method that allows specifying when the context was added.
162
+ For normal use, prefer the add_context() method.
163
+
164
+ Args:
165
+ context_text: The context text to add
166
+ timestamp: ISO timestamp of when this interaction occurred
167
+
168
+ Returns:
169
+ Dictionary with success status and the added turn details
170
+ """
171
+ endpoint = f"sessions/{str(self._id)}/add-turn"
172
+ payload = {
173
+ "turn_type": "context",
174
+ "context_text": context_text,
175
+ "timestamp": timestamp,
176
+ }
177
+
178
+ return await self._client._request(
179
+ "POST",
180
+ endpoint,
181
+ json=payload,
182
+ response_model=None, # Return raw dict since we don't have a specific model
183
+ )
184
+
185
+ async def add_images(
186
+ self,
187
+ images: Dict[str, str],
188
+ timestamp: Optional[str] = None,
189
+ ) -> Dict:
190
+ """Adds images to the session's conversation history.
191
+
192
+ Args:
193
+ images: Dictionary mapping image descriptions to URLs
194
+ timestamp: Optional ISO timestamp of when this interaction occurred
195
+
196
+ Returns:
197
+ Dictionary with success status and the added turn details
198
+ """
199
+ endpoint = f"sessions/{str(self._id)}/add-turn"
200
+ payload = {
201
+ "turn_type": "image",
202
+ "images": images,
203
+ }
204
+ if timestamp:
205
+ payload["timestamp"] = timestamp
206
+
207
+ return await self._client._request(
208
+ "POST",
209
+ endpoint,
210
+ json=payload,
211
+ response_model=None, # Return raw dict since we don't have a specific model
212
+ )
213
+
214
+ async def add_open_response(
215
+ self,
216
+ question: str,
217
+ response: str,
218
+ timestamp: Optional[str] = None,
219
+ ) -> Dict:
220
+ """Adds an open question-answer pair to the session's history.
221
+
222
+ Args:
223
+ question: The open question text
224
+ response: The response that was given
225
+ timestamp: Optional ISO timestamp of when this interaction occurred
226
+
227
+ Returns:
228
+ Dictionary with success status and the added turn details
229
+ """
230
+ endpoint = f"sessions/{str(self._id)}/add-turn"
231
+ payload = {
232
+ "turn_type": "open",
233
+ "question": question,
234
+ "response": response,
235
+ }
236
+ if timestamp:
237
+ payload["timestamp"] = timestamp
238
+
239
+ return await self._client._request(
240
+ "POST",
241
+ endpoint,
242
+ json=payload,
243
+ response_model=None, # Return raw dict since we don't have a specific model
244
+ )
245
+
149
246
  async def close(self) -> SurveySessionCloseResponse:
150
247
  """Closes this survey session on the server."""
151
248
  endpoint = f"sessions/{str(self._id)}/close"
@@ -153,36 +250,30 @@ class SurveySession:
153
250
  "POST", endpoint, response_model=SurveySessionCloseResponse
154
251
  )
155
252
 
156
- async def add_historical_mc_turn(
253
+ async def add_closed_response(
157
254
  self,
158
255
  question: str,
159
256
  options: List[str],
160
- chosen_option: str,
257
+ response: str,
161
258
  timestamp: Optional[str] = None,
162
259
  ) -> Dict:
163
- """Adds a historical multiple choice turn to this session with a pre-specified answer.
164
-
165
- This method allows you to add a multiple choice question-answer pair to the session's
166
- conversation history without generating a new response. This is useful for recreating
167
- conversation history or adding context from previous interactions.
260
+ """Adds a closed question-answer pair to the session's history.
168
261
 
169
262
  Args:
170
- question: The multiple choice question text
263
+ question: The closed question text
171
264
  options: List of answer options
172
- chosen_option: The option that was selected
265
+ response: The option that was selected
173
266
  timestamp: Optional ISO timestamp of when this interaction occurred
174
267
 
175
268
  Returns:
176
269
  Dictionary with success status and the added turn details
177
-
178
- Raises:
179
- Simile.APIError: If the API request fails
180
270
  """
181
271
  endpoint = f"sessions/{str(self._id)}/add-turn"
182
272
  payload = {
273
+ "turn_type": "closed",
183
274
  "question": question,
184
275
  "options": options,
185
- "chosen_option": chosen_option,
276
+ "response": response,
186
277
  }
187
278
  if timestamp:
188
279
  payload["timestamp"] = timestamp
@@ -193,3 +284,37 @@ class SurveySession:
193
284
  json=payload,
194
285
  response_model=None, # Return raw dict since we don't have a specific model
195
286
  )
287
+
288
+
289
+ async def fork(self, turn_index: int) -> "SurveySession":
290
+ """Fork this session at a specific turn.
291
+
292
+ Creates a new session with the same agent and copies turns from this session
293
+ up to and including the specified turn index.
294
+
295
+ Args:
296
+ turn_index: The 0-based index of the last turn to include in the fork
297
+
298
+ Returns:
299
+ A new SurveySession object representing the forked session
300
+
301
+ Raises:
302
+ Simile.APIError: If the API request fails
303
+ """
304
+ endpoint = f"sessions/{str(self._id)}/fork"
305
+ params = {"turn_index": turn_index}
306
+
307
+ response = await self._client._request(
308
+ "POST",
309
+ endpoint,
310
+ params=params,
311
+ response_model=SurveySessionCreateResponse,
312
+ )
313
+
314
+ # Create a new SurveySession instance from the response
315
+ return SurveySession(
316
+ id=response.id,
317
+ agent_id=response.agent_id,
318
+ status=response.status,
319
+ client=self._client,
320
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simile
3
- Version: 0.2.15
3
+ Version: 0.3.2
4
4
  Summary: Package for interfacing with Simile AI agents for simulation
5
5
  Author-email: Simile AI <cqz@simile.ai>
6
6
  License: MIT
@@ -0,0 +1,11 @@
1
+ simile/__init__.py,sha256=gElQY-o-_BSigva3w9zIX2KuCR49OM3MpL8sqeUpKzk,936
2
+ simile/auth_client.py,sha256=ICImmaA5fZX9ADbIPIUh4RED3hBZvLf3XSiaqELDAME,7923
3
+ simile/client.py,sha256=2ZCNzT1j-wZoT0SanLcdO0FPQN6gToksLL5hkBCcc9E,12292
4
+ simile/exceptions.py,sha256=-rJ3KZcpvNRi9JXbDpxWDSL2lU1mEJX2piwYRZvhKmg,1406
5
+ simile/models.py,sha256=SOAqUpxkiZduDBuMooTaOjiLX_3bBolWn7ivj8A-MgY,5304
6
+ simile/resources.py,sha256=Juoa32SlN8LdvzCFaobq7uV2itmcwbk5dM_mlc4bCVk,10420
7
+ simile-0.3.2.dist-info/licenses/LICENSE,sha256=tpxX3bpODfyOQVyEM6kCMvPHFCpkjFDj0AICRqKqOFA,1066
8
+ simile-0.3.2.dist-info/METADATA,sha256=o-m8mOiHXeCCPzB7StUcPuPWNE9v-n2RG2mubGuu_5M,1276
9
+ simile-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ simile-0.3.2.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
11
+ simile-0.3.2.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- simile/__init__.py,sha256=qtWFBsMK2F1BNZ0V07fEb56fcuFOm48QcA4ne_s9t44,920
2
- simile/auth_client.py,sha256=ICImmaA5fZX9ADbIPIUh4RED3hBZvLf3XSiaqELDAME,7923
3
- simile/client.py,sha256=KumgPioNjR6UYNIT1MJipw3bMArPPNFnrluvHkw1eSw,12279
4
- simile/exceptions.py,sha256=-rJ3KZcpvNRi9JXbDpxWDSL2lU1mEJX2piwYRZvhKmg,1406
5
- simile/models.py,sha256=bdtXGM4K4x_bUTXRMf6DzGEtJRMgnofE9yy3OlA0qEQ,5448
6
- simile/resources.py,sha256=HWi2Fp32UBMqz7TQ9aA66Xs6mex7Olyz44TmfDOj_hc,6519
7
- simile-0.2.15.dist-info/licenses/LICENSE,sha256=tpxX3bpODfyOQVyEM6kCMvPHFCpkjFDj0AICRqKqOFA,1066
8
- simile-0.2.15.dist-info/METADATA,sha256=bZ6ThCzUNab_wKM7TJJ2pkoNtwe3_dqYJyIOLAS4fMg,1277
9
- simile-0.2.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
- simile-0.2.15.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
11
- simile-0.2.15.dist-info/RECORD,,