Skip to content

Commit bc3cd85

Browse files
committed
Add search and chat buttons
1 parent 347ec49 commit bc3cd85

File tree

5 files changed

+48
-3
lines changed

5 files changed

+48
-3
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
**/.DS_Store
33

44
# -=- Eroxl's Device Specific Ignores -=-
5-
**/Icon?
5+
Icon?
6+
!icons
67

78
# -=- Node Modules -=-
89
**/node_modules/**
@@ -15,4 +16,4 @@
1516
**/cypress/videos
1617

1718
# -=- Security -=-
18-
/config/.env
19+
/config/.env

backend/src/helpers/getChatResponse.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import ChromaClient from './clients/ChromaClient';
33

44
import type { ChatCompletionRequestMessage } from 'openai';
55

6+
const RELATIVE_TEXT_COUNT = 3;
7+
68
const CONTEXT_PROMPT_TEMPLATE = '### Context: ';
79

810
const QUESTION_PROMPT_TEMPLATE = '### Question: ';
@@ -47,7 +49,7 @@ const getChatResponse = async (
4749
// ~ Query the database for the most similar message
4850
const similarMessages = await blockCollection.query(
4951
embeddings.data.data[0].embedding,
50-
1,
52+
RELATIVE_TEXT_COUNT,
5153
{
5254
userID: user,
5355
},
@@ -89,6 +91,9 @@ const getChatResponse = async (
8991
.join('\n')
9092

9193

94+
// ~ TODO: Start adding support for streaming the response
95+
// https://www.reddit.com/r/ChatGPT/comments/11m3jdw/chatgpt_api_streaming/
96+
// https://gist.github.com/montanaflynn/6a438f0be606daede899
9297
const response = await OpenAIClient.createChatCompletion({
9398
messages: [
9499
{

web/src/components/pageInfo/PageSidebar.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import React, { useState, useEffect } from 'react';
2+
import Image from 'next/image';
23

34
import PageSidebarItem from './PageSidebarItem';
5+
import Brain from '../../public/icons/Brain.svg';
6+
import Search from '../../public/icons/Search.svg';
47

58
export interface PageSidebarItemProps {
69
_id: string,
@@ -55,6 +58,36 @@ const PageSidebar = () => {
5558

5659
return (
5760
<div className="absolute h-screen pt-12 pr-3 select-none print:h-max w-52 print:w-0 bg-amber-400/10 no-scrollbar dark:bg-white/10">
61+
<div className="flex flex-col w-full gap-2 pb-2 pl-3">
62+
<button
63+
className="flex flex-row gap-1 p-2 py-1 text-left text-white rounded hover:bg-white/20"
64+
onClick={() => {
65+
document.dispatchEvent(new CustomEvent('openSearchModal'));
66+
}}
67+
>
68+
<Image
69+
src={Search}
70+
alt="Search"
71+
width={24}
72+
height={24}
73+
/>
74+
Search
75+
</button>
76+
<button
77+
className="flex flex-row gap-1 p-2 py-1 text-left text-white rounded hover:bg-white/20"
78+
onClick={() => {
79+
document.dispatchEvent(new CustomEvent('openChatPage'));
80+
}}
81+
>
82+
<Image
83+
src={Brain}
84+
alt="Chat"
85+
width={24}
86+
height={24}
87+
/>
88+
Chat
89+
</button>
90+
</div>
5891
{/* ~ Render the page tree after it has been loaded */}
5992
{!isLoading && (
6093
(pageTree as PageSidebarItemProps[]).map((pageItem) => {

web/src/public/icons/Brain.svg

+3
Loading

web/src/public/icons/Search.svg

+3
Loading

0 commit comments

Comments
 (0)