Skip to content

Latest commit

 

History

History
554 lines (387 loc) · 56.1 KB

File metadata and controls

554 lines (387 loc) · 56.1 KB

Beta.Conversations

Overview

(beta) Conversations API

Available Operations

  • start - Create a conversation and append entries to it.
  • list - List all created conversations.
  • get - Retrieve a conversation information.
  • delete - Delete a conversation.
  • append - Append new entries to an existing conversation.
  • get_history - Retrieve all entries in a conversation.
  • get_messages - Retrieve all messages in a conversation.
  • restart - Restart a conversation starting from a given entry.
  • start_stream - Create a conversation and append entries to it.
  • append_stream - Append new entries to an existing conversation.
  • restart_stream - Restart a conversation starting from a given entry.

start

Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.start(inputs="<value>", completion_args={
        "response_format": {
            "type": "text",
        },
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
inputs models.ConversationInputs ✔️ N/A
store OptionalNullable[bool] N/A
handoff_execution OptionalNullable[models.ConversationRequestHandoffExecution] N/A
instructions OptionalNullable[str] N/A
tools List[models.ConversationRequestTool] N/A
completion_args OptionalNullable[models.CompletionArgs] N/A
guardrails List[models.GuardrailConfig] N/A
name OptionalNullable[str] N/A
description OptionalNullable[str] N/A
metadata Dict[str, Any] N/A
agent_id OptionalNullable[str] N/A
agent_version OptionalNullable[models.ConversationRequestAgentVersion] N/A
model OptionalNullable[str] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ConversationResponse

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

list

Retrieve a list of conversation entities sorted by creation time.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.list(page=0, page_size=100)

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
page Optional[int] N/A
page_size Optional[int] N/A
metadata Dict[str, Any] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

List[models.AgentsAPIV1ConversationsListResponse]

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

get

Given a conversation_id retrieve a conversation entity with its attributes.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.get(conversation_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation from which we are fetching metadata.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ResponseV1ConversationsGet

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

delete

Delete a conversation given a conversation_id.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    mistral.beta.conversations.delete(conversation_id="<id>")

    # Use the SDK ...

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation from which we are fetching metadata.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

append

Run completion on the history of the conversation and the user entries. Return the new created entries.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.append(conversation_id="<id>", store=True, handoff_execution="server", completion_args={
        "response_format": {
            "type": "text",
        },
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation to which we append entries.
inputs Optional[models.ConversationInputs] N/A
store Optional[bool] Whether to store the results into our servers or not.
handoff_execution Optional[models.ConversationAppendRequestHandoffExecution] N/A
completion_args Optional[models.CompletionArgs] White-listed arguments from the completion API
tool_confirmations List[models.ToolCallConfirmation] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ConversationResponse

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

get_history

Given a conversation_id retrieve all the entries belonging to that conversation. The entries are sorted in the order they were appended, those can be messages, connectors or function_call.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.get_history(conversation_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation from which we are fetching entries.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ConversationHistory

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

get_messages

Given a conversation_id retrieve all the messages belonging to that conversation. This is similar to retrieving all entries except we filter the messages only.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.get_messages(conversation_id="<id>")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation from which we are fetching messages.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ConversationMessages

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

restart

Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.restart(conversation_id="<id>", from_entry_id="<id>", store=True, handoff_execution="server", completion_args={
        "response_format": {
            "type": "text",
        },
    })

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the original conversation which is being restarted.
from_entry_id str ✔️ N/A
inputs Optional[models.ConversationInputs] N/A
store Optional[bool] Whether to store the results into our servers or not.
handoff_execution Optional[models.ConversationRestartRequestHandoffExecution] N/A
completion_args Optional[models.CompletionArgs] White-listed arguments from the completion API
guardrails List[models.GuardrailConfig] N/A
metadata Dict[str, Any] Custom metadata for the conversation.
agent_version OptionalNullable[models.ConversationRestartRequestAgentVersion] Specific version of the agent to use when restarting. If not provided, uses the current version.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.ConversationResponse

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

start_stream

Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.start_stream(inputs=[
        {
            "object": "entry",
            "type": "function.result",
            "tool_call_id": "<id>",
            "result": "<value>",
        },
    ], completion_args={
        "response_format": {
            "type": "text",
        },
    })

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

Parameters

Parameter Type Required Description
inputs models.ConversationInputs ✔️ N/A
store OptionalNullable[bool] N/A
handoff_execution OptionalNullable[models.ConversationStreamRequestHandoffExecution] N/A
instructions OptionalNullable[str] N/A
tools List[models.ConversationStreamRequestTool] N/A
completion_args OptionalNullable[models.CompletionArgs] N/A
guardrails List[models.GuardrailConfig] N/A
name OptionalNullable[str] N/A
description OptionalNullable[str] N/A
metadata Dict[str, Any] N/A
agent_id OptionalNullable[str] N/A
agent_version OptionalNullable[models.ConversationStreamRequestAgentVersion] N/A
model OptionalNullable[str] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

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

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

append_stream

Run completion on the history of the conversation and the user entries. Return the new created entries.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.append_stream(conversation_id="<id>", store=True, handoff_execution="server", completion_args={
        "response_format": {
            "type": "text",
        },
    })

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

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the conversation to which we append entries.
inputs Optional[models.ConversationInputs] N/A
store Optional[bool] Whether to store the results into our servers or not.
handoff_execution Optional[models.ConversationAppendStreamRequestHandoffExecution] N/A
completion_args Optional[models.CompletionArgs] White-listed arguments from the completion API
tool_confirmations List[models.ToolCallConfirmation] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

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

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

restart_stream

Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.

Example Usage

from mistralai.client import Mistral
import os


with Mistral(
    api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:

    res = mistral.beta.conversations.restart_stream(conversation_id="<id>", from_entry_id="<id>", store=True, handoff_execution="server", completion_args={
        "response_format": {
            "type": "text",
        },
    })

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

Parameters

Parameter Type Required Description
conversation_id str ✔️ ID of the original conversation which is being restarted.
from_entry_id str ✔️ N/A
inputs Optional[models.ConversationInputs] N/A
store Optional[bool] Whether to store the results into our servers or not.
handoff_execution Optional[models.ConversationRestartStreamRequestHandoffExecution] N/A
completion_args Optional[models.CompletionArgs] White-listed arguments from the completion API
guardrails List[models.GuardrailConfig] N/A
metadata Dict[str, Any] Custom metadata for the conversation.
agent_version OptionalNullable[models.ConversationRestartStreamRequestAgentVersion] Specific version of the agent to use when restarting. If not provided, uses the current version.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

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

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*