simile 0.1.0__tar.gz → 0.1.1__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.2
2
2
  Name: simile
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A Python client library for interacting with my Agent & Population endpoints
5
5
  Home-page: https://github.com/simile-team/simile
6
6
  Author: Joon Sung Park
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="simile", # Replace with your desired package name
8
- version="0.1.0",
8
+ version="0.1.1",
9
9
  author="Joon Sung Park",
10
10
  author_email="joon.s.pk@gmail.com",
11
11
  description="A Python client library for interacting with my Agent & Population endpoints",
@@ -1,6 +1,7 @@
1
1
  # simile/resource_agent.py
2
2
  """
3
- Implements Agent-related methods analogous to how you might use openai.Completion or similar classes.
3
+ Implements Agent-related methods.
4
+ We now hide async calls by automatically waiting on tasks.
4
5
  """
5
6
 
6
7
  from .api_requestor import request
@@ -15,22 +16,41 @@ class Agent:
15
16
  forked_agent_id="",
16
17
  speech_pattern="",
17
18
  self_description="",
18
- population_id="",
19
+ population_id=None,
19
20
  read_permission="private",
20
21
  write_permission="private",
21
22
  agent_data=None
22
23
  ):
23
24
  """
24
- Asynchronously create an agent via POST /create_single_agent/
25
- Returns a Task object that you can poll or wait on.
26
-
27
- Usage:
28
- from simile import Agent
29
- task = Agent.create("John", "Doe")
30
- # block until done:
31
- result = task.wait() # => {"agent_id": "..."}
32
- new_agent_id = result["agent_id"]
25
+ Creates a new agent (blocking call).
26
+
27
+ * first_name (required)
28
+ * last_name (required)
29
+ * population_id (required)
30
+ * read_permission (default: 'private')
31
+ * write_permission (default: 'private')
32
+
33
+ This function will not return until the creation is fully done server-side.
34
+
35
+ Returns:
36
+ agent_id (str): The new agent's unique ID.
37
+
38
+ Raises:
39
+ ValueError if required fields are missing.
40
+ RequestError if the server returns an error.
33
41
  """
42
+ # Validate required fields
43
+ if not first_name:
44
+ raise ValueError("first_name is required.")
45
+ if not last_name:
46
+ raise ValueError("last_name is required.")
47
+ if not population_id:
48
+ raise ValueError("population_id is required.")
49
+ if not read_permission:
50
+ raise ValueError("read_permission is required.")
51
+ if not write_permission:
52
+ raise ValueError("write_permission is required.")
53
+
34
54
  if agent_data is None:
35
55
  agent_data = []
36
56
 
@@ -46,6 +66,7 @@ class Agent:
46
66
  "agent_data": agent_data
47
67
  }
48
68
 
69
+ # Kick off the creation, which returns a task
49
70
  resp = request("POST", "/create_single_agent/", json=payload)
50
71
  data = resp.json()
51
72
  task_id = data.get("task_id")
@@ -54,7 +75,15 @@ class Agent:
54
75
 
55
76
  # The result endpoint is /create_single_agent_result/<task_id>/
56
77
  result_endpoint = "/create_single_agent_result/{task_id}/"
57
- return Task(task_id, result_endpoint)
78
+
79
+ # Wait for the task to finish
80
+ final_data = Task(task_id, result_endpoint).wait()
81
+ agent_id = final_data.get("agent_id")
82
+
83
+ if not agent_id:
84
+ raise RequestError("No 'agent_id' returned in final result.")
85
+
86
+ return agent_id
58
87
 
59
88
  @staticmethod
60
89
  def retrieve_details(agent_id):
@@ -79,15 +108,13 @@ class Agent:
79
108
  @staticmethod
80
109
  def generate_response(agent_id, question_type, question_payload):
81
110
  """
82
- Asynchronously generate an agent's response via /generate_agent_response/.
111
+ Generates an agent's response (blocking call).
112
+
83
113
  question_type can be 'categorical', 'numerical', or 'chat'.
84
- question_payload is a dict. E.g. { "question": "...", "options": [...] }, etc.
114
+ question_payload is a dict, e.g. { "question": "...", "options": [...] }
85
115
 
86
- Returns a Task object for polling or waiting.
87
- Usage:
88
- from simile import Agent
89
- task = Agent.generate_response("a_123", "chat", {...})
90
- result = task.wait()
116
+ Returns:
117
+ The final result from the server once the async task completes.
91
118
  """
