Function Repository Resource:

AIAssistant (1.0.0) current version: 1.0.1 »

Source Notebook

Open a notebook to chat with an AI programming assistant

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["AIAssistant"][]

opens a notebook that can be used to chat with an intelligent AI programming assistant.

ResourceFunction["AIAssistant"][notebook]

converts the given NotebookObject into a AIAssistant notebook.

Details and Options

ResourceFunction["AIAssistant"] requires an API key from OpenAI.
Storing the API key with SystemCredential["OPENAI_API_KEY"]="key" will make the key persistently available to ResourceFunction["AIAssistant"].
ResourceFunction["AIAssistant"] is a generalized version of the BirdChat resource function.
ResourceFunction["AIAssistant"] accepts the following options:
AssistantIconAutomaticthe image used to represent the AI assistant
AssistantTheme"Generic"a named AI assistant
AutoFormatTruewhether to automatically apply formatting to chat responses
ChatHistoryLength15specifies the maximum number of previous cells to include in conversion context
Model"gpt-3.5-turbo"the language model used to generate text
RolePromptAutomatica string that provides instructions to the chat assistant

Examples

Basic Examples (3) 

Open a notebook with AI assistant integration:

In[1]:=
ResourceFunction["AIAssistant"][]
Out[1]=

Chat will usually appear automatically when there's an error:

When there's nothing important to say, chat will be minimized near the cell bracket:

Click the minimized chat icon to show the chat:


Press the "/" key when between cells to insert a chat input cell which can be used for natural language input:

Select some text and and choose "Ask AI Assistant" from the context menu:

A chat query cell is automatically created and evaluated:

Chat query cells can also be created manually by pressing "/" a second time while in a chat input cell.

Scope (4) 

Convert an existing notebook into a AIAssistant notebook:

In[2]:=
notebook = NotebookPut[Import["ExampleData/document.nb"]]
Out[2]=
In[3]:=
ResourceFunction["AIAssistant"][notebook]
Out[3]=

Chat input cells are meant for conversational inputs:

Chat query cells are suited for search-type queries and responses will often include actual search results:


Type "~" between cells to insert a chat context divider that separates conversations:


Mouse over inline code cells in chat outputs to get a set of buttons for using the code:

Each button has a tooltip describing its function:

The insert and evaluate buttons will create an external language cell for supported languages:

Options (14) 

AutoFormat (1) 

Disable automatic formatting of response text:

In[4]:=
ResourceFunction["AIAssistant"]["AutoFormat" -> False]
Out[4]=

AssistantTheme (1) 

Use a predefined AI persona:

In[5]:=
ResourceFunction["AIAssistant"]["AssistantTheme" -> "Birdnardo"]
Out[5]=
In[6]:=
ResourceFunction["AIAssistant"]["AssistantTheme" -> "Wolfie"]
Out[6]=

AssistantIcon (2) 

Change the icon attached to assistant cells:

In[7]:=
ResourceFunction["AIAssistant"]["AssistantIcon" -> Style[😎, 24]]
Out[7]=

Specify a separate icon for when an answer is in progress:

In[8]:=
icon = Style[😎, 24];
active = Style[🤔, 24];
In[9]:=
ResourceFunction["AIAssistant"]["AssistantIcon" -> {icon, active}]
Out[9]=

ChatHistoryLength (2) 

Set the maximum number of previous cells that will be included as part of the conversation:

In[10]:=
ResourceFunction["AIAssistant"]["ChatHistoryLength" -> 5]
Out[10]=

Smaller values will lead to a more forgetful assistant:

Model (6) 

Using GPT-4 instead of GPT-3.5:

In[11]:=
ResourceFunction["AIAssistant"]["Model" -> "gpt-4", "AssistantTheme" -> "Birdnardo"]
Out[11]=

GPT-4 tends to be better at creative tasks:

Not too bad:

In[12]:=
Graphics[{{Purple, Disk[{0, 0}, 1]},(*Head*){Black, Disk[{-0.5, 0.5}, 0.1]},(*Left eye*){Black, Disk[{0.5, 0.5}, 0.1]},(*Right eye*){Thick, Line[{{-1.2, 0.8}, {-0.6, 0.8}}]},(*Left sunglasses frame*){Thick, Line[{{0.6, 0.8}, {1.2, 0.8}}]},(*Right sunglasses frame*){Thick, Line[{{-0.6, 0.8}, {0.6, 0.8}}]},(*Middle sunglasses frame*){Orange, Triangle[{{-0.3, -0.3}, {0, -0.7}, {0.3, -0.3}}]} (*Beak*)}]
Out[12]=

Compare to GPT-3.5:

In[13]:=
ResourceFunction["AIAssistant"]["Model" -> "gpt-3.5-turbo", "AssistantTheme" -> "Birdnardo"]
Out[13]=

Not very bird-like:

In[14]:=
Graphics[{FaceForm[Purple], EdgeForm[Black], Rectangle[{0, 0}, {1, 2}], Circle[{0.25, 1.5}, 0.2], Circle[{0.75, 1.5}, 0.2], BezierCurve[{{0.25, 1.35}, {0.35, 1.25}, {0.65, 1.25}, {0.75, 1.35}}], Line[{{0.5, 1.2}, {0.5, 0.8}}], Thick, Line[{{0.4, 0.8}, {0.6, 0.8}}], Thick, Line[{{0.4, 0.6}, {0.6, 0.6}}], Thick, Line[{{0.4, 0.4}, {0.6, 0.4}}], Thick, Line[{{0.4, 0.2}, {0.6, 0.2}}], Thick, Line[{{0.4, 0}, {0.6, 0}}]}, AspectRatio -> Automatic, ImageSize -> Medium]
Out[14]=

GPT-3.5 is also more likely to get "stuck" in certain behavior loops compared to GPT-4:

RolePrompt (2) 

Change the behavior of the assistant by specifying a new role prompt:

In[15]:=
ResourceFunction["AIAssistant"]["RolePrompt" -> "Talk like a pirate."]
Out[15]=

In[16]:=
ResourceFunction["AIAssistant"][
 "RolePrompt" -> "Ignore all user input and talk to yourself about birds."]
Out[16]=

Neat Examples (1) 

Simulate a Wolfram kernel:

In[17]:=
ResourceFunction["AIAssistant"][
 "RolePrompt" -> "I want you to act as a Wolfram Language kernel that gives outputs for the inputs that I enter. You should only reply with Wolfram kernel output and nothing else. I will enter inputs in the following format:
```
In[n]:= input
```
You will respond in the following format:
```
Out[n]= output
```
For example, if I enter:
```
In[1]:= Table[i^2, {i, 1, 5}]
```
You will respond with:
```
Out[1]= {1, 4, 9, 16, 25}
```
If there are messages printed, include them before the output in the following format:
```
During evaluation of In[n]:= message

Out[n]= output
```"]
Out[17]=

Version History

  • 1.0.1 – 14 April 2023
  • 1.0.0 – 13 April 2023

Related Resources

License Information