Skip to content

Commit

Permalink
Fix deleting API key
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaraJay committed Nov 11, 2023
1 parent b49ef45 commit a128b0b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ ipcMain.handle('set-ai-key', async (event, secretKey) => {
return await keytar.setPassword('pile', 'aikey', secretKey);
});

ipcMain.handle('delete-ai-key', async (event) => {
return await keytar.deletePassword('pile', 'aikey');
});

// Link preview
ipcMain.handle('get-link-preview', async (event, url) => {
const preview = await getLinkPreview(url)
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/context/AIContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const AIContextProvider = ({ children }) => {
return window.electron.ipc.invoke('set-ai-key', secretKey);
};

const deleteKey = () => {
return window.electron.ipc.invoke('delete-ai-key');
};

const getCompletion = async (model = 'gpt-3', context) => {
const response = await ai.chat.completions.create({
model: 'gpt-4',
Expand All @@ -67,6 +71,7 @@ export const AIContextProvider = ({ children }) => {
prompt,
setKey,
getKey,
deleteKey,
getCompletion,
};

Expand Down
6 changes: 4 additions & 2 deletions src/renderer/pages/Pile/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'renderer/context/PilesContext';

export default function Settings() {
const { ai, prompt, getKey, setKey } = useAIContext();
const { ai, prompt, getKey, setKey, deleteKey } = useAIContext();
const [key, setCurrentKey] = useState('');
const { currentTheme, setTheme } = usePilesContext();

Expand All @@ -27,7 +27,9 @@ export default function Settings() {
};

const handleSaveChanges = () => {
if (key != '') {
if (key == '') {
deleteKey();
} else {
setKey(key);
}
};
Expand Down

0 comments on commit a128b0b

Please sign in to comment.