Added error handling.
Replaced icon
@@ -19,13 +19,13 @@ The plugin can be configured by clicking the plugin button in the Chrome toolbar
|
||||
These are the tools that are currently available:
|
||||
|
||||
### Auto-complete
|
||||
Select a text and press `Alt+c` to trigger the auto-complete tool.
|
||||
Select a text and press `Alt+C` to trigger the auto-complete tool.
|
||||
|
||||
### Improve
|
||||
Select a text and press `Alt+i` to trigger the improvement tool. The original text will be commented out and the improved text will be inserted below it.
|
||||
Select a text and press `Alt+I` to trigger the improvement tool. The original text will be commented out and the improved text will be inserted below it.
|
||||
|
||||
### Ask
|
||||
Select a text and press `Alt+a` to trigger the ask tool. The original text will be deleted and the answer will be inserted in its place.
|
||||
Select a text and press `Alt+A` to trigger the ask tool. The original text will be deleted and the answer will be inserted in its place.
|
||||
|
||||
For example: "Create a table 4x3 that the first row is bold face" will be replaced with, e.g.,:
|
||||
```latex
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"action": {
|
||||
"default_popup": "popup/popup.html",
|
||||
"default_icon": "popup/icon.png"
|
||||
"default_icon": "popup/LeafLLM.png"
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
@@ -11,9 +11,9 @@
|
||||
],
|
||||
"description": "LLM-based tools for Overleaf",
|
||||
"icons": {
|
||||
"16": "popup/icon_16.png",
|
||||
"48": "popup/icon_48.png",
|
||||
"128": "popup/icon_128.png"
|
||||
"16": "popup/LeafLLM_16.png",
|
||||
"48": "popup/LeafLLM_48.png",
|
||||
"128": "popup/LeafLLM_128.png"
|
||||
},
|
||||
"commands": {
|
||||
"Complete": {
|
||||
|
||||
BIN
popup/Leaf.png
Normal file
|
After Width: | Height: | Size: 320 KiB |
BIN
popup/LeafLLM.xcf
Normal file
BIN
popup/LeafLLM_128.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
popup/LeafLLM_16.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
popup/LeafLLM_48.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
popup/icon.png
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 23 KiB |
|
Before Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 12 KiB |
@@ -90,7 +90,7 @@ function commentText(text) {
|
||||
}
|
||||
|
||||
async function improveTextHandler(openAI) {
|
||||
if (!(await settingIsEnabled('textImprovement'))) return
|
||||
if (!(await settingIsEnabled('textImprovement'))) throw new Error('Text improvement is not enabled.')
|
||||
const selection = window.getSelection()
|
||||
const selectedText = selection.toString()
|
||||
if (!selectedText) return
|
||||
@@ -100,7 +100,7 @@ async function improveTextHandler(openAI) {
|
||||
}
|
||||
|
||||
async function completeTextHandler(openAI) {
|
||||
if (!(await settingIsEnabled('textCompletion'))) return
|
||||
if (!(await settingIsEnabled('textCompletion'))) throw new Error('Text completion is not enabled.')
|
||||
const selection = window.getSelection()
|
||||
const selectedText = selection.toString()
|
||||
if (!selectedText) return
|
||||
@@ -109,7 +109,7 @@ async function completeTextHandler(openAI) {
|
||||
}
|
||||
|
||||
async function askHandler(openAI) {
|
||||
if (!(await settingIsEnabled('textAsk'))) return
|
||||
if (!(await settingIsEnabled('textAsk'))) throw new Error('Text ask is not enabled.')
|
||||
const selection = window.getSelection()
|
||||
const selectedText = selection.toString()
|
||||
if (!selectedText) return
|
||||
@@ -129,21 +129,20 @@ function setAPIKey(key) {
|
||||
currentAPIKey = key
|
||||
if (currentAPIKey) {
|
||||
openAI = new OpenAIAPI(currentAPIKey)
|
||||
console.log('AI4Overleaf: OpenAI API key set, enabling AI4Overleaf features.')
|
||||
console.log('LeafLLM: OpenAI API key set, enabling LeafLLM features.')
|
||||
} else {
|
||||
openAI = undefined
|
||||
console.log('AI4Overleaf: OpenAI API key is not set, AI4Overleaf features are disabled.')
|
||||
console.log('LeafLLM: OpenAI API key is not set, LeafLLM features are disabled.')
|
||||
}
|
||||
}
|
||||
|
||||
function handleCommand(command) {
|
||||
console.log('Handling command')
|
||||
if (command === 'Improve') {
|
||||
improveTextHandler(openAI)
|
||||
improveTextHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||
} else if (command === 'Complete') {
|
||||
completeTextHandler(openAI)
|
||||
completeTextHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||
} else if (command === 'Ask') {
|
||||
askHandler(openAI)
|
||||
askHandler(openAI).catch(e => console.error(`Failed to execute the '${command}' command. Error message: ${e}`))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||