GeezerVison is showing github.com — api-client-python/docs/sdks/clientchat/README.md at main · gleanwork/api-client-python
672 lines (461 loc) · 114 KB File metadata and controls672 lines (461 loc) · 114 KB Copy raw file Download raw file OutlineEdit and raw actions
Have a conversation with Glean AI.
Example Usage: citationResponse
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create(messages=[], timeout_millis=30000)
# Handle response
print(res)
Example Usage: defaultExample
from glean.api_client import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create(messages=[
{
"fragments": [
models.ChatMessageFragment(
text="What are the company holidays this year?",
),
],
},
], timeout_millis=30000)
# Handle response
print(res)
Example Usage: gptAgentExample
from glean.api_client import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create(messages=[
{
"fragments": [
models.ChatMessageFragment(
text="Who was the first person to land on the moon?",
),
],
},
], agent_config={
"agent": models.AgentEnum.GPT,
}, timeout_millis=30000)
# Handle response
print(res)
Example Usage: streamingExample
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create(messages=[], timeout_millis=30000)
# Handle response
print(res)
Example Usage: updateResponse
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create(messages=[], timeout_millis=30000)
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
Example |
messages |
List[models.ChatMessage] |
✔️ |
A list of chat messages, from most recent to least recent. At least one message must specify a USER author. |
|
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
|
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
|
session_info |
Optional[models.SessionInfo] |
➖ |
N/A |
|
save_chat |
Optional[bool] |
➖ |
Save the current interaction as a Chat for the user to access and potentially continue later. |
|
chat_id |
Optional[str] |
➖ |
The id of the Chat that context should be retrieved from and messages added to. An empty id starts a new Chat, and the Chat is saved if saveChat is true. |
|
agent_config |
Optional[models.AgentConfig] |
➖ |
Describes the agent that executes the request. |
|
inclusions |
Optional[models.ChatRestrictionFilters] |
➖ |
N/A |
|
exclusions |
Optional[models.ChatRestrictionFilters] |
➖ |
N/A |
|
timeout_millis |
Optional[int] |
➖ |
Timeout in milliseconds for the request. A 408 error will be returned if handling the request takes longer. |
30000 |
application_id |
Optional[str] |
➖ |
The ID of the application this request originates from, used to determine the configuration of underlying chat processes. This should correspond to the ID set during admin setup. If not specified, the default chat experience will be used. |
|
agent_id |
Optional[str] |
➖ |
The ID of the Agent that should process this chat request. Only Agents with trigger set to 'User chat message' are invokable through this API. If not specified, the default chat experience will be used. |
|
stream |
Optional[bool] |
➖ |
If set, response lines will be streamed one-by-one as they become available. Each will be a ChatResponse, formatted as JSON, and separated by a new line. If false, the entire response will be returned at once. Note that if this is set and the model being used does not support streaming, the model's response will not be streamed, but other messages from the endpoint still will be. |
|
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
|
models.ChatResponse
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Deletes all saved Chats a user has had and all their contained conversational content.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
glean.client.chat.delete_all()
# Use the SDK ...
| Parameter |
Type |
Required |
Description |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Deletes saved Chats and all their contained conversational content.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
glean.client.chat.delete(ids=[])
# Use the SDK ...
| Parameter |
Type |
Required |
Description |
ids |
List[str] |
✔️ |
A non-empty list of ids of the Chats to be deleted. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Retrieves the chat history between Glean Assistant and the user for a given Chat. Omit pagination fields to return the full message history (existing behavior). Use last alone for the latest page, last with before for older messages, or first with after for newer messages. Each page is chronological and includes pagination cursors and page flags.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.retrieve(id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
id |
str |
✔️ |
The id of the Chat to be retrieved. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
first |
Optional[int] |
➖ |
Maximum number of messages to return from the start of the chat, or after the cursor when after is set. Pair with after for newer messages; alone returns the earliest messages. Mutually exclusive with last and before. |
after |
Optional[str] |
➖ |
An opaque message cursor from this chat. Returns messages strictly newer than this cursor. Pair with first. Mutually exclusive with before; cannot be combined with last. |
last |
Optional[int] |
➖ |
Maximum number of messages to return from the end of the chat, or before the cursor when before is set. Alone returns the latest messages; pair with before for older messages. Mutually exclusive with first and after. |
before |
Optional[str] |
➖ |
An opaque message cursor from this chat. Returns messages strictly older than this cursor. Pair with last. Mutually exclusive with after; cannot be combined with first. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.GetChatResponse
| Error Type |
Status Code |
Content Type |
| errors.AccessRequestPermissionDeniedResponseError |
403 |
application/json |
| errors.GleanError |
4XX, 5XX |
*/* |
Retrieves all the saved Chats between Glean Assistant and the user. The returned Chats contain only metadata and no conversational content.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.list()
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.ListChatsResponse
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Gets the Chat application details for the specified application ID.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.retrieve_application(id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
id |
str |
✔️ |
The id of the Chat application to be retrieved. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.GetChatApplicationResponse
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Upload files for Chat.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.upload_files(files=[])
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
files |
List[models.UploadChatFilesRequestFile] |
✔️ |
Raw files to be uploaded for chat in binary format. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.UploadChatFilesResponse
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Get files uploaded by a user for Chat.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.retrieve_files(file_ids=[
"<value 1>",
])
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
file_ids |
List[str] |
✔️ |
IDs of files to fetch. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.GetChatFilesResponse
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Delete files uploaded by a user for Chat.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
glean.client.chat.delete_files(file_ids=[
"<value 1>",
"<value 2>",
"<value 3>",
])
# Use the SDK ...
| Parameter |
Type |
Required |
Description |
file_ids |
List[str] |
✔️ |
IDs of files to delete. |
locale |
Optional[str] |
➖ |
The client's preferred locale in rfc5646 format (e.g. en, ja, pt-BR). If omitted, the Accept-Language will be used. If not present or not supported, defaults to the closest match or en. |
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Download the raw content of a file generated or uploaded during a chat session (for example, an image produced by the assistant). Returns the file bytes with a Content-Type header matching the file's MIME type.
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.retrieve_file(file_id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
file_id |
str |
✔️ |
Identifier of the chat file to download. |
preview |
Optional[bool] |
➖ |
When true and the file is a PDF, the response is served inline (Content-Disposition: inline) instead of as an attachment.
|
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
httpx.Response
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
Have a conversation with Glean AI.
Example Usage: citationResponse
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create_stream(messages=[], timeout_millis=30000)
# Handle response
print(res)
Example Usage: defaultExample
from glean.api_client import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create_stream(messages=[
{
"fragments": [
models.ChatMessageFragment(
text="What are the company holidays this year?",
),
],
},
], timeout_millis=30000)
# Handle response
print(res)
Example Usage: gptAgentExample
from glean.api_client import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create_stream(messages=[
{
"fragments": [
models.ChatMessageFragment(
text="Who was the first person to land on the moon?",
),
],
},
], agent_config={
"agent": models.AgentEnum.GPT,
}, timeout_millis=30000)
# Handle response
print(res)
Example Usage: streamingExample
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create_stream(messages=[], timeout_millis=30000)
# Handle response
print(res)
Example Usage: updateResponse
from glean.api_client import Glean
import os
with Glean(
api_token=os.getenv("GLEAN_API_TOKEN"),
) as glean:
res = glean.client.chat.create_stream(messages=[], timeout_millis=30000)
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
Example |
messages |
List[models.ChatMessage] |
✔️ |
A list of chat messages, from most recent to least recent. At least one message must specify a USER author. |
|
timezone_offset |
Optional[int] |
➖ |
The offset of the client's timezone in minutes from UTC. e.g. PDT is -420 because it's 7 hours behind UTC. |
|
session_info |
Optional[models.SessionInfo] |
➖ |
N/A |
|
save_chat |
Optional[bool] |
➖ |
Save the current interaction as a Chat for the user to access and potentially continue later. |
|
chat_id |
Optional[str] |
➖ |
The id of the Chat that context should be retrieved from and messages added to. An empty id starts a new Chat, and the Chat is saved if saveChat is true. |
|
agent_config |
Optional[models.AgentConfig] |
➖ |
Describes the agent that executes the request. |
|
inclusions |
Optional[models.ChatRestrictionFilters] |
➖ |
N/A |
|
exclusions |
Optional[models.ChatRestrictionFilters] |
➖ |
N/A |
|
timeout_millis |
Optional[int] |
➖ |
Timeout in milliseconds for the request. A 408 error will be returned if handling the request takes longer. |
30000 |
application_id |
Optional[str] |
➖ |
The ID of the application this request originates from, used to determine the configuration of underlying chat processes. This should correspond to the ID set during admin setup. If not specified, the default chat experience will be used. |
|
agent_id |
Optional[str] |
➖ |
The ID of the Agent that should process this chat request. Only Agents with trigger set to 'User chat message' are invokable through this API. If not specified, the default chat experience will be used. |
|
stream |
Optional[bool] |
➖ |
If set, response lines will be streamed one-by-one as they become available. Each will be a ChatResponse, formatted as JSON, and separated by a new line. If false, the entire response will be returned at once. Note that if this is set and the model being used does not support streaming, the model's response will not be streamed, but other messages from the endpoint still will be. |
|
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
|
str
| Error Type |
Status Code |
Content Type |
| errors.GleanError |
4XX, 5XX |
*/* |
|