Skip to content

Commit

Permalink
Fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaraJay committed Jul 26, 2024
1 parent 145291c commit 4230fed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "Pile",
"version": "0.9.8",
"version": "0.9.9",
"keywords": [
"pile"
],
Expand Down
27 changes: 2 additions & 25 deletions src/renderer/pages/Pile/Settings/AISettingsTabs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { CardIcon, OllamaIcon, BoxOpenIcon } from 'renderer/icons';
import { useIndexContext } from 'renderer/context/IndexContext';

export default function AISettingTabs() {
export default function AISettingTabs({ APIkey, setCurrentKey }) {
const {
prompt,
setPrompt,
Expand All @@ -29,36 +29,13 @@ export default function AISettingTabs() {
} = useAIContext();

const { currentTheme, setTheme } = usePilesContext();
const [key, setCurrentKey] = useState('');

useEffect(() => {
retrieveKey();

if (ollama) {
setPileAIProvider('ollama');
}
}, [ollama]);

const retrieveKey = async () => {
const k = await getKey();
setCurrentKey(k);
};

const handleTabChange = (newValue) => {
setPileAIProvider(newValue);
};

const handleInputChange = (setter) => (e) => setter(e.target.value);

const handleSaveChanges = () => {
if (!key || key == '') {
deleteKey();
} else {
setKey(key);
}
updateSettings(prompt);
};

const renderThemes = () => {
return Object.entries(availableThemes).map(([theme, colors]) => (
<button
Expand Down Expand Up @@ -230,7 +207,7 @@ export default function AISettingTabs() {
id="openai-api-key"
className={styles.input}
onChange={handleInputChange(setCurrentKey)}
value={key}
value={APIkey}
placeholder="Paste an OpenAI API key to enable AI reflections"
/>
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/pages/Pile/Settings/Settings.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ input {
transform: translate(-50%, -50%);
width: 90vw;
max-width: 500px;
max-height: 85vh;
max-height: 95vh;
padding: 18px;
animation: contentShow 150ms cubic-bezier(0.16, 1, 0.3, 1);
overflow-y: overlay;
Expand Down
11 changes: 6 additions & 5 deletions src/renderer/pages/Pile/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Settings() {
ollama,
baseUrl,
} = useAIContext();
const [key, setCurrentKey] = useState('');
const [APIkey, setCurrentKey] = useState('');
const { currentTheme, setTheme } = usePilesContext();

const retrieveKey = async () => {
Expand Down Expand Up @@ -56,14 +56,15 @@ export default function Settings() {
};

const handleSaveChanges = () => {
if (!key || key == '') {
if (!APIkey || APIkey == '') {
deleteKey();
} else {
setKey(key);
console.log('save key', APIkey);
setKey(APIkey);
}

updateSettings(prompt);
regenerateEmbeddings();
// regenerateEmbeddings();
};

const renderThemes = () => {
Expand Down Expand Up @@ -109,7 +110,7 @@ export default function Settings() {
<label className={styles.Label} htmlFor="name">
Select your AI provider
</label>
<AISettingTabs />
<AISettingTabs APIkey={APIkey} setCurrentKey={setCurrentKey} />
</fieldset>

<fieldset className={styles.Fieldset}>
Expand Down

0 comments on commit 4230fed

Please sign in to comment.