Skip to main content

Pieces OS Client Python SDK Copilot

Use the following methods to communicate with Pieces Copilot using the Pieces OS Client Python SDK.

Copilot Management

Ask a Question to Pieces Copilot

The stream_question() method of the Copilot class allows you to ask a question to Pieces Copilot and stream the response.

Parameters

Param NameParam TypeParam Notes
questionstring[required]

Example

from pieces_os_client.wrapper import PiecesClient

# Initialize the PiecesClient
pieces_client = PiecesClient()

# Set the question you want to ask
question = "What is Object-Oriented Programming?"

# Ask the question and stream the response
for response in pieces_client.copilot.stream_question(question):
if response.question:
# Each answer is a chunk of the entire response to the question
answers = response.question.answers.iterable
for answer in answers:
print(answer.text,end="")

# Close the client
pieces_client.close()

Get Availiable LLMs

The get_models() method returns a list of available LLMs as a dictionary.

Example

from pieces_os_client.wrapper import PiecesClient
from pieces_os_client import ClassificationSpecificEnum, FragmentMetadata

# Initialize the PiecesClient
pieces_client = PiecesClient()

# Get all models and print their names
models = pieces_client.get_models()
for model_name, model_id in models.items():
print(model_name)

# Close the client
pieces_client.close()

Copilot Class

The Copilot class provides a way to manage copilot functionality with various properties and methods.

Properties

Property NameProperty Description
chatThe chat object.

BasicChat Class

The BasicChat class provides a way to manage chat with various properties and methods.

Properties

Property NameProperty Description
conversationThe conversation object.
idThe ID of the chat.
nameThe name of the chat.
annotationsThe annotations of the chat.

Methods

delete()

The delete() method deletes the chat.

Example

from pieces_os_client.wrapper import PiecesClient

# Initialize the PiecesClient
pieces_client = PiecesClient()

# Get the chat ID
chat_id = "your_chat_id"

# Delete the chat
pieces_client.copilot.chat(chat_id).delete()

# Close the client
pieces_client.close()