Skip to content

Commit

Permalink
split too long lines
Browse files Browse the repository at this point in the history
  • Loading branch information
BWMac committed Jan 17, 2025
1 parent 6d80b59 commit 89db642
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 52 deletions.
61 changes: 38 additions & 23 deletions synapseclient/models/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ class AgentSession(AgentSessionSynchronousProtocol):
"""Represents a [Synapse Agent Session](https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/agent/AgentSession.html)
Attributes:
id: The unique ID of the agent session. Can only be used by the user that created it.
id: The unique ID of the agent session.
Can only be used by the user that created it.
access_level: The access level of the agent session.
One of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or WRITE_YOUR_PRIVATE_DATA.
One of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA,
or WRITE_YOUR_PRIVATE_DATA.
started_on: The date the agent session was started.
started_by: The ID of the user who started the agent session.
modified_on: The date the agent session was last modified.
agent_registration_id: The registration ID of the agent that will be used for this session.
agent_registration_id: The registration ID of the agent that will
be used for this session.
etag: The etag of the agent session.
Note: It is recommended to use the `Agent` class to start and get sessions,
Expand Down Expand Up @@ -191,14 +194,15 @@ class AgentSession(AgentSessionSynchronousProtocol):
"""

id: Optional[str] = None
"""The unique ID of the agent session. Can only be used by the user that created it."""
"""The unique ID of the agent session.
Can only be used by the user that created it."""

access_level: Optional[
AgentSessionAccessLevel
] = AgentSessionAccessLevel.PUBLICLY_ACCESSIBLE
"""The access level of the agent session.
One of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or WRITE_YOUR_PRIVATE_DATA.
Defaults to PUBLICLY_ACCESSIBLE.
One of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or
WRITE_YOUR_PRIVATE_DATA. Defaults to PUBLICLY_ACCESSIBLE.
"""

started_on: Optional[datetime] = None
Expand Down Expand Up @@ -319,14 +323,15 @@ async def prompt_async(
*,
synapse_client: Optional[Synapse] = None,
) -> None:
"""Sends a prompt to the agent and adds the response to the AgentSession's chat history.
A session must be started before sending a prompt.
"""Sends a prompt to the agent and adds the response to the AgentSession's
chat history. A session must be started before sending a prompt.
Arguments:
prompt: The prompt to send to the agent.
enable_trace: Whether to enable trace for the prompt.
print_response: Whether to print the response to the console.
newer_than: The timestamp to get trace results newer than. Defaults to None (all results).
newer_than: The timestamp to get trace results newer than.
Defaults to None (all results).
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
instance from the Synapse class constructor.
Expand Down Expand Up @@ -362,9 +367,11 @@ class Agent(AgentSynchronousProtocol):
Example: Chat with the baseline Synapse Agent
You can chat with the same agent which is available in the Synapse UI at https://www.synapse.org/Chat:default.
By default, this "baseline" agent is used when a registration ID is not provided. In the background,
the Agent class will start a session and set that new session as the current session if one is not already set.
You can chat with the same agent which is available in the Synapse UI
at https://www.synapse.org/Chat:default. By default, this "baseline" agent
is used when a registration ID is not provided. In the background,
the Agent class will start a session and set that new session as the
current session if one is not already set.
syn = Synapse()
syn.login()
Expand All @@ -376,9 +383,11 @@ class Agent(AgentSynchronousProtocol):
print_response=True,
)
Example: Register and chat with a custom agent **Only available for internal users (Sage Bionetworks employees)**
Example: Register and chat with a custom agent
**Only available for internal users (Sage Bionetworks employees)**
Alternatively, you can register a custom agent and chat with it provided you have already created it.
Alternatively, you can register a custom agent and chat with it provided
you have already created it.
syn = Synapse()
syn.login(silent=True)
Expand All @@ -395,11 +404,13 @@ class Agent(AgentSynchronousProtocol):
Advanced Example: Start and prompt multiple sessions
Here, we connect to a custom agent and start one session with the prompt "Hello". In the background,
this first session is being set as the current session and future prompts will be sent to this session
by default. If we want to send a prompt to a different session, we can do so by starting it and calling
prompt again, but with our new session as an argument. We now have two sessions, both stored in the
my_agent.sessions dictionary. After the second prompt, my_second_session is now the current session.
Here, we connect to a custom agent and start one session with the prompt "Hello".
In the background, this first session is being set as the current session
and future prompts will be sent to this session by default. If we want to send a
prompt to a different session, we can do so by starting it and calling prompt again,
but with our new session as an argument. We now have two sessions, both stored in the
my_agent.sessions dictionary. After the second prompt, my_second_session is now
the current session.
syn = Synapse()
syn.login()
Expand Down Expand Up @@ -469,7 +480,8 @@ def fill_from_dict(self, agent_registration: Dict[str, str]) -> "Agent":
async def register_async(
self, *, synapse_client: Optional[Synapse] = None
) -> "Agent":
"""Registers an agent with the Synapse API. If agent already exists, it will be retrieved.
"""Registers an agent with the Synapse API.
If agent already exists, it will be retrieved.
Arguments:
synapse_client: If not passed in and caching was not disabled by
Expand Down Expand Up @@ -524,7 +536,8 @@ async def start_session_async(
Arguments:
access_level: The access level of the agent session.
Must be one of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or WRITE_YOUR_PRIVATE_DATA.
Must be one of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA,
or WRITE_YOUR_PRIVATE_DATA.
Defaults to PUBLICLY_ACCESSIBLE.
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
Expand All @@ -548,7 +561,8 @@ async def get_session_async(
self, session_id: str, *, synapse_client: Optional[Synapse] = None
) -> "AgentSession":
"""Gets an existing agent session.
Adds the session to the Agent's sessions dictionary and sets it as the current session.
Adds the session to the Agent's sessions dictionary and
sets it as the current session.
Arguments:
session_id: The ID of the session to get.
Expand Down Expand Up @@ -587,7 +601,8 @@ async def prompt_async(
prompt: The prompt to send to the agent.
enable_trace: Whether to enable trace for the prompt.
print_response: Whether to print the response to the console.
session_id: The ID of the session to send the prompt to. If None, the current session will be used.
session_id: The ID of the session to send the prompt to.
If None, the current session will be used.
newer_than: The timestamp to get trace results newer than. Defaults to None (all results).
synapse_client: If not passed in and caching was not disabled by
`Synapse.allow_client_caching(False)` this will use the last created
Expand Down
17 changes: 10 additions & 7 deletions synapseclient/models/mixins/asynchronous_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ class CallersContext(str, Enum):
"""Enum representing information about a web service call:
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/auth/CallersContext.html>
- SESSION_ID: Each web service request is issued a unique session ID (UUID) that is included in the call's access record.
Events that are triggered by a web service request should include the session ID so that they can be linked to
each other and the call's access record.
- SESSION_ID: Each web service request is issued a unique session ID (UUID)
that is included in the call's access record.
Events that are triggered by a web service request should include the session ID
so that they can be linked to each other and the call's access record.
"""

SESSION_ID = "SESSION_ID"
Expand All @@ -107,9 +108,11 @@ class AsynchronousJobStatus:
Attributes:
state: The state of the job. Either PROCESSING, FAILED, or COMPLETE.
canceling: Whether the job has been requested to be cancelled.
request_body: The body of an Asynchronous job request. Will be one of the models described here:
request_body: The body of an Asynchronous job request.
Will be one of the models described here:
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/asynch/AsynchronousRequestBody.html>
response_body: The body of an Asynchronous job response. Will be one of the models described here:
response_body: The body of an Asynchronous job response.
Will be one of the models described here:
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/asynch/AsynchronousResponseBody.html>
etag: The etag of the job status. Changes whenever the status changes.
id: The ID if the job issued when this job was started.
Expand All @@ -118,8 +121,8 @@ class AsynchronousJobStatus:
changed_on: The date-time when the status of this job was last changed.
progress_message: The current message of the progress tracker.
progress_current: A value indicating how much progress has been made.
I.e. a value of 50 indicates that 50% of the work has been
completed if progress_total is 100.
I.e. a value of 50 indicates that 50% of the work has been
completed if progress_total is 100.
progress_total: A value indicating the total amount of work to complete.
exception: The exception that needs to be thrown if the job fails.
error_message: A one-line error message when the job fails.
Expand Down
37 changes: 24 additions & 13 deletions synapseclient/models/protocols/agent_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def start(self, *, synapse_client: Optional[Synapse] = None) -> "AgentSession":
"""Starts an agent session.
Arguments:
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The new AgentSession object.
Expand All @@ -28,7 +29,8 @@ def get(self, *, synapse_client: Optional[Synapse] = None) -> "AgentSession":
"""Gets an existing agent session.
Arguments:
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The existing AgentSession object.
Expand All @@ -39,7 +41,8 @@ def update(self, *, synapse_client: Optional[Synapse] = None) -> "AgentSession":
"""Updates an existing agent session.
Arguments:
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The updated AgentSession object.
Expand All @@ -61,8 +64,10 @@ def prompt(
prompt: The prompt to send to the agent.
enable_trace: Whether to enable trace for the prompt.
print_response: Whether to print the response to the console.
newer_than: The timestamp to get trace results newer than. Defaults to None (all results).
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
newer_than: The timestamp to get trace results newer than.
Defaults to None (all results).
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
"""
return None

Expand All @@ -75,7 +80,8 @@ def register(self, *, synapse_client: Optional[Synapse] = None) -> "Agent":
"""Registers an agent with the Synapse API. If agent exists, it will be retrieved.
Arguments:
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The registered or existing Agent object.
Expand All @@ -86,7 +92,8 @@ def get(self, *, synapse_client: Optional[Synapse] = None) -> "Agent":
"""Gets an existing agent.
Arguments:
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The existing Agent object.
Expand All @@ -103,9 +110,10 @@ def start_session(
Adds the session to the Agent's sessions dictionary and sets it as the current session.
Arguments:
access_level: The access level of the agent session.
Must be one of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA, or WRITE_YOUR_PRIVATE_DATA.
Defaults to PUBLICLY_ACCESSIBLE.
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
Must be one of PUBLICLY_ACCESSIBLE, READ_YOUR_PRIVATE_DATA,
or WRITE_YOUR_PRIVATE_DATA. Defaults to PUBLICLY_ACCESSIBLE.
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
Returns:
The new AgentSession object.
Expand Down Expand Up @@ -145,8 +153,11 @@ def prompt(
prompt: The prompt to send to the agent.
enable_trace: Whether to enable trace for the prompt.
print_response: Whether to print the response to the console.
session_id: The ID of the session to send the prompt to. If None, the current session will be used.
newer_than: The timestamp to get trace results newer than. Defaults to None (all results).
synapse_client: The Synapse client to use for the request. If None, the default client will be used.
session_id: The ID of the session to send the prompt to.
If None, the current session will be used.
newer_than: The timestamp to get trace results newer than.
Defaults to None (all results).
synapse_client: The Synapse client to use for the request.
If None, the default client will be used.
"""
return None
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ async def test_get(self) -> None:
assert new_session == agent_session

async def test_update(self) -> None:
# GIVEN an agent session with a valid agent registration id and access level set
# GIVEN an agent session with a valid agent
# registration id and access level set
agent_session = AgentSession(
agent_registration_id=AGENT_REGISTRATION_ID,
access_level=AgentSessionAccessLevel.PUBLICLY_ACCESSIBLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ async def test_get_job_async_when_job_fails(self) -> None:
):
with pytest.raises(
SynapseError,
match=f"{self.failed_job_status.error_message}\n{self.failed_job_status.error_details}",
match=(
f"{self.failed_job_status.error_message}\n"
f"{self.failed_job_status.error_details}"
),
):
# WHEN I call get_job_async
# AND the job fails in the Synapse API
Expand Down
Loading

0 comments on commit 89db642

Please sign in to comment.