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
 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
56
57
58
59
60
61
62
63
64
65
66
67
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,
        overrides: RequestOverrides = None,
    ) -> 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.
            overrides: The request overrides to apply to the request.

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

        return Response.from_dict(res, ComposeMessageResponse)

    def compose_message_reply(
        self,
        identifier: str,
        message_id: str,
        request_body: ComposeMessageRequest,
        overrides: RequestOverrides = None,
    ) -> 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.
            overrides: The request overrides to apply to the request.

        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,
            overrides=overrides,
        )

        return Response.from_dict(res, ComposeMessageResponse)

compose_message(identifier, request_body, overrides=None)

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
overrides RequestOverrides

The request overrides to apply to the request.

None

Returns:

Type Description
Response[ComposeMessageResponse]

The generated message.

Source code in nylas/resources/smart_compose.py
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
def compose_message(
    self,
    identifier: str,
    request_body: ComposeMessageRequest,
    overrides: RequestOverrides = None,
) -> 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.
        overrides: The request overrides to apply to the request.

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

    return Response.from_dict(res, ComposeMessageResponse)

compose_message_reply(identifier, message_id, request_body, overrides=None)

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
overrides RequestOverrides

The request overrides to apply to the request.

None

Returns:

Type Description
ComposeMessageResponse

The generated message reply.

Source code in nylas/resources/smart_compose.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def compose_message_reply(
    self,
    identifier: str,
    message_id: str,
    request_body: ComposeMessageRequest,
    overrides: RequestOverrides = None,
) -> 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.
        overrides: The request overrides to apply to the request.

    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,
        overrides=overrides,
    )

    return Response.from_dict(res, ComposeMessageResponse)