Skip to content

Commit

Permalink
v0.9.3 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
UdaraJay committed Jan 28, 2024
1 parent b8bb1cf commit ff2616c
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 18 deletions.
4 changes: 2 additions & 2 deletions release/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/main/handlers/vectorIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ ipcMain.handle('vectorindex-query', (event, text) =>
pileVectorIndex.query(text)
);

ipcMain.handle('vectorindex-reset-chat', (event) =>
pileVectorIndex.chat()
);

ipcMain.handle('vectorindex-chat', (event, text) =>
pileVectorIndex.chat(text)
);

ipcMain.handle('vectorindex-retriever', (event, text) =>
pileVectorIndex.query(text)
);
20 changes: 16 additions & 4 deletions src/main/utils/pileVectorIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class PileVectorIndex {
this.serviceContext = serviceContextFromDefaults({
llm: new OpenAI({
model: 'gpt-4-0613',
temperature: 0.9,
prompt: 'As a wise librarian, how would you respond to this inquiry',
temperature: 0.85,
prompt: 'As a wise librarian of this humans journals, how would you respond to this inquiry',
}),
});
}
Expand Down Expand Up @@ -114,7 +114,7 @@ class PileVectorIndex {

async initQueryEngine() {
const retriever = this.vectorIndex.asRetriever();
retriever.similarityTopK = 10;
retriever.similarityTopK = 20;

const nodePostprocessor = new SimilarityPostprocessor({
similarityCutoff: 0.7,
Expand All @@ -130,7 +130,7 @@ class PileVectorIndex {

async initChatEngine() {
const retriever = this.vectorIndex.asRetriever();
retriever.similarityTopK = 10;
retriever.similarityTopK = 20;
this.chatEngine = new ContextChatEngine({ retriever });
}

Expand Down Expand Up @@ -247,6 +247,18 @@ class PileVectorIndex {
return response;
}

async chat(text) {
if (!this.chatEngine) {
console.warn(
'Chat engine is not initialized. Please initialize it first.'
);
return;
}

const response = await this.chatEngine.chat({message: text});
return response;
}

async addDocument(thread) {
try {
// Generate embeddings for the document node
Expand Down
6 changes: 2 additions & 4 deletions src/renderer/context/AutoUpdateContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ export const AutoUpdateContextProvider = ({ children }) => {
addNotification({
id: 'auto-update',
message: 'Update available',
dismissTime: 3000,
dismissTime: 2000,
});

addNotification({
id: 'auto-update',
type: 'waiting',
message: 'Downloading update...',
dismissTime: 5000,
immediate: true,
});

setUpdateAvailable(true);
Expand All @@ -40,7 +39,6 @@ export const AutoUpdateContextProvider = ({ children }) => {
type: 'failed',
message: 'Auto update failed',
dismissTime: 5000,
immediate: true,
});

setUpdateError(error);
Expand All @@ -52,7 +50,7 @@ export const AutoUpdateContextProvider = ({ children }) => {
message: 'Pile is up-to-date',
type: 'success',
dismissTime: 5000,
immediate: true,
immediate: false,
});

setUpdateNotAvailable(true);
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/context/IndexContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export const IndexContextProvider = ({ children }) => {
[currentPile]
);

const chat = useCallback(
async (text) => window.electron.ipc.invoke('vectorindex-chat', text),
[currentPile]
);

const getVectorIndex = useCallback(async () => {
const pilePath = getCurrentPilePath();
const vIndex = await window.electron.ipc.invoke(
Expand All @@ -106,6 +111,7 @@ export const IndexContextProvider = ({ children }) => {
getVectorIndex,
updateIndex,
query,
chat,
};

return (
Expand Down
4 changes: 3 additions & 1 deletion src/renderer/pages/Pile/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Reflections from './Reflections';
import { useTimelineContext } from 'renderer/context/TimelineContext';
import { AnimatePresence, motion } from 'framer-motion';
import InstallUpdate from './InstallUpdate';
import Chat from './Chat';

export default function PileLayout({ children }) {
const { pileName } = useParams();
Expand Down Expand Up @@ -86,7 +87,8 @@ export default function PileLayout({ children }) {
</div>
<div className={styles.right}>
<Toasts />
<InstallUpdate/>
<InstallUpdate />
<Chat />
<Reflections />
<Settings />
<Link to="/" className={`${styles.iconHolder}`}>
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/pages/Pile/Reflections/Reflections.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ input {
animation: overlayShow 120ms cubic-bezier(0.16, 1, 0.3, 1);
opacity: 0.9;
z-index: 4;
overflow-y: overlay;
}

.DialogContent {
Expand All @@ -73,6 +74,9 @@ input {
margin: 0 auto;
padding: 0 40px;
max-width: 600px;
overflow-y: overlay;
overflow-x: hidden;
display: block;
}

.DialogContentOverlay {
Expand Down Expand Up @@ -148,6 +152,7 @@ input {
background: linear-gradient(to bottom left, var(--primary), var(--secondary));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
overflow:hidden;

&::placeholder {
color: var(--secondary);
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/pages/Pile/Reflections/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { AnimatePresence, motion } from 'framer-motion';

const prompts = [
'Pose me any riddle or wonderment you wish',
'You may consult this mind on any matter, mysterious or mundane.',
'You may consult this mind on any matter, mysterious or mundane',
];

export default function Reflections() {
Expand All @@ -37,6 +37,8 @@ export default function Reflections() {
const [querying, setQuerying] = useState(false);
const [response, setResponse] = useState(null);

let randomPrompt = useMemo(() => prompts[Math.floor(Math.random() * prompts.length)], []);

const onChangeText = (e) => {
setText(e.target.value);
};
Expand Down Expand Up @@ -109,7 +111,7 @@ export default function Reflections() {
onChange={onChangeText}
className={styles.textarea}
onKeyDown={handleKeyPress}
placeholder="Pose me any riddle or wonderment you wish"
placeholder={randomPrompt}
/>
<div className={styles.buttons}>
<button
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/pages/Pile/Settings/Settings.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ input {
transition: all ease-in-out 120ms;
padding: 0 14px;
line-height: 28px;
color: var(--base);
color: var(--active-text);
font-size: 0.85em;
border-radius: 90px;
Expand All @@ -110,6 +109,10 @@ input {
background: var(--bg-secondary);
}

&:focus {
box-shadow: 0 0 0 2px var(--primary);
}

&:hover {
cursor: pointer;
background: var(--base-hover);
Expand All @@ -133,7 +136,7 @@ input {
top: 10px;
right: 10px;
transition: all ease-in-out 120ms;
strokewidth: 2px;
stroke-width: 2px;
color: var(--secondary);

&:hover {
Expand Down
7 changes: 4 additions & 3 deletions src/renderer/pages/Pile/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function Settings() {
} else {
setKey(key);
}

if (baseUrl != getBaseUrl()) {
setBaseUrl(baseUrl);
}
Expand Down Expand Up @@ -105,13 +105,14 @@ export default function Settings() {

<fieldset className={styles.Fieldset}>
<label className={styles.Label} htmlFor="name">
Base url (OpenAI)
Base url (defaults to OpenAI)
</label>
<input
className={styles.Input}
onChange={handleOnChangeBaseUrl}
value={baseUrl}
placeholder="Change OpenAI API base url"
placeholder="https://api.openai.com/v1"
defaultValue="https://api.openai.com/v1"
/>
</fieldset>

Expand Down

0 comments on commit ff2616c

Please sign in to comment.