AsynchronousCommunicator¶
synapseclient.models.mixins.AsynchronousCommunicator
¶
Mixin to handle communication with the Synapse Asynchronous Job service.
Source code in synapseclient/models/mixins/asynchronous_job.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
Methods:¶
send_job_and_wait_async
async
¶
send_job_and_wait_async(post_exchange_args: Optional[Dict[str, Any]] = None, timeout: int = 120, *, synapse_client: Optional[Synapse] = None) -> Self
Send the job to the Asynchronous Job service and wait for it to complete. Intended to be called by a class inheriting from this mixin to start a job in the Synapse API and wait for it to complete. The inheriting class needs to represent an asynchronous job request and response and include all necessary attributes. This was initially implemented to be used in the AgentPrompt class which can be used as an example.
| PARAMETER | DESCRIPTION |
|---|---|
post_exchange_args
|
Additional arguments to pass to the request. |
timeout
|
The number of seconds to wait for the job to complete or progress before raising a SynapseTimeoutError. Defaults to 120.
TYPE:
|
synapse_client
|
If not passed in and caching was not disabled by
|
| RETURNS | DESCRIPTION |
|---|---|
Self
|
An instance of this class. |
Using this function
This function was initially implemented to be used in the AgentPrompt class to send a prompt to an AI agent and wait for the response. It can also be used in any other class that needs to use an Asynchronous Job.
The inheriting class (AgentPrompt) will typically not be used directly, but rather through a higher level class (AgentSession), but this example shows how you would use this function.
from synapseclient import Synapse
from synapseclient.models.agent import AgentPrompt
syn = Synapse()
syn.login()
agent_prompt = AgentPrompt(
id=None,
session_id="123",
prompt="Hello",
response=None,
enable_trace=True,
trace=None,
)
# This will fill the id, response, and trace
# attributes with the response from the API
agent_prompt.send_job_and_wait_async()
Source code in synapseclient/models/mixins/asynchronous_job.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |