Skip to content

Commit c7012bb

Browse files
committed
Merge remote-tracking branch 'origin/main' into cloudflare
2 parents 8fe1002 + 7fd6956 commit c7012bb

File tree

5 files changed

+155
-4
lines changed

5 files changed

+155
-4
lines changed

app/[docs_id]/chatForm.tsx

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,111 @@
22

33
import { hello } from "./chatServer";
44

5-
export function ChatForm() {
6-
return <button className="btn" onClick={hello}>あああ</button>
7-
}
5+
export function ChatForm() {return (
6+
<>
7+
<style jsx>{`
8+
/* 簡単なCSSで見た目を整える(オプション) */
9+
.form-container {
10+
background-color: white;
11+
border-radius: 10px;
12+
box-shadow: 0 4px 8px rgba(67, 204, 216, 0.86);
13+
padding: 20px;
14+
width: 90%;
15+
max-width: 1000px;
16+
display: flex;
17+
flex-direction: column;
18+
}
19+
.input-area {
20+
border: 1px solid #ccc;
21+
border-radius: 8px;
22+
padding: 5px 15 px;
23+
margin-bottom: 15px;
24+
min-height: 150px; /* 入力欄の高さ */
25+
display: flex;
26+
}
27+
.text-input {
28+
border: none;
29+
outline: none;
30+
flex-grow: 1;
31+
font-size: 16px;
32+
resize: none; /* テキストエリアのリサイズを無効化 */
33+
overflow: auto;
34+
padding: 10px;
35+
}
36+
.controls {
37+
display: flex;
38+
align-items: center;
39+
justify-content: space-between;
40+
}
41+
.left-icons button {
42+
background: none;
43+
border: none;
44+
font-size: 24px;
45+
cursor: pointer;
46+
color: #555;
47+
margin-right: 15px;
48+
padding: 5px;
49+
}
50+
.left-icons button:hover {
51+
color: #000;
52+
}
53+
.left-icons span {
54+
font-size: 14px;
55+
vertical-align: middle;
56+
margin-left: 5px;
57+
color: #555;
58+
}
59+
.right-controls {
60+
display: flex;
61+
align-items: center;
62+
}
63+
.voice-icon button {
64+
background: none;
65+
border: none;
66+
font-size: 24px;
67+
cursor: pointer;
68+
color: #555;
69+
margin-right: 15px;
70+
padding: 5px;
71+
}
72+
.voice-icon button:hover {
73+
color: #000;
74+
}
75+
.send-button {
76+
background-color: #007bff; /* 青色の送信ボタン */
77+
color: white;
78+
border: none;
79+
border-radius: 50%; /* 丸いボタン */
80+
width: 40px;
81+
height: 40px;
82+
display: flex;
83+
justify-content: center;
84+
align-items: center;
85+
font-size: 20px;
86+
cursor: pointer;
87+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
88+
transition: background-color 0.3s ease;
89+
}
90+
.send-button:hover {
91+
background-color: #0056b3;
92+
}
93+
`}</style>
94+
95+
<div className="form-container">
96+
<div className="input-area">
97+
<textarea className="text-input" placeholder="質問を入力してください"></textarea>
98+
</div>
99+
100+
<div className="controls">
101+
<div className="left-icons">
102+
103+
</div>
104+
<div className="right-controls">
105+
<button type="submit" className="send-button" title="送信">
106+
<span className="icon"></span>
107+
</button>
108+
</div>
109+
</div>
110+
</div>
111+
</>
112+
)}

app/[docs_id]/chatServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"use server";
22

33
export async function hello() {
4-
console.log("hello, world");
4+
55
}

app/chat/route.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { NextResponse } from 'next/server';
2+
import { GoogleGenerativeAI } from '@google/generative-ai';
3+
4+
5+
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
6+
7+
export async function POST(request) {
8+
const { message } = await request.json();
9+
10+
11+
if (!message) {
12+
return NextResponse.json(
13+
{ error: "メッセージがありません。" },
14+
{ status: 400 }
15+
);
16+
}
17+
18+
try {
19+
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });
20+
21+
const result = await model.generateContent(message);
22+
const response = result.response;
23+
const text = response.text();
24+
25+
return NextResponse.json({ response: text });
26+
27+
} catch (e) {
28+
29+
console.error("Error:", e);
30+
return NextResponse.json(
31+
{ response: "エラーが発生しました。" },
32+
{ status: 500 }
33+
);
34+
}
35+
}

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts"
1414
},
1515
"dependencies": {
16+
"@google/generative-ai": "^0.24.1",
1617
"@opennextjs/cloudflare": "^1.6.3",
1718
"next": "<15.4",
1819
"react": "19.1.0",

0 commit comments

Comments
 (0)