Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability Enhancements and Bug Fixes #193

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
NEXT_PUBLIC_API_URL="https://ayushma-api.ohc.network/api/"
NEXT_PUBLIC_COOKIE_STORAGE="ayushma-storage"
NEXT_PUBLIC_AI_NAME="Ayushma"
NEXT_PUBLIC_AI_DESCRIPTION="Revolutionizing medical diagnosis through AI and Opensource"
NEXT_PUBLIC_AI_DESCRIPTION="Ayushma - Revolutionizing Healthcare Delivery Through AI and Open Source"
NEXT_PUBLIC_AI_WARNING="Please be aware that Ayushma AI may generate inaccurate information; kindly report any concerns to [email protected]"
NEXT_PUBLIC_GOOGLE_RECAPTCHA_SITE_KEY="6Lerts4nAAAAAKyXaNZkYj4XfRO0M2R-XYIA3qv8"
2 changes: 1 addition & 1 deletion src/app/(auth)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function AuthLayout({
<div className="w-[300px] flex flex-col gap-4">
<div>
<img
src={(storage.theme || storage.preferedTheme) === 0 ? (process.env.NEXT_PUBLIC_LOGO_URL || "/logo_text.svg") : (process.env.NEXT_PUBLIC_LOGO_DARK_URL || "/logo_white.svg")}
src={(storage.theme || storage.preferredTheme) === 0 ? (process.env.NEXT_PUBLIC_LOGO_URL || "/logo_text.svg") : (process.env.NEXT_PUBLIC_LOGO_DARK_URL || "/logo_white.svg")}
alt="Logo"
className="w-full object-contain"
/>
Expand Down
43 changes: 0 additions & 43 deletions src/app/(main)/client.tsx

This file was deleted.

58 changes: 41 additions & 17 deletions src/app/(main)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,47 @@
import { Project } from "@/types/project";
import { API } from "@/utils/api";
import { redirect } from "next/navigation";
import Client from "./client";
"use client";

const getDefaultProject = async () => {
//const projects = await API.projects.list();
//return projects.results.find((project: Project) => project.is_default);
}
import { Project } from "@/types/project";
import { API, paginatedResponse } from "@/utils/api";
import { useQuery } from "@tanstack/react-query";
import { useRouter } from "next/navigation";
import { useEffect } from "react";

export default async function Page() {
let defaultProject;
try {
//defaultProject = await getDefaultProject();
export default function Page() {
const projectsQuery = useQuery<paginatedResponse<Project>>({
queryKey: ["projects", "app"],
queryFn: () =>
API.projects.list({
ordering: "-is_default,created_at",
}),
});
const router = useRouter();

} catch (error) {
console.log(error);
}
useEffect(() => {
const defaultProject = projectsQuery.data?.results?.find(
(project: Project) => project.is_default,
);
if (defaultProject) router.push(`/project/${defaultProject.external_id}`);
}, [projectsQuery.data]);

//if (defaultProject) redirect(`/project/${defaultProject.external_id}`);
return (
<div className="flex flex-col justify-center items-center h-screen">
{projectsQuery.isLoading && (
<div className="flex items-center">
<div className="w-4 h-4 mr-2 rounded-full bg-gray-900 animate-pulse"></div>
<div className="w-4 h-4 mr-2 rounded-full bg-gray-900 animate-pulse"></div>
<div className="w-4 h-4 rounded-full bg-gray-900 animate-pulse"></div>
</div>
)}

return <Client />
{!projectsQuery.isLoading &&
!projectsQuery.data?.results?.find(
(project: Project) => project.is_default,
) && (
<div className="flex flex-col justify-center items-center">
<i className="fa-regular fa-folder-open text-4xl"></i>
<div className="mt-5 font-semibold">No default project found</div>
</div>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion src/app/(main)/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export default function Page() {
</Button>
</div>
</div>
<Toaster />
<Toaster position="top-right" />
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(main)/project/[project_id]/chat/[chat_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ChatBar from "@/components/chatbar";
import ChatBlock from "@/components/chatblock";
import { storageAtom } from "@/store";
import { Chat, ChatConverseStream, ChatMessageType } from "@/types/chat";
import { ChatType, ChatConverseStream, ChatMessageType } from "@/types/chat";
import { Project } from "@/types/project";
import { API } from "@/utils/api";
import { getFormData } from "@/utils/converse";
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function Chat(
});
const project: Project | undefined = projectQuery.data;

const chat: Chat | undefined = chatQuery.data;
const chat: ChatType | undefined = chatQuery.data;
const [autoPlayIndex, setAutoPlayIndex] = useState<number>(-1);

const openai_key =
Expand Down
90 changes: 44 additions & 46 deletions src/app/(main)/project/[project_id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export default function Chat(params: { params: { project_id: string } }) {
router.push(`/project/${project_id}/chat/${chatID}?autoplay`);
}, [chatID, isTyping, project_id, router]);

const projectQuery = useQuery(
{
queryKey: ["chat", project_id],
queryFn: () => API.projects.get(project_id),
refetchOnWindowFocus: false,
},
);
const projectQuery = useQuery({
queryKey: ["chat", project_id],
queryFn: () => API.projects.get(project_id),
refetchOnWindowFocus: false,
});
const project: Project | undefined = projectQuery.data;

const streamChatMessage = async (message: ChatConverseStream) => {
if (chat === "") setChat(message.input);
setChatMessage((prevChatMessage) => {
const updatedChatMessage = prevChatMessage + message.delta;
const updatedChatMessage = (prevChatMessage + message.delta)
.replaceAll(`${process.env.NEXT_PUBLIC_AI_NAME}:`, "")
.trimStart();
return updatedChatMessage;
});
if (message.stop) setIsTyping(false);
Expand All @@ -54,39 +54,35 @@ export default function Chat(params: { params: { project_id: string } }) {
}
};

const newChatMutation = useMutation(
{
mutationFn: () =>
API.chat.create(
project_id,
chat !== "" ? chat.slice(0, 50) : "new chat",
storage.openai_api_key,
),
retry: false,
},
);

const converseMutation = useMutation(
{
mutationFn: (params: { external_id: string; formdata: FormData }) =>
API.chat.converse(
project_id,
params.external_id,
params.formdata,
openai_key,
streamChatMessage,
20,
!project?.assistant_id,
),
retry: false,
onSuccess: async (data, vars) => {
if (!data) return;
setChatID(data.external_id);
await queryClient.invalidateQueries({ queryKey: ["chats"] });
setIsTyping(false);
},
const newChatMutation = useMutation({
mutationFn: () =>
API.chat.create(
project_id,
chat !== "" ? chat.slice(0, 50) : "new chat",
storage.openai_api_key,
),
retry: false,
});

const converseMutation = useMutation({
mutationFn: (params: { external_id: string; formdata: FormData }) =>
API.chat.converse(
project_id,
params.external_id,
params.formdata,
openai_key,
streamChatMessage,
20,
!project?.assistant_id,
),
retry: false,
onSuccess: async (data, vars) => {
if (!data) return;
setChatID(data.external_id);
await queryClient.invalidateQueries({ queryKey: ["chats"] });
setIsTyping(false);
},
);
});

const getFormData = async (blobUrl?: string, text?: string) => {
const fd = new FormData();
Expand Down Expand Up @@ -118,7 +114,6 @@ export default function Chat(params: { params: { project_id: string } }) {
setIsTyping(false);
setApiError(e?.error?.error);
}

};

const handleAudio = async (blobUrl: string) => {
Expand All @@ -132,16 +127,18 @@ export default function Chat(params: { params: { project_id: string } }) {
project_id,
external_id,
sttFormData,
)
);

setChat(transcript);

const fd = await getFormData(undefined, transcript);
fd.append("transcript_start_time", stats.transcript_start_time.toString());
fd.append(
"transcript_start_time",
stats.transcript_start_time.toString(),
);
fd.append("transcript_end_time", stats.transcript_end_time.toString());
converseMutation.mutate({ external_id, formdata: fd });
}
catch (e: any) {
} catch (e: any) {
setIsTyping(false);
setApiError(e?.error?.error);
}
Expand All @@ -168,7 +165,8 @@ export default function Chat(params: { params: { project_id: string } }) {
setChat(prompt);
setIsTyping(true);
const fd = await getFormData(undefined, prompt);
const { external_id } = await newChatMutation.mutateAsync();
const { external_id } =
await newChatMutation.mutateAsync();
if (external_id === "") return;
setChatID(external_id);

Expand Down
Loading