Skip to content

Commit f808be5

Browse files
author
Ali Raheem
committed
Add basic length control
1 parent 978a638 commit f808be5

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

aify.xpi

208 Bytes
Binary file not shown.

plugin/html/draft.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ document.addEventListener("DOMContentLoaded", async function () {
1414
}
1515
});
1616
async function callBackendAPI(original, action) {
17-
const data = await browser.storage.local.get(["model", "apiKey"]);
17+
const data = await browser.storage.local.get(["model", "apiKey", "maxTokens"]);
1818
const model = data.model;
1919
const apiKey = data.apiKey;
20+
const maxTokens = parseInt(data.maxTokens);
21+
console.log(maxTokens);
2022
const response = await fetch("https://api.openai.com/v1/chat/completions", {
2123
method: "POST",
2224
headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}` },
23-
body: JSON.stringify({ model: model, messages: [{ role: "user", content: `${action}\n---\n${original}` }] }),
25+
body: JSON.stringify({
26+
model: model,
27+
messages: [{ role: "user", content: `${action}\n---\n${original}` }],
28+
...(maxTokens ? { 'max_tokens': maxTokens } : {})
29+
}),
2430
});
2531
if (!response.ok) {
2632
throw new Error(`API request failed: ${response.status}`);

plugin/html/settings.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ label {
2323
.button {
2424
color: #fff;
2525
padding: 12px 20px;
26-
border: none;
2726
border-radius: 4px;
2827
cursor: pointer;
2928
}

plugin/html/settings.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ <h1>Aify Settings</h1>
5252
<div class="col-25"> <label for="api-key">API Key</label></div>
5353
<div class="col-75"> <input type="text" id="api-key" placeholder="Your API Key.." class="full-width"></div>
5454
</div>
55+
<div class="row">
56+
<div class="col-25"> <label for="max-tokens">Max Length (in tokens)</label></div>
57+
<div class="col-75">
58+
<select id="max-tokens">
59+
<option value="0">Unlimited</option>
60+
<option value="300">Long (300 tokens)</option>
61+
<option value="100">Medium (100 tokens)</option>
62+
<option value="50">Short (50 tokens)</option>
63+
</select>
64+
</div>
65+
</div>
5566
<div class="row">
5667
<div class="col-25"> <label for="actions-container">Actions</label> </div>
5768
<div class="col-75"> <div class="container" id="actions-container"> </div></div>

plugin/html/settings.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ document.addEventListener("DOMContentLoaded", function () {
44
var actionsContainer = document.getElementById("actions-container");
55
var addActionButton = document.getElementById("add-action");
66
var saveButton = document.getElementById("save-settings");
7+
var maxTokensInput = document.getElementById("max-tokens");
78
var defaultButton = document.getElementById("default-settings");
89
var defaultActions = [
910
{ name: "Reply to this", prompt: "Reply to the following email." },
@@ -14,9 +15,10 @@ document.addEventListener("DOMContentLoaded", function () {
1415
{ name: "Prompt provided", prompt: " " },
1516
];
1617
var defaultModel = "gpt-3.5-turbo";
17-
browser.storage.local.get(["model", "apiKey", "actions"], function (data) {
18+
browser.storage.local.get(["model", "apiKey", "actions", "maxTokens"], function (data) {
1819
modelSelect.value = data.model || defaultModel;
1920
apiKeyInput.value = data.apiKey || "";
21+
maxTokensInput.value = data.maxTokens || 0;
2022
var actions = data.actions || defaultActions;
2123
actions.forEach(function (action) {
2224
addAction(action.name, action.prompt);
@@ -31,14 +33,15 @@ document.addEventListener("DOMContentLoaded", function () {
3133
var promptInput = actionDiv.querySelector(".action-prompt");
3234
return { name: nameInput.value, prompt: promptInput.value };
3335
});
34-
browser.storage.local.set({ model: modelSelect.value, apiKey: apiKeyInput.value, actions: actions });
36+
browser.storage.local.set({ model: modelSelect.value, apiKey: apiKeyInput.value, actions: actions, maxTokens: maxTokensInput.value });
3537
});
3638
defaultButton.addEventListener("click", function () {
3739
while (actionsContainer.firstChild) {
3840
actionsContainer.removeChild(actionsContainer.firstChild);
3941
}
4042
modelSelect.value = defaultModel;
4143
apiKeyInput.value = "";
44+
maxTokens.value = 0;
4245
defaultActions.forEach(function (action) {
4346
addAction(action.name, action.prompt);
4447
});

0 commit comments

Comments
 (0)