@@ -7,31 +7,45 @@ import { Suspense } from 'react';
77function ChatContent ( ) {
88 const { messages, input, handleInputChange, handleSubmit } = useChat ( ) ;
99 const [ token ] = useQueryState ( 'token' ) ;
10-
11- return (
12- < div className = "flex flex-col w-full max-w-md py-24 mx-auto stretch" >
13- { messages . map ( m => (
14- < div key = { m . id } className = "whitespace-pre-wrap" >
15- { m . role === 'user' ? 'User: ' : 'AI: ' }
16- { m . toolInvocations ? (
17- < pre > { JSON . stringify ( m . toolInvocations , null , 2 ) } </ pre >
18- ) : (
19- < p > { m . content } </ p >
20- ) }
21- </ div >
22- ) ) }
10+ const [ aiKey , setAiKey ] = useQueryState ( 'ai_key' ) ;
2311
24- < form onSubmit = { ( e ) => {
25- handleSubmit ( e , { headers : { token : token ?? '' } } ) ;
26- } } >
12+ return (
13+ < >
14+ < div className = "fixed top-0 w-full max-w-md p-4 bg-white" >
15+ < span className = "inline-block w-24" > Token:</ span >
2716 < input
28- className = "fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl"
29- value = { input }
30- placeholder = "Say something..."
31- onChange = { handleInputChange }
17+ type = "password"
18+ className = "inline-block w-full p-2 border border-gray-300 rounded"
19+ value = { aiKey || '' }
20+ onChange = { ( e ) => setAiKey ( e . target . value ) }
21+ placeholder = "Enter your OpenAI/Anthropic API key..."
3222 />
33- </ form >
34- </ div >
23+ </ div >
24+
25+ < div className = "flex flex-col w-full max-w-md py-24 mx-auto stretch" >
26+ { messages . map ( m => (
27+ < div key = { m . id } className = "whitespace-pre-wrap" >
28+ { m . role === 'user' ? 'User: ' : 'AI: ' }
29+ { m . toolInvocations ? (
30+ < pre > { JSON . stringify ( m . toolInvocations , null , 2 ) } </ pre >
31+ ) : (
32+ < p > { m . content } </ p >
33+ ) }
34+ </ div >
35+ ) ) }
36+
37+ < form onSubmit = { ( e ) => {
38+ handleSubmit ( e , { headers : { token : token ?? '' , ai_key : aiKey ?? '' } } ) ;
39+ } } >
40+ < input
41+ className = "fixed bottom-0 w-full max-w-md p-2 mb-8 border border-gray-300 rounded shadow-xl"
42+ value = { input }
43+ placeholder = "Say something..."
44+ onChange = { handleInputChange }
45+ />
46+ </ form >
47+ </ div >
48+ </ >
3549 ) ;
3650}
3751
0 commit comments