Generative AI Conversations
The Pieces for Obsidian Plugin provides versatile tools to interact with generative AI, enabling you to gain insights, debug efficiently, and enhance your notes and workflows directly within Obsidian.
Accessing Copilot Chat in Obsidian
There are two primary ways to access generative AI conversations with the Pieces Copilot.
via Right-Click Menu
Highlight Text or Code Block
Highlight any text or code block within your note and right-click to open the context menu.
Select "Ask Copilot About Selection"
Choose Ask Copilot About Selection
to get insights or suggestions for the selected snippet.
via the Pieces Plugin Sidebar
Open the Pieces Plugin
Open the Pieces for Obsidian Plugin by clicking its icon in the Obsidian sidebar.
Navigate to Pieces Chat
Navigate to the Pieces Chat section by selecting it from the top of the plugin slider.
Start a Conversation
The chat window will open, allowing you to start a conversation directly with the Copilot.
Contextualized Chats
Using the Pieces: Ask Copilot About Selection
command lets you interact with Copilot regarding specific text or code within your notes.
There are two ways to access this command:
via Right-Click Menu
Highlight Text or Content
Select the text or excerpt in your note that you want to query.
Right-Click
Right-click on the highlighted text.
Select Command
Choose Ask Copilot About Your Selection
from the context menu.
Enter Question
Type your prompt in the text input field and press return
(macOS) or enter
(Windows/Linux).
via Command Palette
Open the Command Palette
Use ⌘+p
(macOS) or ctrl+p
(Windows/Linux) to open the command palette in Obsidian.
Run the Command
Type and run Pieces for Developers: Ask Copilot About Your Selection
.
Enter Question
Type your prompt in the text input field and press return
(macOS) or enter
(Windows/Linux).
This approach is ideal for localized queries where you need quick insights or guidance on a specific selection.
Adding Context to Copilot Chats
There are a number of individual items you can add as context to a chat, namely Files
, Folders
, Snippets
, Websites
, and Messages
.
This flexibility is particularly useful when the reference material you want to use isn’t directly accessible in Obsidian or when you want to compartmentalize context, avoiding overlap between files or projects.
To do this, you can select the Starred Message Icon in the bottom-left corner of your Copilot Chat window, openable from the Obsidian sidebar.
Click the Starred Message Icon then add whatever context items you need.
Adding Code Snippets
You can paste snippets of code as a code block inside of any Copilot Chat by clicking the { }
icon inside the chat window, then pasting in your code.
This is useful for bringing in code that isn’t present immediately in the active file as context, or for comparisons and suggestions.
Extracting Code from Screenshots
You can also extract code from screenshots directly from the Copilot chat menu by selecting Extract Code from Screenshot
, selecting the desired screenshot from your Finder (macOS) or File Explorer (Windows/Linux) menu, and confirming.
Pieces Copilot will then scan the screenshot and generate the code captured from the image into the chat, from which you can copy, insert at your cursor, save it as a snippet, and more.
Adding Folders from File Explorer
If you right-click on a folder in Obsidian’s file explorer, you’ll see the following options: Pieces: Add Vault to Copilot Context
and Pieces: Add File to Copilot Context
, so you can take any folder or file in the project you’re working in and immediately have the Pieces Copilot interact with it.
Improving Code Consistency & Standardization
The Pieces Copilot helps improve code quality by identifying inconsistencies and providing actionable suggestions for standardization.
Naming Inconsistencies
If functions across your workspace use inconsistent naming patterns (e.g., authenticateUser
in authHandler.go
vs. retrieveUserProfile
in userHandler.go
), Pieces Copilot can suggest adopting a standardized naming convention for better readability and maintainability, like this:
func authenticateUser(ctx context.Context, credentials Credentials) (User, error) {
if credentials.Username == "" || credentials.Password == "" {
return User{}, errors.New("missing credentials")
}
}
Inconsistent Error Handling
If error-handling strategies differ across files (e.g., structured errors in authService.go
vs. inconsistent handling in userService.go
), Pieces Copilot can help unify the approach:
func LoginUser(credentials Credentials) (string, error) {
token, err := authenticate(credentials)
if err != nil {
return "", fmt.Errorf("login failed: %w", err)
}
return token, nil
}