simile 0.2.1__tar.gz → 0.2.3__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simile
3
- Version: 0.2.1
3
+ Version: 0.2.3
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "simile"
7
- version = "0.2.1"
7
+ version = "0.2.3"
8
8
  authors = [
9
9
  { name="Simile AI", email="cqz@simile.ai" },
10
10
  ]
@@ -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
- DeletionResponse, QualGenerationRequest, QualGenerationResponse, MCGenerationRequest, MCGenerationResponse
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
- # --- Population Endpoints ---
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,31 @@ 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
- # --- Agent Endpoints ---
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 get_agents_in_population(self, population_id: Union[str, uuid.UUID]) -> List[AgentModel]:
105
+ """Retrieves all agents belonging to a specific population."""
106
+ endpoint = f"populations/{str(population_id)}/agents"
107
+ raw_response = await self._request("GET", endpoint)
108
+ agents_data_list = raw_response.model_dump_json()
109
+ return [AgentModel(**data) for data in agents_data_list]
110
+
111
+ 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
112
  """Creates a new agent, optionally within a population and with initial data items."""
85
- # Ensure population_id is uuid if provided
86
113
  pop_id_uuid: Optional[uuid.UUID] = None
87
114
  if population_id:
88
115
  pop_id_uuid = uuid.UUID(str(population_id)) if not isinstance(population_id, uuid.UUID) else population_id
89
116
 
90
117
  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=Agent)
118
+ response_data = await self._request("POST", "agents/create", json=payload.model_dump(mode='json', exclude_none=True), response_model=AgentModel)
92
119
  return response_data
93
120
 
94
- async def get_agent(self, agent_id: Union[str, uuid.UUID]) -> Agent:
95
- response_data = await self._request("GET", f"agents/get/{str(agent_id)}", response_model=Agent)
121
+ async def get_agent(self, agent_id: Union[str, uuid.UUID]) -> AgentModel:
122
+ response_data = await self._request("GET", f"agents/get/{str(agent_id)}", response_model=AgentModel)
96
123
  return response_data
97
124
 
98
125
  async def delete_agent(self, agent_id: Union[str, uuid.UUID]) -> DeletionResponse:
99
126
  response_data = await self._request("DELETE", f"agents/delete/{str(agent_id)}", response_model=DeletionResponse)
100
127
  return response_data
101
128
 
102
- # --- Data Item Endpoints ---
103
129
  async def create_data_item(self, agent_id: Union[str, uuid.UUID], data_type: str, content: Any) -> DataItem:
104
130
  """Creates a new data item for a specific agent."""
105
131
  payload = CreateDataItemPayload(data_type=data_type, content=content)
@@ -114,10 +140,9 @@ class Simile:
114
140
  params = {}
115
141
  if data_type:
116
142
  params["data_type"] = data_type
117
- # Ensure agent_id is string for URL
118
143
  agent_id_str = str(agent_id)
119
144
  raw_response = await self._request("GET", f"data_item/list/{agent_id_str}", params=params)
120
- return [DataItem(**item) for item in raw_response.json()]
145
+ return [DataItem(**item) for item in raw_response.model_dump_json()]
121
146
 
122
147
  async def update_data_item(self, data_item_id: Union[str, uuid.UUID], content: Any) -> DataItem:
123
148
  """Updates an existing data item."""
@@ -129,11 +154,10 @@ class Simile:
129
154
  response_data = await self._request("DELETE", f"data_item/delete/{str(data_item_id)}", response_model=DeletionResponse)
130
155
  return response_data
131
156
 
132
- # --- LLM Generation Methods ---
133
157
  async def generate_qual_response(self, agent_id: uuid.UUID, question: str) -> QualGenerationResponse:
134
158
  """Generates a qualitative response from an agent based on a question."""
135
159
  endpoint = f"/generation/qual/{str(agent_id)}"
136
- request_payload = QualGenerationRequest(question=question) # Create payload internally
160
+ request_payload = QualGenerationRequest(question=question)
137
161
  response_data = await self._request(
138
162
  "POST",
139
163
  endpoint,
@@ -144,9 +168,14 @@ class Simile:
144
168
 
145
169
  async def generate_mc_response(self, agent_id: uuid.UUID, question: str, options: List[str]) -> MCGenerationResponse:
146
170
  """Generates a multiple-choice response from an agent."""
147
- endpoint = f"generation/mc/{str(agent_id)}" # Ensured str(agent_id)
148
- request_payload = MCGenerationRequest(question=question, options=options) # Create payload internally
149
- response_data = await self._request("POST", endpoint, json=request_payload.model_dump(), response_model=MCGenerationResponse)
171
+ endpoint = f"generation/mc/{str(agent_id)}"
172
+ request_payload = MCGenerationRequest(question=question, options=options)
173
+ response_data = await self._request(
174
+ "POST",
175
+ endpoint,
176
+ json=request_payload.model_dump(),
177
+ response_model=MCGenerationResponse
178
+ )
150
179
  return response_data
151
180
 
152
181
  async def aclose(self):
@@ -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 # For initial data items
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
- # --- LLM Generation Models ---
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
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simile
3
- Version: 0.2.1
3
+ Version: 0.2.3
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
@@ -6,6 +6,7 @@ simile/__init__.py
6
6
  simile/client.py
7
7
  simile/exceptions.py
8
8
  simile/models.py
9
+ simile/resources.py
9
10
  simile.egg-info/PKG-INFO
10
11
  simile.egg-info/SOURCES.txt
11
12
  simile.egg-info/dependency_links.txt
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes