CopilotClient Class
A client for interacting with the Copilot service.
Constructor
CopilotClient()
Parameters
| Name | Description |
|---|---|
|
settings
Required
|
|
|
token
Required
|
|
Methods
| __init__ | |
| __new__ | |
| ask_question |
Ask a question in the specified conversation. |
| ask_question_with_activity |
Ask a question using an Activity object. |
| execute |
Execute an activity with a specified conversation ID. |
| post_request |
Send a POST request to the specified URL with the given data and headers. |
| scope_from_cloud |
Get the token audience scope from PowerPlatformCloud. |
| scope_from_settings |
Get the token audience scope from connection settings. |
| send_activity |
Send an activity to the bot. This is an alias for ask_question_with_activity for consistency with the .NET implementation. |
| start_conversation |
Start a new conversation and optionally emit a start conversation event. |
| start_conversation_with_request |
Start a new conversation with a StartRequest object. |
| subscribe |
Subscribe to conversation events. Note: This method is marked as obsolete in the .NET implementation and is for MSFT internal use only. |
__init__
__init__(settings: ConnectionSettings, token: str)
Parameters
| Name | Description |
|---|---|
|
settings
Required
|
|
|
token
Required
|
|
__new__
__new__(**kwargs)
ask_question
Ask a question in the specified conversation.
async ask_question(question: str, conversation_id: str | None = None) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
question
Required
|
The question to be asked. |
|
conversation_id
|
The ID of the conversation in which the question is asked. If not provided, the current conversation ID is used. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
ask_question_with_activity
Ask a question using an Activity object.
async ask_question_with_activity(activity: Activity) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
The Activity object representing the question to be asked. |
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
execute
Execute an activity with a specified conversation ID.
async execute(conversation_id: str, activity: Activity) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
conversation_id
Required
|
The conversation ID. |
|
activity
Required
|
The Activity object to execute. |
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
post_request
Send a POST request to the specified URL with the given data and headers.
async post_request(url: str, data: dict, headers: dict) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
url
Required
|
The URL to which the POST request is sent. |
|
data
Required
|
The data to be sent in the POST request body. |
|
headers
Required
|
The headers to be included in the POST request. |
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
scope_from_cloud
Get the token audience scope from PowerPlatformCloud.
static scope_from_cloud(cloud) -> str
Parameters
| Name | Description |
|---|---|
|
cloud
Required
|
The PowerPlatformCloud value. |
Returns
| Type | Description |
|---|---|
|
The token audience scope URL. |
scope_from_settings
Get the token audience scope from connection settings.
static scope_from_settings(settings: ConnectionSettings) -> str
Parameters
| Name | Description |
|---|---|
|
settings
Required
|
The ConnectionSettings object. |
Returns
| Type | Description |
|---|---|
|
The token audience scope URL. |
send_activity
Send an activity to the bot.
This is an alias for ask_question_with_activity for consistency with the .NET implementation.
async send_activity(activity: Activity) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
activity
Required
|
The Activity object to send. |
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
start_conversation
Start a new conversation and optionally emit a start conversation event.
async start_conversation(emit_start_conversation_event: bool = True) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
emit_start_conversation_event
|
A boolean flag indicating whether to emit a start conversation event. Default value: True
|
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
start_conversation_with_request
Start a new conversation with a StartRequest object.
async start_conversation_with_request(start_request: StartRequest) -> AsyncIterable[Activity]
Parameters
| Name | Description |
|---|---|
|
start_request
Required
|
The StartRequest containing conversation parameters. |
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of Activity objects received in the response. |
subscribe
Subscribe to conversation events.
Note: This method is marked as obsolete in the .NET implementation and is for MSFT internal use only.
async subscribe(conversation_id: str, last_received_event_id: str | None = None) -> AsyncIterable[SubscribeEvent]
Parameters
| Name | Description |
|---|---|
|
conversation_id
Required
|
The conversation ID to subscribe to. |
|
last_received_event_id
|
Optional last received event ID for resumption. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An asynchronous iterable of SubscribeEvent objects. |
Attributes
APPLICATION_JSON_TYPE
APPLICATION_JSON_TYPE = 'application/json'
EVENT_STREAM_TYPE
EVENT_STREAM_TYPE = 'text/event-stream'
EXPERIMENTAL_URL_HEADER_KEY
EXPERIMENTAL_URL_HEADER_KEY = 'x-ms-d2e-experimental'