Skip to content

Commit 5dfab79

Browse files
committed
FormDataからオブジェクトに変更
1 parent 85891bf commit 5dfab79

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

app/[docs_id]/chatForm.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff 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}`);

app/actions/chatActions.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff 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+
1015
const 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();

0 commit comments

Comments
 (0)