Skip to content

Commit

Permalink
Merge pull request #4 from tg1482/fix_query
Browse files Browse the repository at this point in the history
Fix query
  • Loading branch information
tg1482 authored Apr 16, 2023
2 parents 4be1ba5 + 71d49ed commit 43d6579
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
7 changes: 0 additions & 7 deletions components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const Settings: React.FC<SettingsProps> = ({
const [activeSubGroup,setActiveSubGroup] = useState<string | null>(null);

const setSessionState = async (user: any) => {
console.log("Setting stage",user)
if (user) {
if (user.id !== -99) {
const response = await fetch(`/api/get-query-counts?userId=${user.id}`);
Expand Down Expand Up @@ -186,13 +185,11 @@ export const Settings: React.FC<SettingsProps> = ({
});

if (result?.error) {
console.log(result.error);
alert("Incorrect email or password");
} else {
const session = await getSession();
if (session) {
// The user is now signed in; handle the signed-in state here.
console.log("User is signed in:",session.user);
setSessionState(session.user);
setUserSignedIn(true);
setActiveSubGroup(null);
Expand Down Expand Up @@ -240,8 +237,6 @@ export const Settings: React.FC<SettingsProps> = ({
throw new Error(error.error);
}

console.log('User created successfully!');

const responseBody = await response.json();
const userId = parseInt(responseBody.userId);

Expand All @@ -258,8 +253,6 @@ export const Settings: React.FC<SettingsProps> = ({

await createSubscription(1,userId);

console.log('Subscription created successfully!');

// sign in
await handleSignIn();

Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "app",
"version": "0.1.0",
"private": true,
"engines": {
"node": "18.5"
},
"scripts": {
"dev": "next dev",
"build": "next build",
Expand Down Expand Up @@ -60,4 +63,4 @@
"tailwindcss": "^3.2.7",
"tsx": "^3.12.3"
}
}
}
10 changes: 8 additions & 2 deletions pages/api/vectordbqa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ export default async function handler(
res.write(`data: ${data}\n\n`);
};

// Heartbeat
const heartbeatInterval = setInterval(() => {
res.write(':heartbeat\n');
},5 * 1000); // Send heartbeat every 5 seconds

const testRegex = /testing|test|test123/;
if (testRegex.test(prompt)) {
sendData(JSON.stringify({ data: "test answer" }));
sendData(JSON.stringify({ data: "DONE" }));
clearInterval(heartbeatInterval);
res.end();
return;
}
Expand All @@ -62,8 +68,7 @@ export default async function handler(
sendData(JSON.stringify({ data: token }));
},
}),
}
);
});

const chain = VectorDBQAChain.fromLLM(model,vectorStore);
chain.returnSourceDocuments = false;
Expand All @@ -78,6 +83,7 @@ export default async function handler(
console.log("Error in LLM, sending DONE and closing connection")
} finally {
sendData(JSON.stringify({ data: "DONE" }));
clearInterval(heartbeatInterval);
res.end();
}
}
17 changes: 3 additions & 14 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ function Home() {

const { data: session } = useSession();

console.log(session);

const setSessionState = async (user: any) => {
console.log("Setting stage",user)
if (user) {
if (user.id !== -99) {
const response = await fetch(`/api/get-query-counts?userId=${user.id}`);
Expand Down Expand Up @@ -142,7 +139,6 @@ function Home() {
// Save session with the latest values when the user leaves the tab
useEffect(() => {
const saveSession = () => {
console.log("Saving session");
if (userId == -99 && session) {
sessionStorage.setItem(
"session",
Expand All @@ -151,7 +147,6 @@ function Home() {
}
};
saveSession();
console.log(userAgeGroup,userSex,userFitnessLevel,userAnythingElse);
},[freeQueries,queryCount,session,userId]);

// Handle answer
Expand All @@ -178,19 +173,14 @@ function Home() {
searchSettings = `You will give a detailed response to the question, but not too scientific. Break your response into:
1. Background in one paragraph
2. Main response in one paragraph
3. Counter argument in one paragraph
4. And final takeaway in one paragraph.
5. In the end, remind that you are a bot and that you are not Professor Andrew Huberman.
3. And final takeaway in one paragraph.
Highlight the important parts in bold.`;
}
else if (userSearchParameters === "Protocol" || query.toLowerCase().includes("protocol")) {
searchSettings = `I am looking for a detailed protocol for the topic. Break your response into:
1. Background in one paragraph
2. The protocol in bullet points
3. Recommendations on the protocol in bullet points
4. Cautions on the protocol in bullet points
5. And final takeaway in one paragraph.
6. In the end, remind that you are a bot and that you are not Professor Andrew Huberman.
3. Cautions on the protocol in bullet points
Highlight the important parts in bold.`;
}

Expand Down Expand Up @@ -238,8 +228,6 @@ function Home() {

const ctrl = new AbortController();

console.log("Prompt",prompt);

await fetchEventSource("/api/vectordbqa",{
method: "POST",
headers: {
Expand All @@ -251,6 +239,7 @@ function Home() {
const data = JSON.parse(event.data);
if (data.data === "DONE") {
// Request complete
setAnswer((prev) => prev + ` \n \n Note: I am an AI language model and not Professor Andrew Huberman.`);
postCompletion(apiKey,queryCount);
} else {
// Stream text
Expand Down

1 comment on commit 43d6579

@vercel
Copy link

@vercel vercel bot commented on 43d6579 Apr 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

huber-gpt – ./

huber-gpt-tg1482.vercel.app
huber-gpt.vercel.app
huber-gpt-git-main-tg1482.vercel.app
www.hubergpt.com

Please sign in to comment.