diff --git a/package-lock.json b/package-lock.json
index 70d2e53..bdf5f3b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "codereview.gpt",
- "version": "0.2.0",
+ "version": "0.3.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "codereview.gpt",
- "version": "0.2.0",
+ "version": "0.3.0",
"dependencies": {
"buffer": "^6.0.3",
"chatgpt": "^5.1.3",
diff --git a/public/options.html b/public/options.html
index 1b7ea45..45d1680 100644
--- a/public/options.html
+++ b/public/options.html
@@ -13,9 +13,15 @@
- Please store your Open AI API Key here. Fetch one at https://platform.openai.com/account/api-keys.
+ Open AI API Key
+ Please store your Open AI API Key. Fetch one at https://platform.openai.com/account/api-keys.
+
+ OpenAPI Base URL
+ Please store your custom OpenAPI Base URL here.
+
+
diff --git a/src/options.js b/src/options.js
index 3b23bdd..dd45d28 100644
--- a/src/options.js
+++ b/src/options.js
@@ -1,30 +1,32 @@
// Saves options to chrome.storage
const saveOptions = () => {
- const openai_apikey = document.getElementById('openai_apikey').value;
-
- chrome.storage.sync.set(
- { openai_apikey: openai_apikey },
- () => {
- // Update status to let user know options were saved.
- const status = document.getElementById('status');
- status.textContent = 'Options saved.';
- setTimeout(() => {
- status.textContent = '';
- }, 750);
- }
- );
- };
-
- // Restores select box and checkbox state using the preferences
- // stored in chrome.storage.
- const restoreOptions = () => {
- chrome.storage.sync.get(
- { openai_apikey: '' },
- (items) => {
- document.getElementById('openai_apikey').value = items.openai_apikey;
- }
- );
- };
-
- document.addEventListener('DOMContentLoaded', restoreOptions);
- document.getElementById('save').addEventListener('click', saveOptions);
\ No newline at end of file
+ const openai_apikey = document.getElementById('openai_apikey').value;
+ const openai_base_url = document.getElementById('openai_base_url').value;
+
+ chrome.storage.sync.set(
+ { openai_apikey: openai_apikey, openai_base_url: openai_base_url },
+ () => {
+ // Update status to let user know options were saved.
+ const status = document.getElementById('status');
+ status.textContent = 'Options saved.';
+ setTimeout(() => {
+ status.textContent = '';
+ }, 750);
+ }
+ );
+};
+
+// Restores select box and checkbox state using the preferences
+// stored in chrome.storage.
+const restoreOptions = () => {
+ chrome.storage.sync.get(
+ { openai_apikey: '', openai_base_url: 'https://api.openai.com/v1' },
+ (items) => {
+ document.getElementById('openai_apikey').value = items.openai_apikey;
+ document.getElementById('openai_base_url').value = items.openai_base_url;
+ }
+ );
+};
+
+document.addEventListener('DOMContentLoaded', restoreOptions);
+document.getElementById('save').addEventListener('click', saveOptions);
\ No newline at end of file
diff --git a/src/popup.js b/src/popup.js
index 781dca4..b3d6cf6 100644
--- a/src/popup.js
+++ b/src/popup.js
@@ -52,10 +52,20 @@ async function getApiKey() {
return options['openai_apikey'];
}
+async function getBaseURL() {
+ let options = await new Promise((resolve) => {
+ chrome.storage.sync.get('openai_base_url', resolve);
+ });
+ console.log(options);
+ return options['openai_base_url'];
+}
+
async function callChatGPT(messages, callback, onDone) {
let apiKey;
+ let baseURL;
try {
apiKey = await getApiKey();
+ baseURL = await getBaseURL();
} catch (e) {
callback('Please add your Open AI API key to the settings of this Chrome Extension.');
onDone();
@@ -64,6 +74,7 @@ async function callChatGPT(messages, callback, onDone) {
const api = new ChatGPTAPI({
apiKey: apiKey,
+ apiBaseUrl: baseURL,
systemMessage: `You are a programming code change reviewer, provide feedback on the code changes given. Do not introduce yourselves.`
})