92
119
  payload = {
93
120
  "agent_id": agent_id,
@@ -102,4 +129,7 @@ class Agent:
102
129
 
103
130
  # The result endpoint is /generate_agent_response_result/<task_id>/
104
131
  result_endpoint = "/generate_agent_response_result/{task_id}/"
105
- return Task(task_id, result_endpoint)
132
+
133
+ # Wait and return final data
134
+ final_data = Task(task_id, result_endpoint).wait()
135
+ return final_data
@@ -1,6 +1,7 @@
1
1
  # simile/resource_population.py
2
2
  """
3
- Implements Population-related methods: create, get_agents, add_agent, remove_agent, delete, etc.
3
+ Implements Population-related methods.
4
+ Some are synchronous; get_sub_population is async but we now hide the wait.
4
5
  """
5
6
 
6
7
  from .api_requestor import request
@@ -9,12 +10,37 @@ from .error import RequestError
9
10
 
10
11
  class Population:
11
12
  @staticmethod
12
- def create(name="New Population"):
13
+ def create(name, read_permission="private", write_permission="private", readme=""):
13
14
  """
14
15
  Synchronously create a population via POST /create_population/.
15
- Returns a dict { "status": "success", "population_id": "..." } or raises an error.
16
+
17
+ Required fields:
18
+ - name
19
+ - read_permission
20
+ - write_permission
21
+ Optional:
22
+ - readme
23
+
24
+ Returns:
25
+ {
26
+ "status": "success",
27
+ "population_id": "..."
28
+ }
29
+ or raises an error.
16
30
  """
17
- payload = {"name": name}
31
+ if not name:
32
+ raise ValueError("name is required.")
33
+ if not read_permission:
34
+ raise ValueError("read_permission is required.")
35
+ if not write_permission:
36
+ raise ValueError("write_permission is required.")
37
+
38
+ payload = {
39
+ "name": name,
40
+ "read_permission": read_permission,
41
+ "write_permission": write_permission,
42
+ "readme": readme
43
+ }
18
44
  resp = request("POST", "/create_population/", json=payload)
19
45
  return resp.json()
20
46
 
@@ -65,23 +91,29 @@ class Population:
65
91
  return resp.json()
66
92
 
67
93
  @staticmethod
68
- def create_sub_population(population_id="", n=1):
94
+ def get_sub_population(population_id="", n=1):
69
95
  """
70
- Asynchronously create a sub-population by sampling from an existing population
71
- or from all agents if no population_id is given.
72
- Endpoint: POST /create_sub_population/
73
- Returns a Task object. On success, final data should have "new_population_id".
96
+ Initiates a sub-population retrieval/generation (blocking call) by sampling
97
+ from an existing population (if population_id is provided) or from all
98
+ agents if no population_id is given.
99
+
100
+ Endpoint: POST /get_sub_population/
101
+ Waits until the async task completes, then returns final result, typically
102
+ containing "new_population_id".
74
103
  """
75
104
  payload = {
76
105
  "population_id": population_id,
77
106
  "n": n
78
107
  }
79
- resp = request("POST", "/create_sub_population/", json=payload)
108
+ resp = request("POST", "/get_sub_population/", json=payload)
80
109
  data = resp.json()
81
110
  task_id = data.get("task_id")
82
111
  if not task_id:
83
- raise RequestError("No 'task_id' returned from create_sub_population endpoint.")
112
+ raise RequestError("No 'task_id' returned from get_sub_population endpoint.")
113
+
114
+ # The result endpoint is /get_sub_population_result/<task_id>/
115
+ result_endpoint = "/get_sub_population_result/{task_id}/"
84
116
 
85
- # The result endpoint is /create_sub_population_result/<task_id>/
86
- result_endpoint = "/create_sub_population_result/{task_id}/"
87
- return Task(task_id, result_endpoint)
117
+ # Wait for completion and return the final result
118
+ final_data = Task(task_id, result_endpoint).wait()
119
+ return final_data
@@ -6,6 +6,7 @@ class Task:
6
6
  """
7
7
  Represents an asynchronous Celery-like task.
8
8
  Contains logic for polling the result endpoint until completion or failure.
9
+ Used internally to hide the async nature from the end user.
9
10
  """
10
11
  def __init__(self, task_id, result_endpoint):
11
12
  self.task_id = task_id
@@ -55,8 +56,7 @@ class Task:
55
56
  self._finished = True
56
57
  self._last_result = data.get("error")
57
58
  else:
58
- # Some other custom statuses
59
- # We'll treat them like "still running"
59
+ # Some other custom statuses are treated as "still running"
60
60
  pass
61
61
 
62
62
  def wait(self, interval=2, timeout=300):
@@ -70,7 +70,9 @@ class Task:
70
70
  if self._finished:
71
71
  break
72
72
  if time.time() - start > timeout:
73
- raise TimeoutError(f"Task {self.task_id} did not complete within {timeout} seconds.")
73
+ raise TimeoutError(
74
+ f"Task {self.task_id} did not complete within {timeout} seconds."
75
+ )
74
76
  time.sleep(interval)
75
77
 
76
78
  if self._last_status == "SUCCESS":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: simile
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A Python client library for interacting with my Agent & Population endpoints
5
5
  Home-page: https://github.com/simile-team/simile
6
6
  Author: Joon Sung Park
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