wuyiqunLu commited on
Commit
58d7e55
1 Parent(s): 760e83d

feat: add message to ask user login (#36)

Browse files

TODO: ask user to visit va.landing.ai on hugging face
<img width="963" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/0b2bc134-2562-43df-ad96-ffd395e66a1c">
<img width="1301" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/132986242/fb4a17c8-c2ea-4153-9b92-bad52e7e07b1">

app/api/chat/route.ts CHANGED
@@ -10,10 +10,6 @@ import { MessageBase } from '../../../lib/types';
10
 
11
  export const runtime = 'edge';
12
 
13
- const openai = new OpenAI({
14
- apiKey: process.env.OPENAI_API_KEY,
15
- });
16
-
17
  export const POST = async (req: Request) => {
18
  const json = await req.json();
19
  const { messages } = json as {
@@ -43,6 +39,9 @@ export const POST = async (req: Request) => {
43
  };
44
  },
45
  );
 
 
 
46
  const res = await openai.chat.completions.create({
47
  model: 'gpt-4-vision-preview',
48
  messages: formattedMessage,
 
10
 
11
  export const runtime = 'edge';
12
 
 
 
 
 
13
  export const POST = async (req: Request) => {
14
  const json = await req.json();
15
  const { messages } = json as {
 
39
  };
40
  },
41
  );
42
+ const openai = new OpenAI({
43
+ apiKey: process.env.OPENAI_API_KEY,
44
+ });
45
  const res = await openai.chat.completions.create({
46
  model: 'gpt-4-vision-preview',
47
  messages: formattedMessage,
app/chat/[id]/page.tsx CHANGED
@@ -1,5 +1,7 @@
1
  import { getKVChat } from '@/lib/kv/chat';
2
  import { Chat } from '@/components/chat';
 
 
3
 
4
  interface PageProps {
5
  params: {
@@ -10,5 +12,6 @@ interface PageProps {
10
  export default async function Page({ params }: PageProps) {
11
  const { id: chatId } = params;
12
  const chat = await getKVChat(chatId);
13
- return <Chat chat={chat} />;
 
14
  }
 
1
  import { getKVChat } from '@/lib/kv/chat';
2
  import { Chat } from '@/components/chat';
3
+ import { auth } from '@/auth';
4
+ import { Session } from 'next-auth';
5
 
6
  interface PageProps {
7
  params: {
 
12
  export default async function Page({ params }: PageProps) {
13
  const { id: chatId } = params;
14
  const chat = await getKVChat(chatId);
15
+ const session = await auth();
16
+ return <Chat chat={chat} session={session} />;
17
  }
components/chat/ChatList.tsx CHANGED
@@ -3,14 +3,37 @@
3
  import { Separator } from '@/components/ui/Separator';
4
  import { ChatMessage } from '@/components/chat/ChatMessage';
5
  import { MessageBase } from '../../lib/types';
 
 
 
6
 
7
  export interface ChatList {
8
  messages: MessageBase[];
 
9
  }
10
 
11
- export function ChatList({ messages }: ChatList) {
12
  return (
13
  <div className="relative mx-auto max-w-5xl px-8 pr-12">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  {messages
15
  // .filter(message => message.role !== 'system')
16
  .map((message, index) => (
 
3
  import { Separator } from '@/components/ui/Separator';
4
  import { ChatMessage } from '@/components/chat/ChatMessage';
5
  import { MessageBase } from '../../lib/types';
6
+ import { Session } from 'next-auth';
7
+ import { IconExclamationTriangle } from '../ui/Icons';
8
+ import Link from 'next/link';
9
 
10
  export interface ChatList {
11
  messages: MessageBase[];
12
+ session: Session | null;
13
  }
14
 
15
+ export function ChatList({ messages, session }: ChatList) {
16
  return (
17
  <div className="relative mx-auto max-w-5xl px-8 pr-12">
18
+ {!session && (
19
+ <>
20
+ <div className="group relative mb-4 flex items-center">
21
+ <div className="bg-background flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow">
22
+ <IconExclamationTriangle />
23
+ </div>
24
+ <div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden">
25
+ <p className="text-muted-foreground leading-normal">
26
+ Please{' '}
27
+ <Link href="/sign-in" className="underline">
28
+ log in
29
+ </Link>{' '}
30
+ to save and revisit your chat history!
31
+ </p>
32
+ </div>
33
+ </div>
34
+ <Separator className="my-4" />
35
+ </>
36
+ )}
37
  {messages
38
  // .filter(message => message.role !== 'system')
39
  .map((message, index) => (
components/chat/index.tsx CHANGED
@@ -5,12 +5,14 @@ import { Composer } from '@/components/chat/Composer';
5
  import { ChatEntity } from '@/lib/types';
6
  import useVisionAgent from '@/lib/hooks/useVisionAgent';
7
  import { useScrollAnchor } from '@/lib/hooks/useScrollAnchor';
 
8
 
9
  export interface ChatProps extends React.ComponentProps<'div'> {
10
  chat: ChatEntity;
 
11
  }
12
 
13
- export function Chat({ chat }: ChatProps) {
14
  const { url, id } = chat;
15
  const { messages, append, reload, stop, isLoading, input, setInput } =
16
  useVisionAgent(chat);
@@ -22,7 +24,7 @@ export function Chat({ chat }: ChatProps) {
22
  <>
23
  <div className="h-full overflow-auto relative" ref={scrollRef}>
24
  <div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
25
- <ChatList messages={messages} />
26
  <div className="h-px w-full" ref={visibilityRef} />
27
  </div>
28
  </div>
 
5
  import { ChatEntity } from '@/lib/types';
6
  import useVisionAgent from '@/lib/hooks/useVisionAgent';
7
  import { useScrollAnchor } from '@/lib/hooks/useScrollAnchor';
8
+ import { Session } from 'next-auth';
9
 
10
  export interface ChatProps extends React.ComponentProps<'div'> {
11
  chat: ChatEntity;
12
+ session: Session | null;
13
  }
14
 
15
+ export function Chat({ chat, session }: ChatProps) {
16
  const { url, id } = chat;
17
  const { messages, append, reload, stop, isLoading, input, setInput } =
18
  useVisionAgent(chat);
 
24
  <>
25
  <div className="h-full overflow-auto relative" ref={scrollRef}>
26
  <div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
27
+ <ChatList messages={messages} session={session} />
28
  <div className="h-px w-full" ref={visibilityRef} />
29
  </div>
30
  </div>
components/project/ProjectChat.tsx CHANGED
@@ -34,7 +34,7 @@ const ProjectChat: React.FC<ChatProps> = ({ mediaList }) => {
34
  <>
35
  <div className="h-full overflow-auto" ref={scrollRef}>
36
  <div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
37
- <ChatList messages={messages} />
38
  <div className="h-px w-full" ref={visibilityRef} />
39
  </div>
40
  </div>
 
34
  <>
35
  <div className="h-full overflow-auto" ref={scrollRef}>
36
  <div className="pb-[200px] pt-4 md:pt-10" ref={messagesRef}>
37
+ <ChatList messages={messages} session={null} />
38
  <div className="h-px w-full" ref={visibilityRef} />
39
  </div>
40
  </div>
components/ui/Icons.tsx CHANGED
@@ -551,6 +551,28 @@ function IconLoading({ className, ...props }: React.ComponentProps<'svg'>) {
551
  );
552
  }
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
  export {
555
  IconEdit,
556
  IconNextChat,
@@ -582,4 +604,5 @@ export {
582
  IconGoogle,
583
  IconLoading,
584
  IconDiscord,
 
585
  };
 
551
  );
552
  }
553
 
554
+ function IconExclamationTriangle({
555
+ className,
556
+ ...props
557
+ }: React.ComponentProps<'svg'>) {
558
+ return (
559
+ <svg
560
+ width="15"
561
+ height="15"
562
+ viewBox="0 0 15 15"
563
+ fill="none"
564
+ xmlns="http://www.w3.org/2000/svg"
565
+ >
566
+ <path
567
+ d="M8.4449 0.608765C8.0183 -0.107015 6.9817 -0.107015 6.55509 0.608766L0.161178 11.3368C-0.275824 12.07 0.252503 13 1.10608 13H13.8939C14.7475 13 15.2758 12.07 14.8388 11.3368L8.4449 0.608765ZM7.4141 1.12073C7.45288 1.05566 7.54712 1.05566 7.5859 1.12073L13.9798 11.8488C14.0196 11.9154 13.9715 12 13.8939 12H1.10608C1.02849 12 0.980454 11.9154 1.02018 11.8488L7.4141 1.12073ZM6.8269 4.48611C6.81221 4.10423 7.11783 3.78663 7.5 3.78663C7.88217 3.78663 8.18778 4.10423 8.1731 4.48612L8.01921 8.48701C8.00848 8.766 7.7792 8.98664 7.5 8.98664C7.2208 8.98664 6.99151 8.766 6.98078 8.48701L6.8269 4.48611ZM8.24989 10.476C8.24989 10.8902 7.9141 11.226 7.49989 11.226C7.08567 11.226 6.74989 10.8902 6.74989 10.476C6.74989 10.0618 7.08567 9.72599 7.49989 9.72599C7.9141 9.72599 8.24989 10.0618 8.24989 10.476Z"
568
+ fill="currentColor"
569
+ fill-rule="evenodd"
570
+ clip-rule="evenodd"
571
+ ></path>
572
+ </svg>
573
+ );
574
+ }
575
+
576
  export {
577
  IconEdit,
578
  IconNextChat,
 
604
  IconGoogle,
605
  IconLoading,
606
  IconDiscord,
607
+ IconExclamationTriangle,
608
  };