pieces-app / documentation

Official documentation for Pieces for Developers
https://docs.pieces.app
402 stars 50 forks source link

Add docs in Python SDK build section on how to add context to a Pieces Copilot chat #564

Open shivay-at-pieces opened 2 months ago

shivay-at-pieces commented 2 months ago

Include code example on how to add context to your Pieces Copilot conversation

Ayush9026 commented 2 months ago

@shivay-at-pieces bhaiya i will solve this.

shivay-at-pieces commented 2 months ago

so here is how to add a context to the Copilot. You can add 4 things as a context: A file/folder path A snippet A raw snippet A message And all work the same way you append the context.(context type) list Note: the conversation association is not implemented yet in the sdks (means it won't be synced across the other plugins) eg: you added a path and asked a question in a conversation in your code the desktop app won't know what context you added:

from pieces_os_client.wrapper import PiecesClient
copilot = PiecesClient().copilot
copilot.context.paths.append("STRING TO PATH") # adding a path
copilot.context.raw_assets.append("from pieces_os_client.wrapper import PiecesClient") # adding raw snippet
copilot.context.assets.append(BasicAsset("Asset ID")) # Adding an asset
copilot.context.messages.append(BasicMessage("Message ID")) # Adding a message
copilot.ask_stream("Question releated to the context")

Note: if the path is not valid or the raw_assets is not a string typed or the asset/ message is not a Basic typed it will release an error when asking the question Also there is a bug which I fixed in that PR gonna be merged today and a release will be tagged where every time you do PiecesClient().copilot it will create a new instance instead of using the old instance which the copilot will be rested and all the context set will be removed so you should store the PiecesClient().copilot in a variable and use it