-
Notifications
You must be signed in to change notification settings - Fork 21
/
README.qmd
161 lines (104 loc) · 9.54 KB
/
README.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: chattr
format: md
---
<!-- badges: start -->
[![R-CMD-check](https://github.com/mlverse/chattr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mlverse/chattr/actions/workflows/R-CMD-check.yaml) [![Codecov test coverage](https://codecov.io/gh/mlverse/chattr/branch/main/graph/badge.svg)](https://app.codecov.io/gh/mlverse/chattr?branch=main) [![CRAN status](https://www.r-pkg.org/badges/version/chattr)](https://CRAN.R-project.org/package=chattr) [![](man/figures/lifecycle-experimental.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
```{r}
#| echo: false
#| eval: false
source("utils/toc.R")
toc()
```
```{r}
#| echo: false
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
pkg <- pkgdown::as_pkgdown()
urls <- pkg$desc$get_urls()
url <- urls[grepl(".io", urls)][[1]]
```
<!-- toc: start -->
- [Intro](#intro)
- [Install](#install)
- [Available models](#available-models)
- [Using](#using)
- [The App](#the-app)
- [Additional ways to interact](#additional-ways-to-interact)
- [How it works](#how-it-works)
- [Keyboard Shortcut](#keyboard-shortcut)
- [How to setup the keyboard shortcut](#how-to-setup-the-keyboard-shortcut)
<!-- toc: end -->
## Intro {#intro}
`chattr` is an interface to LLMs (Large Language Models). It enables interaction with the model directly from the RStudio IDE. `chattr` allows you to submit a prompt to the LLM from your script, or by using the provided Shiny Gadget.
This package's main goal is to aid in exploratory data analysis (EDA) tasks. The additional information appended to your request, provides a sort of "guard rails", so that the packages and techniques we usually recommend as best practice, are used in the model's responses.
## Install {#install}
Since this is a very early version of the package install the package from GitHub:
```{r}
#| eval: false
remotes::install_github("mlverse/chattr")
```
## Available models {#available-models}
`chattr` provides two main integration with two main LLM back-ends. Each back-end provides access to multiple LLM types. The plan is to add more back-ends as time goes by:
| Provider | Models | Setup Instructions |
|:-------------------:|:--------------------------------:|:----------------:|
| OpenAI | GPT Models accessible via the OpenAI's REST API. `chattr` provides a convenient way to interact with GPT 4, and 3.5. | [Interact with OpenAI GPT models](https://mlverse.github.io/chattr/articles/openai-gpt.html) |
| [LLamaGPT-Chat](https://github.com/kuvaus/LlamaGPTJ-chat) | LLM models available in your computer. Including GPT-J, LLaMA, and MPT. Tested on a [GPT4ALL](https://gpt4all.io/index.html) model. **LLamaGPT-Chat** is a command line chat program for models written in C++. | [Interact with local models](https://mlverse.github.io/chattr/articles/backend-llamagpt.html) |
| [GitHub Copilot](https://docs.posit.co/ide/user/ide/guide/tools/copilot.html) | AI pair programmer that offers autocomplete-style suggestions as you code | [Interact with GitHub Copilot Chat](https://mlverse.github.io/chattr/articles/copilot-chat.html) |
| [Databricks](https://docs.databricks.com/en/machine-learning/foundation-models/index.html#databricks-foundation-model-apis) | DBRX, Meta Llama 3 70B, and Mixtral 8x7B via [Databricks foundational model REST API](https://docs.databricks.com/en/machine-learning/foundation-models/index.html#pay-per-token-foundation-model-apis). | [Interact with Databricks foundation chat models](https://mlverse.github.io/chattr/articles/backend-databricks.html) |
## Using {#using}
### The App {#the-app}
The main way to use `chattr` is through the Shiny Gadget app. By default, in RStudio the app will run inside the Viewer pane. `chattr` will prompt you to select the model back-end you with to use. The list of the actual models will depend on which of them you have a setup for. If no model setup is found, it will return an error. If you receive the error, please refer to the previous section to learn how to setup a model back-end in your machine. Here is an example of what the selection prompt will look like:
``` r
chattr::chattr_app()
#> ── chattr - Available models
#>
#> 1: GitHub - Copilot Chat - (copilot)
#> 2: OpenAI - Chat Completions - gpt-3.5-turbo (gpt35)
#> 3: OpenAI - Chat Completions - gpt-4 (gpt4)
#> 4: LlamaGPT - ~/ggml-gpt4all-j-v1.3-groovy.bin (llamagpt)
#>
#> Select the number of the model you would like to use:
```
This prompt only occurs the first time you call `chattr_app()`, or `chattr()`. If you close the app, and open it again, the app will use the model you initially selected. The selection is set for the rest of your R session, or until you manually change it. Please note that if, for example, `chattr` cannot find the setup for OpenAI, then those lines would not show up as options in your actual prompt.
If you wish to avoid the interactive prompt, then call `chattr_use()` to designate the model you wish to use before calling the app. You can also use `chattr_use()` to change the model back-end you are interacting with during your R session:
``` r
chattr_use("gpt35")
chattr_app()
```
![Screenshot of the Sniny gadget app in a dark mode RStudio theme](man/figures/readme/chat1.png)
<br>
After the LLM finishes its response, the `chattr` app processes all markdown code chunks. It will place three convenience buttons:
- **Copy to clipboard** - It will write the code inside the chunk to your clipboard.
- **Copy to document** - It will copy-paste the code directly to where the app was called from. If the app is started while working on a script, `chattr` will copy the code to that same script.
- **Copy to new script** - It creates a new R script in the RStudio IDE, and copies the content of the chunk directly to it. Very useful when the LLM writes a Shiny app for you
A lot of effort was put in to make the app's appearance as close as possible to the IDE. This way it feels more integrated with your work space. This includes switching the color scheme based on the current RStudio theme being light, or dark.
The settings screen can be accessed by clicking on the "gear" button. The screen that opens will contain the following:
- Save and Open chats - This is an early experiment to allow us to save and retrieve past chats. `chattr` will save the file in an RDS format. The main objective of this feature, is to be able to see past chats, not to continue previous conversations with the LLM.
- Prompt settings - In this section you can change the additional information attached to your prompt. Including the number of max data files, and data frames sent to the LLM.
![Screenshot of the Sniny gadget options](man/figures/readme/chat2.png)
### Additional ways to interact {#additional-ways-to-interact}
Apart from the Shiny app, `chattr` provides two more ways to interact with the LLM. For details, see: [Other interfaces](https://mlverse.github.io/chattr/articles/other-interfaces.html)
## How it works {#how-it-works}
`chattr` enriches your request with additional instructions, name and structure of data frames currently in your environment, the path for the data files in your working directory. If supported by the model, `chattr` will include the current chat history.
![Diagram that illustrates how `chattr` handles model requests](man/figures/readme/chattr-diagram.png)
To see what `chattr` will send to the model, set the `preview` argument to `TRUE`:
```{r}
library(chattr)
data(mtcars)
data(iris)
chattr_use("gpt4")
chattr(preview = TRUE)
```
## Keyboard Shortcut {#keyboard-shortcut}
The best way to access `chattr`'s app is by setting up a keyboard shortcut for it. This package includes an RStudio Addin that gives us direct access to the app, which in turn, allows a **keyboard shortcut** to be assigned to the addin. The name of the addin is: "Open Chat". If you are not familiar with how to assign a keyboard shortcut see the next section.
### How to setup the keyboard shortcut {#how-to-setup-the-keyboard-shortcut}
- Select *Tools* in the top menu, and then select *Modify Keyboard Shortcuts*
![Screenshot that shows where to find the option to modify the keyboard shortcuts](man/figures/readme/keyboard-shortcuts.png){width="700"}
- Search for the `chattr` adding by writing "open chat", in the search box
![Screenshot that shows where to input the addin search](man/figures/readme/addin-find.png){width="500"}
- To select a key combination for your shortcut, click on the Shortcut box and then type *press* the key combination in your keyboard. In my case, I chose *Ctrl+Shift+C*
![Screenshot that shows what the interface looks like when a shortcut has been selected](man/figures/readme/addin-assign.png){width="500"}