Python Copilot
stream_question()β
stream_question(question)
Ask Pieces Copilot a question and stream the response.
Parametersβ
| Param Name | Param Type | Param Notes | 
|---|---|---|
| question | string | [required] | 
Exampleβ
from pieces_os_client.wrapper import PiecesClient
pieces_client = PiecesClient(config={'host': 'your_base_url'})
# 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="")
BasicChatβ
BasicChat(id)
Parametersβ
| Param Name | Param Description | Param Type | Param Notes | 
|---|---|---|---|
| id | Your conversation id. | string | [required] | 
Methodsβ
idβ
Gets the ID of the conversation.
Returnsβ
| Return Type | Return Description | 
|---|---|
| string | The ID of the conversation. | 
nameβ
Gets the name of the conversation.
Returnsβ
| Return Type | Return Description | 
|---|---|
| string | Name of the conversation, or "New Conversation" if name is not set. | 
name = name: strβ
Sets the name of the conversation.
Parametersβ
| Param Name | Param Type | Param Description | 
|---|---|---|
| name | string | The new name of the conversation. | 
messages()β
Retrieves the messages in the conversation.
Returnsβ
| Return Type | Return Description | 
|---|---|
| list | A list of BasicMessageinstances representing the messages in the conversation. | 
annotationsβ
Gets the annotations of the conversation.
Returnsβ
| Return Type | Return Description | 
|---|---|
| dict/None | The annotations of the conversation, or Noneif not available. | 
descriptionβ
Gets the conversation description.
Returnsβ
| Return Type | Return Description | 
|---|---|
| string | The description of the conversation. | 
delete()β
Deletes the conversation.
Exampleβ
from pieces_copilot_sdk import PiecesClient
# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'host': 'your_base_url'})
# Initialize a BasicChat instance
chat = pieces_client.copilot.chats()[0]
# Get the ID of the conversation
conversation_id = chat.id
print(f"Conversation ID: {conversation_id}")
# Get the name of the conversation
conversation_name = chat.name
print(f"Conversation Name: {conversation_name}")
# Set a new name for the conversation
chat.name = "Project Discussion"
print(f"Updated Conversation Name: {chat.name}")
# Retrieve the messages in the conversation
messages = chat.messages()
for message in messages:
    print(f"Message: {message.raw_content}")
    print(f"Message Role: {message.role}")
# Get the annotations of the conversation
annotations = chat.annotations
if annotations:
    print(f"Annotations: {annotations}")
else:
    print("No annotations available.")
# Get the description of the conversation
description = chat.description
print(f"Description: {description}")
# Delete the conversation
chat.delete()
print("Conversation deleted.")
pieces_client.close()
BasicMessageβ
TheΒ BasicMessageΒ class represents a Copilot chat message. To open and maintain the model, you should be usingΒ pieces_client.copilot.chat.messages()Β to open and maintain the messages of the current chat.
Propertiesβ
raw_contentβ
Sets the raw content of the message and updates it in the API.
roleβ
Gets the role of the message.
Returnsβ
| Return Type | Return Description | 
|---|---|
| Literal["USER", "SYSTEM", "ASSISTANT"] | The role of the message. | 
idβ
Gets the ID of the message.
Returnsβ
| Return Type | Return Description | 
|---|---|
| string | The ID of the message. | 
deleteβ
Deletes the message.
Exampleβ
from pieces_copilot_sdk import PiecesClient
# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'host': 'your_base_url'})
# Initialize a BasicChat instance
chat = pieces_client.copilot.chats()[0]
messages = chat.messages()
# Set the raw content of the message
message.raw_content = "This is the updated raw content of the message."
print("Raw content updated.")
# Get the role of the message
role = message.role
print(f"Role: {role}")
# Get the ID of the message
message_id = message.id
print(f"Message ID: {message_id}")
# Delete the message
message.delete()
print("Message deleted.")
pieces_client.close()
stream_question()β
stream_question(query, pipeline)
Asks a question to the QGPT model and streams the responses. By default, it will create a new conversation, and it always uses it in the ask. You can always change the conversation inΒ copilot.chat = BasicChat(chat_id="YOU ID GOES HERE").
Parametersβ
| Param Name | Param Description | Param Note | 
|---|---|---|
| query | The question to ask. | [required] | 
| pipeline | The pipeline to follow. | [optional] | 
Returnsβ
| Return Type | Return Description | 
|---|---|
| QGPTStreamOutput | The streamed output from the QGPTmodel. | 
Exampleβ
from pieces_copilot_sdk import PiecesClient
# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'host': 'your_base_url'})
for response in pieces_client.copilot.stream_question("Your question"):
    if response.question:
        answers = response.question.answers.iterable
        for answer in answers:
            print(answer.text,end="")
question()β
question(query, pipeline)
Asks a question to the QGPT model and return the responses.
The question is not a part of any conversation.
Parametersβ
| Param Name | Param Description | Param Note | 
|---|---|---|
| query | The question to ask. | [required] | 
| pipeline | The pipeline to follow. | [optional] | 
Returnsβ
| Return Type | Return Description | 
|---|---|
| QGPTStreamOutput | The streamed output from the QGPTmodel. | 
Exampleβ
from pieces_copilot_sdk import PiecesClient
# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'host': 'your_base_url'})
text = pieces_client.copilot.question("Your question").answers.iterable[0].text
print(text)
contextβ
copilot.context
Returns a context model to interact with the conversation context.
If you set the context of the copilot, you will get a value error in the ask_stream method if you add an invalid type
Exampleβ
context = copilot.context
context.paths.append("/path/to/folder/or/file")
context.message.append(BasicMessage("my_message_id"))
context.assets.append(BasicAsset("my_message_id"))
context.raw_assets.append("import sublime") # snippet content
context.clear() # clear all the context
chats()β
Retrieves a list of all chat identifiers.
Returnsβ
| Return Type | Return Description | 
|---|---|
| list[BasicChat] | A list of BasicChatinstances representing the chat identifiers. | 
Exampleβ
chat_list = copilot.chats()
for chat in chat_list:
    print(f"Chat ID: {chat.id}, Chat Name: {chat.name}")
chat (getter)β
copilot.chat
Gets the current conversation being used in the copilot.
Returnsβ
| Return Type | Return Description | 
|---|---|
| BasicChat/None | The current BasicChatinstance orNoneif no chat is set. | 
Exampleβ
current_chat = copilot.chat
if current_chat:
    print(f"Current Chat ID: {current_chat.id}")
else:
    print("No chat is currently set.")
chat (setter)β
copilot.chat = your_value_here
Sets the current conversation to be used in the copilot.
Parametersβ
| Param Type | Param Description | 
|---|---|
| BasicChat/None | The BasicChatinstance is set. | 
Raisesβ
| Raise Type | Raise Description | 
|---|---|
| ValueError | If the provided chat is not a valid BasicChatinstance. | 
new_chat = copilot.chats[0]
try:
    copilot.chat = new_chat
    print("Chat set successfully.")
except ValueError as e:
    print(f"Failed to set chat: {e}")