simile 0.1.0__py3-none-any.whl → 0.1.1__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/resource_agent.py +50 -20
- simile/resource_population.py +46 -14
- simile/task.py +5 -3
- {simile-0.1.0.dist-info → simile-0.1.1.dist-info}/METADATA +1 -1
- simile-0.1.1.dist-info/RECORD +13 -0
- simile-0.1.0.dist-info/RECORD +0 -13
- {simile-0.1.0.dist-info → simile-0.1.1.dist-info}/LICENSE +0 -0
- {simile-0.1.0.dist-info → simile-0.1.1.dist-info}/WHEEL +0 -0
- {simile-0.1.0.dist-info → simile-0.1.1.dist-info}/top_level.txt +0 -0
simile/resource_agent.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# simile/resource_agent.py
|
|
2
2
|
"""
|
|
3
|
-
Implements Agent-related methods
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
114
|
+
question_payload is a dict, e.g. { "question": "...", "options": [...] }
|
|
85
115
|
|
|
86
|
-
Returns
|
|
87
|
-
|
|
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
|
-
|
|
132
|
+
|
|
133
|
+
# Wait and return final data
|
|
134
|
+
final_data = Task(task_id, result_endpoint).wait()
|
|
135
|
+
return final_data
|
simile/resource_population.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# simile/resource_population.py
|
|
2
2
|
"""
|
|
3
|
-
Implements Population-related methods
|
|
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="
|
|
13
|
+
def create(name, read_permission="private", write_permission="private", readme=""):
|
|
13
14
|
"""
|
|
14
15
|
Synchronously create a population via POST /create_population/.
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
94
|
+
def get_sub_population(population_id="", n=1):
|
|
69
95
|
"""
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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", "/
|
|
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
|
|
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
|
-
#
|
|
86
|
-
|
|
87
|
-
return
|
|
117
|
+
# Wait for completion and return the final result
|
|
118
|
+
final_data = Task(task_id, result_endpoint).wait()
|
|
119
|
+
return final_data
|
simile/task.py
CHANGED
|
@@ -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(
|
|
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":
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
simile/__init__.py,sha256=ru0KrsAf-hMJLigoRePoGt8rIA_q8GAaq5FgO42RD-U,1193
|
|
2
|
+
simile/api_requestor.py,sha256=03SWFV5Nrc9w-4ZCJ29hWTJSN8paR26isTLLrwL0h_0,1546
|
|
3
|
+
simile/config.py,sha256=q9twMCyF7jmzxWI0u1KDEXY-MBhHzcy3EiggwzAl-wU,624
|
|
4
|
+
simile/error.py,sha256=Kw6qAtqp1xugiRmA0PuX5q8Rq_RoeP7c7nXuepD86Dk,377
|
|
5
|
+
simile/resource_agent.py,sha256=ZwFYRfRTIxjMFwZ8eFHMgArzFt8MJIUl7DTmhVrBtPU,4579
|
|
6
|
+
simile/resource_population.py,sha256=SHyyBNfuwdrLtOdhLLVUyAs_8y-hs1sPcE6kbWjwWBA,4011
|
|
7
|
+
simile/task.py,sha256=Fn40AHX5FYRDuGdIzWMtMOAjI5O_GHkFpE-li5Cpwck,2737
|
|
8
|
+
simile/utils.py,sha256=1m3IIUY4kGOsy3nMijGWXVqy6MFekEl2IvSsaevNARQ,195
|
|
9
|
+
simile-0.1.1.dist-info/LICENSE,sha256=SwJ_Xw9Vk_7LCC8ttVixbpNxJumTBv04H_gizLbDjkc,1071
|
|
10
|
+
simile-0.1.1.dist-info/METADATA,sha256=klrHynWpxXPIS8I4vLaqwDvlsIVuUvFybfP3Wr2rud4,1421
|
|
11
|
+
simile-0.1.1.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
12
|
+
simile-0.1.1.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
|
|
13
|
+
simile-0.1.1.dist-info/RECORD,,
|
simile-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
simile/__init__.py,sha256=ru0KrsAf-hMJLigoRePoGt8rIA_q8GAaq5FgO42RD-U,1193
|
|
2
|
-
simile/api_requestor.py,sha256=03SWFV5Nrc9w-4ZCJ29hWTJSN8paR26isTLLrwL0h_0,1546
|
|
3
|
-
simile/config.py,sha256=q9twMCyF7jmzxWI0u1KDEXY-MBhHzcy3EiggwzAl-wU,624
|
|
4
|
-
simile/error.py,sha256=Kw6qAtqp1xugiRmA0PuX5q8Rq_RoeP7c7nXuepD86Dk,377
|
|
5
|
-
simile/resource_agent.py,sha256=DJC61cV2FoxaH6wZaluUiFCnZgzEoiJ07aqNShpqiCM,3701
|
|
6
|
-
simile/resource_population.py,sha256=o7jx6HcoimZkz4ATsN1_KN5sufKaTog1trpHsc5LXB8,3153
|
|
7
|
-
simile/task.py,sha256=TDC797_0L6YdsDadn91qdGqYzTgZyAURrVWwbNXm9hU,2656
|
|
8
|
-
simile/utils.py,sha256=1m3IIUY4kGOsy3nMijGWXVqy6MFekEl2IvSsaevNARQ,195
|
|
9
|
-
simile-0.1.0.dist-info/LICENSE,sha256=SwJ_Xw9Vk_7LCC8ttVixbpNxJumTBv04H_gizLbDjkc,1071
|
|
10
|
-
simile-0.1.0.dist-info/METADATA,sha256=26D9jmP7X01XnQvJOuDRJ_qb7zSHJUPnq_fp_vFzTOU,1421
|
|
11
|
-
simile-0.1.0.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
|
12
|
-
simile-0.1.0.dist-info/top_level.txt,sha256=41lJneubAG4-ZOAs5qn7iDtDb-MDxa6DdvgBKwNX84M,7
|
|
13
|
-
simile-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|