File tree Expand file tree Collapse file tree 2 files changed +14
-14
lines changed
Expand file tree Collapse file tree 2 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -14,11 +14,10 @@ export function ChatForm({ documentContent }: { documentContent: string }) {
1414 setIsLoading ( true ) ;
1515 setResponse ( "" ) ;
1616
17- const formData = new FormData ( ) ;
18- formData . append ( "message" , inputValue ) ;
19- formData . append ( "documentContent" , documentContent ) ;
20-
21- const result = await askAI ( { response : "" , error : null } , formData ) ;
17+ const result = await askAI ( {
18+ userQuestion : inputValue ,
19+ documentContent : documentContent ,
20+ } ) ;
2221
2322 if ( result . error ) {
2423 setResponse ( `エラー: ${ result . error } ` ) ;
Original file line number Diff line number Diff line change @@ -7,26 +7,27 @@ interface FormState {
77 error : string | null ;
88}
99
10+ interface ChatParams {
11+ userQuestion : string ;
12+ documentContent : string ;
13+ }
14+
1015const genAI = new GoogleGenerativeAI ( process . env . API_KEY ! ) ;
1116
12- export async function askAI (
13- prevState : FormState ,
14- formData : FormData
15- ) : Promise < FormState > {
16- const message = formData . get ( 'message' ) ;
17- const documentContent = formData . get ( 'documentContent' ) ;
17+ export async function askAI ( params : ChatParams ) : Promise < FormState > {
18+ const { userQuestion, documentContent } = params ;
1819
19- if ( ! message || typeof message !== 'string' || message . trim ( ) === '' ) {
20+ if ( ! userQuestion || userQuestion . trim ( ) === '' ) {
2021 return { response : '' , error : 'メッセージを入力してください。' } ;
2122 }
2223
23- if ( ! documentContent || typeof documentContent !== 'string' ) {
24+ if ( ! documentContent ) {
2425 return { response : '' , error : 'コンテキストとなるドキュメントがありません。' } ;
2526 }
2627
2728 try {
2829 const model = genAI . getGenerativeModel ( { model : "gemini-1.5-flash" } ) ;
29- const fullMessage = documentContent + "\n\n" + message ;
30+ const fullMessage = documentContent + "\n\n" + userQuestion ;
3031 const result = await model . generateContent ( fullMessage ) ;
3132 const response = result . response ;
3233 const text = response . text ( ) ;
You can’t perform that action at this time.
0 commit comments