Introduction to PacketLLM

Introduction

PacketLLM is an RStudio gadget for AI-assisted development. It runs in the Viewer pane and connects to an AI backend, giving you a chat interface without leaving RStudio.

With PacketLLM, you can: - Generate code and explanations. - Analyze text and tabular data from uploaded files (.R, .pdf, .docx, .txt, .csv). - Manage multiple conversations in tabs. - Customize model behavior through settings.

This vignette will guide you through the essential setup and basic usage.

Prerequisites: API Key

PacketLLM requires an API key set in your environment.

  • Obtain an API key: Create an API key with your AI provider.

  • Configure the API Key:
    The recommended method is to set the OPENAI_API_KEY environment variable.

    Using .Renviron (recommended):

    Add the following line to your user or project .Renviron file (replace 'your_secret_api_key_here' with your actual key):

    OPENAI_API_KEY='your_secret_api_key_here'

    You can open the file using (requires the usethis package):

    usethis::edit_r_environ()           # User-level
    usethis::edit_r_environ("project")  # Project-level

    Important: Restart your R session after editing .Renviron.

    Temporary Solution:

    For the current session only, run:

    Sys.setenv(OPENAI_API_KEY = "your_secret_api_key_here")

Installation

Install PacketLLM from CRAN:

install.packages("PacketLLM")

Development version from GitHub:

# install.packages("remotes")
remotes::install_github("AntoniCzolgowski/PacketLLM")

Launching the Chat Gadget

Once installed and your API key is set, launch the gadget from the R console:

library(PacketLLM)
run_llm_chat_app()

This command should be executed in an interactive RStudio session.

Understanding the Interface

The PacketLLM interface consists of:

  • Top Navigation Bar:

    • Settings: Configure the model, and system message (before sending the first message).
    • New Conversation: Create a new chat tab.
    • Close App (X): Exit the PacketLLM gadget.
  • Conversation Tabs:
    Switch between multiple chat sessions; each tab can be closed individually.

  • Chat History Area:
    Displays the dialogue between you and the AI.

  • Input Area:

    • + Button: Open a file browser to attach supported files (.R, .pdf, .docx, .txt, .csv) as context.
    • Attachments Staging Area: Lists selected files pending for upload.
    • Text Input Box: Where you type your message.
    • Send Button: Send your message and any attached files to the model.

Basic Workflow

  1. Launch the App: Run run_llm_chat_app().
  2. Start Chatting: Type your question or prompt.
  3. Send Message: Click the Send button.
  4. Wait for Response: The app will show a processing indicator while waiting for the model’s reply.

Optional steps: - Add File Context: Click the + button to attach files before sending. - Start a New Conversation: Click New Conversation for a fresh session. - Adjust Settings: Use Settings to change model options before sending the first message.

Exploring Further

Experiment with different models, system prompts, and file attachments to enhance your workflow with PacketLLM. For issues or suggestions, please visit the GitHub Issues page.