File tree Expand file tree Collapse file tree 2 files changed +36
-50
lines changed
Expand file tree Collapse file tree 2 files changed +36
-50
lines changed Original file line number Diff line number Diff line change 1+ // npm install @google /generative-ai
2+ import { NextResponse } from 'next/server' ;
3+ import { GoogleGenerativeAI } from '@google/generative-ai' ;
4+
5+
6+ const genAI = new GoogleGenerativeAI ( process . env . API_KEY ) ;
7+
8+ export async function POST ( request ) {
9+ const { message } = await request . json ( ) ;
10+
11+
12+ if ( ! message ) {
13+ return NextResponse . json (
14+ { error : "メッセージがありません。" } ,
15+ { status : 400 }
16+ ) ;
17+ }
18+
19+ try {
20+ const model = genAI . getGenerativeModel ( { model : "gemini-1.5-flash" } ) ;
21+
22+ const result = await model . generateContent ( message ) ;
23+ const response = result . response ;
24+ const text = response . text ( ) ;
25+
26+ return NextResponse . json ( { response : text } ) ;
27+
28+ } catch ( e ) {
29+
30+ console . error ( "Error:" , e ) ;
31+ return NextResponse . json (
32+ { response : "エラーが発生しました。" } ,
33+ { status : 500 }
34+ ) ;
35+ }
36+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments