Skip to content

smart_compose

SmartCompose

Bases: Resource

A collection of Smart Compose related API endpoints.

These endpoints allow for the generation of message suggestions.

Source code in nylas/resources/smart_compose.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class SmartCompose(Resource):
    """
    A collection of Smart Compose related API endpoints.

    These endpoints allow for the generation of message suggestions.
    """

    def compose_message(
        self, identifier: str, request_body: ComposeMessageRequest
    ) -> Response[ComposeMessageResponse]:
        """
        Compose a message.

        Args:
            identifier: The identifier of the grant to generate a message suggestion for.
            request_body: The prompt that smart compose will use to generate a message suggestion.

        Returns:
            The generated message.
        """
        res = self._http_client._execute(
            method="POST",
            path=f"/v3/grants/{identifier}/messages/smart-compose",
            request_body=request_body,
        )

        return Response.from_dict(res, ComposeMessageResponse)

    def compose_message_reply(
        self, identifier: str, message_id: str, request_body: ComposeMessageRequest
    ) -> ComposeMessageResponse:
        """
        Compose a message reply.

        Args:
            identifier: The identifier of the grant to generate a message suggestion for.
            message_id: The id of the message to reply to.
            request_body: The prompt that smart compose will use to generate a message reply suggestion.

        Returns:
            The generated message reply.
        """
        res = self._http_client._execute(
            method="POST",
            path=f"/v3/grants/{identifier}/messages/{message_id}/smart-compose",
            request_body=request_body,
        )

        return Response.from_dict(res, ComposeMessageResponse)

compose_message(identifier, request_body)

Compose a message.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to generate a message suggestion for.

required
request_body ComposeMessageRequest

The prompt that smart compose will use to generate a message suggestion.

required

Returns:

Type Description
Response[ComposeMessageResponse]

The generated message.

Source code in nylas/resources/smart_compose.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def compose_message(
    self, identifier: str, request_body: ComposeMessageRequest
) -> Response[ComposeMessageResponse]:
    """
    Compose a message.

    Args:
        identifier: The identifier of the grant to generate a message suggestion for.
        request_body: The prompt that smart compose will use to generate a message suggestion.

    Returns:
        The generated message.
    """
    res = self._http_client._execute(
        method="POST",
        path=f"/v3/grants/{identifier}/messages/smart-compose",
        request_body=request_body,
    )

    return Response.from_dict(res, ComposeMessageResponse)

compose_message_reply(identifier, message_id, request_body)

Compose a message reply.

Parameters:

Name Type Description Default
identifier str

The identifier of the grant to generate a message suggestion for.

required
message_id str

The id of the message to reply to.

required
request_body ComposeMessageRequest

The prompt that smart compose will use to generate a message reply suggestion.

required

Returns:

Type Description
ComposeMessageResponse

The generated message reply.

Source code in nylas/resources/smart_compose.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def compose_message_reply(
    self, identifier: str, message_id: str, request_body: ComposeMessageRequest
) -> ComposeMessageResponse:
    """
    Compose a message reply.

    Args:
        identifier: The identifier of the grant to generate a message suggestion for.
        message_id: The id of the message to reply to.
        request_body: The prompt that smart compose will use to generate a message reply suggestion.

    Returns:
        The generated message reply.
    """
    res = self._http_client._execute(
        method="POST",
        path=f"/v3/grants/{identifier}/messages/{message_id}/smart-compose",
        request_body=request_body,
    )

    return Response.from_dict(res, ComposeMessageResponse)