Skip to content

Latest commit

 

History

History
144 lines (94 loc) · 13.4 KB

README.md

File metadata and controls

144 lines (94 loc) · 13.4 KB

Chat

Overview

Available Operations

create

Run an assistant turn. The default response is JSON. HTTP clients request server-sent events by setting stream to true in the JSON body. An Accept: text/event-stream header does not replace stream.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:

    res = glean.chat.create(input="Summarize our parental leave policy.", store=True)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
input models.PlatformChatCreateInput ✔️ Either a plain string (single user turn) or a chronological array of USER/ASSISTANT messages. The final array message must be USER.
store Optional[bool] ➖ When true (default), persist the interaction and return a conversation_id. When false, run ephemerally with no persistence.
conversation_id Optional[str] ➖ Continue an existing stored conversation. Incompatible with message-array input and with store: false.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.PlatformChatCompletedResponse

Errors

Error Type Status Code Content Type
errors.PlatformProblemDetailError 400, 401, 403, 404, 408, 413, 422, 429 application/problem+json
errors.PlatformProblemDetailError 500, 503 application/problem+json
errors.GleanError 4XX, 5XX */*

update

Update the name of a chat. Only the chat owner can update it.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:

    res = glean.chat.update(chat_id="{chat_id}", name="Quarterly planning notes")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
chat_id str ✔️ The ID of the chat to update. {chat_id}
name str ✔️ The new name for the chat. Names longer than 80 Unicode code points are truncated to 80 before storage.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

models.PlatformChatUpdateResponse

Errors

Error Type Status Code Content Type
errors.PlatformProblemDetailError 400, 401, 403, 404, 405, 413, 429 application/problem+json
errors.PlatformProblemDetailError 500 application/problem+json
errors.GleanError 4XX, 5XX */*

create_stream

SDK-only logical operation. HTTP clients must call the base path; the URL fragment is not sent. Run an assistant turn as server-sent events. HTTP clients request this mode by setting stream to true in the JSON body.

Example Usage

from glean.api_client import Glean
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:

    res = glean.chat.create_stream(input="Summarize our parental leave policy.", store=True)

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

Parameters

Parameter Type Required Description
input models.PlatformChatCreateStreamInput ✔️ Either a plain string (single user turn) or a chronological array of USER/ASSISTANT messages. The final array message must be USER.
store Optional[bool] ➖ When true (default), persist the interaction and return a conversation_id. When false, run ephemerally with no persistence.
conversation_id Optional[str] ➖ Continue an existing stored conversation. Incompatible with message-array input and with store: false.
retries Optional[utils.RetryConfig] ➖ Configuration to override the default retry behavior of the client.

Response

Union[eventstreaming.EventStream[models.PlatformChatStreamEventServerSentEvent], eventstreaming.EventStreamAsync[models.PlatformChatStreamEventServerSentEvent]]

Errors

Error Type Status Code Content Type
errors.PlatformProblemDetailError 400, 401, 403, 404, 408, 413, 422, 429 application/problem+json
errors.PlatformProblemDetailError 500, 503 application/problem+json
errors.GleanError 4XX, 5XX */*