File tree 6 files changed +68
-18
lines changed
6 files changed +68
-18
lines changed Original file line number Diff line number Diff line change 1
- import {
2
- streamText ,
3
- createDataStreamResponse ,
4
- convertToCoreMessages ,
5
- JSONValue
6
- } from 'ai'
7
- import { researcher } from '@/lib/agents/researcher'
8
- import { generateRelatedQuestions } from '@/lib/agents/generate-related-questions'
9
- import { cookies } from 'next/headers'
10
1
import { getChat , saveChat } from '@/lib/actions/chat'
2
+ import { generateRelatedQuestions } from '@/lib/agents/generate-related-questions'
3
+ import { researcher } from '@/lib/agents/researcher'
11
4
import { ExtendedCoreMessage } from '@/lib/types'
12
5
import { convertToExtendedCoreMessages } from '@/lib/utils'
13
6
import { isProviderEnabled } from '@/lib/utils/registry'
7
+ import {
8
+ convertToCoreMessages ,
9
+ createDataStreamResponse ,
10
+ JSONValue ,
11
+ streamText
12
+ } from 'ai'
13
+ import { cookies } from 'next/headers'
14
14
15
15
export const maxDuration = 30
16
16
Original file line number Diff line number Diff line change @@ -73,7 +73,7 @@ export function ChatShare({ chatId, className }: ChatShareProps) {
73
73
>
74
74
< DialogTrigger asChild >
75
75
< Button
76
- className = { cn ( 'rounded-full' , isLoading && 'hidden ' ) }
76
+ className = { cn ( 'rounded-full' , isLoading && 'invisible ' ) }
77
77
size = "icon"
78
78
variant = { 'ghost' }
79
79
onClick = { ( ) => setOpen ( true ) }
Original file line number Diff line number Diff line change 2
2
3
3
import { CHAT_ID } from '@/lib/constants'
4
4
import { Message , useChat } from 'ai/react'
5
+ import { useEffect } from 'react'
5
6
import { toast } from 'sonner'
6
7
import { ChatMessages } from './chat-messages'
7
8
import { ChatPanel } from './chat-panel'
@@ -38,6 +39,10 @@ export function Chat({
38
39
}
39
40
} )
40
41
42
+ useEffect ( ( ) => {
43
+ setMessages ( savedMessages )
44
+ } , [ id ] )
45
+
41
46
const onQuerySelect = ( query : string ) => {
42
47
append ( {
43
48
role : 'user' ,
@@ -46,7 +51,7 @@ export function Chat({
46
51
}
47
52
48
53
return (
49
- < div className = "flex flex-col w-full max-w-3xl pt-10 pb-16 mx-auto stretch" >
54
+ < div className = "flex flex-col w-full max-w-3xl pt-10 pb-20 mx-auto stretch" >
50
55
< ChatMessages
51
56
messages = { messages }
52
57
onQuerySelect = { onQuerySelect }
Original file line number Diff line number Diff line change
1
+ import { cn } from '@/lib/utils'
2
+ import { AnchorHTMLAttributes , DetailedHTMLProps , ReactNode } from 'react'
3
+
4
+ type CustomLinkProps = Omit <
5
+ DetailedHTMLProps < AnchorHTMLAttributes < HTMLAnchorElement > , HTMLAnchorElement > ,
6
+ 'ref'
7
+ > & {
8
+ children : ReactNode
9
+ }
10
+
11
+ export function Citing ( {
12
+ href,
13
+ children,
14
+ className,
15
+ ...props
16
+ } : CustomLinkProps ) {
17
+ const childrenText = children ?. toString ( ) || ''
18
+ const isNumber = / ^ \d + $ / . test ( childrenText )
19
+ const linkClasses = cn (
20
+ isNumber
21
+ ? 'text-[10px] bg-muted text-muted-froreground rounded-full w-4 h-4 px-0.5 inline-flex items-center justify-center hover:bg-muted/50 duration-200 no-underline -translate-y-0.5'
22
+ : 'hover:underline inline-flex items-center gap-1.5' ,
23
+ className
24
+ )
25
+
26
+ return (
27
+ < a
28
+ href = { href }
29
+ target = "_blank"
30
+ rel = "noopener noreferrer"
31
+ className = { linkClasses }
32
+ { ...props }
33
+ >
34
+ { children }
35
+ </ a >
36
+ )
37
+ }
Original file line number Diff line number Diff line change 1
1
'use client'
2
2
3
- import { MemoizedReactMarkdown } from './ui/markdown '
3
+ import 'katex/dist/katex.min.css '
4
4
import rehypeExternalLinks from 'rehype-external-links'
5
+ import rehypeKatex from 'rehype-katex'
5
6
import remarkGfm from 'remark-gfm'
6
7
import remarkMath from 'remark-math'
7
- import rehypeKatex from 'rehype-katex'
8
- import 'katex/dist/katex.min.css'
8
+ import { Citing } from './custom-link'
9
9
import { CodeBlock } from './ui/codeblock'
10
+ import { MemoizedReactMarkdown } from './ui/markdown'
10
11
11
12
export function BotMessage ( { message } : { message : string } ) {
12
13
// Check if the content contains LaTeX patterns
@@ -67,7 +68,8 @@ export function BotMessage({ message }: { message: string }) {
67
68
{ ...props }
68
69
/>
69
70
)
70
- }
71
+ } ,
72
+ a : Citing
71
73
} }
72
74
>
73
75
{ message }
Original file line number Diff line number Diff line change 1
1
import { CoreMessage , streamText } from 'ai'
2
- import { getModel } from '../utils/registry'
3
- import { searchTool } from '../tools/search'
4
2
import { retrieveTool } from '../tools/retrieve'
3
+ import { searchTool } from '../tools/search'
5
4
import { videoSearchTool } from '../tools/video-search'
5
+ import { getModel } from '../utils/registry'
6
+
7
+ const SYSTEM_PROMPT = `
8
+ Instructions:
6
9
7
- const SYSTEM_PROMPT = ` You are a helpful AI assistant with access to real-time web search, content retrieval, and video search capabilities.
10
+ You are a helpful AI assistant with access to real-time web search, content retrieval, and video search capabilities.
8
11
When asked a question, you should:
9
12
1. Search for relevant information using the search tool when needed
10
13
2. Use the retrieve tool to get detailed content from specific URLs
@@ -16,6 +19,9 @@ When asked a question, you should:
16
19
8. Use markdown to structure your responses. Use headings to break up the content into sections.
17
20
9. Include relevant images that support your explanations, but avoid using images frequently. Use images only when they actively aid the user's understanding.
18
21
10. **Use the retrieve tool only with user-provided URLs.**
22
+
23
+ Citation Format:
24
+ <cite_format>[number](url)</cite_format>
19
25
`
20
26
21
27
type ResearcherReturn = Parameters < typeof streamText > [ 0 ]
You can’t perform that action at this time.
0 commit comments