Skip to main content

A Pieces OS SDK wrapper that allows anyone to easily create a Pieces Copilot experience with minimal code.

Project description

Pieces Copilot Python SDK

This repository contains the Pieces Copilot SDK, a convenient wrapper around the Pieces OS Client SDK. It simplifies the process of interacting with your applications by providing a more user-friendly interface to the underlying Pieces OS Client SDK.

Installation

To use the Pieces Copilot SDK in your project, you need to install it via pip:

pip install pieces_copilot_sdk

Requirements

You must either have Pieces OS installed on your local machine or have access to a remote instance of Pieces OS to use this SDK.

Usage

First, you need to import the SDK and initialize it with your base URL. The base URL will depend on your setup:

  • If you are using a local instance of Pieces OS:
    • On macOS/Windows, use http://localhost:1000
    • On Linux, use http://localhost:5323
  • If you are using a remote instance of Pieces OS, use the URL you have set up for that.

Here's how you can initialize the SDK:

from pieces_copilot_sdk import PiecesClient

# Replace 'your_base_url' with your actual base URL
pieces_client = PiecesClient(config={'baseUrl': 'your_base_url'})

Then, you can use the various methods provided by the SDK to interact with your applications.

Features

  • Simplified Interaction: The Pieces Copilot SDK simplifies the interaction with the Pieces OS Client SDK by providing easy-to-use methods for various operations.
  • Manage Conversations: The SDK provides various methods to manage conversations such as fetching a specific conversation, updating conversation name, and more.
  • Get User Profile Picture: Retrieve the user's profile picture using the get_user_profile_picture() method.

Methods

create_conversation(name=None, first_message=None)

This method creates a new conversation. It takes an optional name and optional first message as parameters. It returns a dictionary containing the new conversation and the answer to the first message (if provided).

Example usage:

new_conversation = pieces_client.create_conversation(
    name='Hello World Conversation',
    first_message='Hello, world!'
)

get_conversation(conversation_id, include_raw_messages=False)

This method retrieves a conversation by its ID. You can choose to include raw messages in the conversation by setting the include_raw_messages parameter to True. It returns a dictionary representing the Conversation object or None.

Example usage:

conversation = pieces_client.get_conversation(
    conversation_id='conversationId',
    include_raw_messages=True
)

get_conversations()

This method retrieves all conversations. It returns a list of Conversation objects or None.

Example usage:

conversations = pieces_client.get_conversations()

prompt_conversation(question, conversation_id, regenerate_conversation_name=False)

This method prompts a conversation with a message. It takes a message string, conversation ID, and an optional flag to regenerate the conversation name (default is False). It returns a dictionary containing the text of the answer, the ID of the user query message, and the ID of the bot response message.

If there are previous messages in the conversation, they will be used as context for the new message.

If there is an error, it will return a dictionary containing only the text of the error message.

Example usage:

answer = pieces_client.prompt_conversation(
    message='Hello, world!',
    conversation_id='conversationId'
)

update_conversation_name(conversation_id)

This method generates a new name for a specific conversation based on the messages that have been sent. It takes a conversation ID as a parameter. It returns a string representing the updated conversation name or None.

Example usage:

updated_name = pieces_client.update_conversation_name(conversation_id='conversationId')

get_user_profile_picture()

This method retrieves the user's profile picture. It returns a string representing the URL of the profile picture or None.

Example usage:

profile_picture_url = pieces_client.get_user_profile_picture()

Full Example

Here's a full example of how to use all the methods provided by the SDK:

from pieces_copilot_sdk import PiecesClient

# Create an instance of PiecesClient
pieces_client = PiecesClient(
    config={
        'baseUrl': 'http://localhost:1000'
    }
)

# 1. Create a new conversation
conversation_response = pieces_client.create_conversation(
    props={
        "name": "Test Conversation",
        "firstMessage": "Hello, how can I use the API?"
    }
)

# Check if the conversation was created successfully
if conversation_response:
    print("Conversation Created:", conversation_response['conversation'].id)
    print("First Message Response:", conversation_response['answer']['text'])

    # 2. Get the created conversation details
    conversation_id = conversation_response['conversation'].id
    conversation_details = pieces_client.get_conversation(
        conversation_id=conversation_id,
        include_raw_messages=True
    )
    print("Conversation Name:", conversation_details.name)

    # 3. Ask a question within the created conversation
    question_response = pieces_client.prompt_conversation(
        question="Can you give me an example code snippet?",
        conversation_id=conversation_id
    )
    print("Question Response:", question_response['text'])

# 4. Retrieve all conversations and print their names
all_conversations = pieces_client.get_conversations()
for conversation in all_conversations:
    print("Conversation Name:", conversation.name)

# 5. Get user profile picture
profile_picture = pieces_client.get_user_profile_picture()
print("User Profile Picture URL:", profile_picture)

Contributing

Contributions are welcome! Please read our contributing guidelines before starting.

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pieces_copilot_sdk-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pieces_copilot_sdk-0.1.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pieces_copilot_sdk-0.1.1.tar.gz.

File metadata

  • Download URL: pieces_copilot_sdk-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.5

File hashes

Hashes for pieces_copilot_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4fbea78652b06cc9bc593983f348518b67bc8f7b525ac58d51592df3022ae45e
MD5 f3d9ffd9a3fd11f999721ba7ac2aa02f
BLAKE2b-256 928fcdbec55f5f46ab9b0ae75048072304c9b396f357b0ad4d15e3d0140c01f5

See more details on using hashes here.

File details

Details for the file pieces_copilot_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pieces_copilot_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e41e57c08a6280983fe30446b40d5382f90adb5092e99f57c343de1983cc569
MD5 7e0e1ec323cbc555d750d455b2a60f7e
BLAKE2b-256 401efbc354486fa671e422405e638c715c252f6aec3cf6bd1df197e9f4e10a3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page