├── README.md ├── .env.local.example ├── .vscode └── settings.json ├── app ├── favicon.ico ├── layout.tsx ├── api │ ├── chat │ │ └── route.ts │ └── chat-with-functions │ │ └── route.ts ├── globals.css ├── function-calling │ └── page.tsx └── page.tsx ├── public ├── images │ ├── banner │ │ ├── 01.png │ │ ├── 02.png │ │ ├── 03.png │ │ └── 02_SP.png │ ├── icons │ │ ├── close.png │ │ ├── submit.png │ │ └── phone-solid.png │ ├── common │ │ └── fix-btn.png │ └── logo │ │ ├── logo-img.png │ │ └── logo-text.png └── iframe │ └── index.html ├── next.config.js ├── postcss.config.js ├── .gitignore ├── tailwind.config.js ├── tsconfig.json ├── package.json └── yarn.lock /README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.env.local.example: -------------------------------------------------------------------------------- 1 | OPENAI_API_KEY=xxxxxxx -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "liveServer.settings.port": 5501 3 | } -------------------------------------------------------------------------------- /app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/app/favicon.ico -------------------------------------------------------------------------------- /public/images/banner/01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/banner/01.png -------------------------------------------------------------------------------- /public/images/banner/02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/banner/02.png -------------------------------------------------------------------------------- /public/images/banner/03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/banner/03.png -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {} 3 | 4 | module.exports = nextConfig 5 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {} 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /public/images/banner/02_SP.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/banner/02_SP.png -------------------------------------------------------------------------------- /public/images/icons/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/icons/close.png -------------------------------------------------------------------------------- /public/images/icons/submit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/icons/submit.png -------------------------------------------------------------------------------- /public/images/common/fix-btn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/common/fix-btn.png -------------------------------------------------------------------------------- /public/images/logo/logo-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/logo/logo-img.png -------------------------------------------------------------------------------- /public/images/logo/logo-text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/logo/logo-text.png -------------------------------------------------------------------------------- /public/images/icons/phone-solid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingtinker/next-openai-app/HEAD/public/images/icons/phone-solid.png -------------------------------------------------------------------------------- /app/layout.tsx: -------------------------------------------------------------------------------- 1 | import './globals.css' 2 | import { Inter } from 'next/font/google' 3 | 4 | const inter = Inter({ subsets: ['latin'] }) 5 | 6 | export const metadata = { 7 | title: 'Create Next App', 8 | description: 'Generated by create next app' 9 | } 10 | 11 | export default function RootLayout({ 12 | children 13 | }: { 14 | children: React.ReactNode 15 | }) { 16 | return ( 17 | 18 |
{children} 19 | 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './pages/**/*.{js,ts,jsx,tsx,mdx}', 5 | './components/**/*.{js,ts,jsx,tsx,mdx}', 6 | './app/**/*.{js,ts,jsx,tsx,mdx}' 7 | ], 8 | theme: { 9 | extend: { 10 | backgroundImage: { 11 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', 12 | 'gradient-conic': 13 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))' 14 | } 15 | }, 16 | letterSpacing: { 17 | tight: '2.5px', 18 | } 19 | }, 20 | plugins: [] 21 | } 22 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true, 17 | "plugins": [ 18 | { 19 | "name": "next" 20 | } 21 | ], 22 | "paths": { 23 | "@/*": ["./*"] 24 | } 25 | }, 26 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 27 | "exclude": ["node_modules"] 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "next-openai", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "ai": "^2.1.31", 13 | "next": "13.4.12", 14 | "openai-edge": "^1.1.0", 15 | "react": "18.2.0", 16 | "react-dom": "^18.2.0" 17 | }, 18 | "devDependencies": { 19 | "@types/node": "^17.0.12", 20 | "@types/react": "18.2.8", 21 | "@types/react-dom": "18.2.4", 22 | "autoprefixer": "^10.4.14", 23 | "eslint": "^7.32.0", 24 | "eslint-config-next": "13.4.12", 25 | "postcss": "^8.4.23", 26 | "tailwindcss": "^3.3.2", 27 | "typescript": "5.1.3" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/api/chat/route.ts: -------------------------------------------------------------------------------- 1 | // ./app/api/chat/route.ts 2 | import { Configuration, OpenAIApi } from 'openai-edge' 3 | import { OpenAIStream, StreamingTextResponse } from 'ai' 4 | 5 | // Create an OpenAI API client (that's edge friendly!) 6 | const config = new Configuration({ 7 | apiKey: process.env.OPENAI_API_KEY 8 | }) 9 | const openai = new OpenAIApi(config) 10 | 11 | // IMPORTANT! Set the runtime to edge 12 | export const runtime = 'edge' 13 | 14 | export async function POST(req: Request) { 15 | // Extract the `prompt` from the body of the request 16 | const { messages } = await req.json() 17 | 18 | // Ask OpenAI for a streaming chat completion given the prompt 19 | const response = await openai.createChatCompletion({ 20 | model: 'gpt-3.5-turbo', 21 | stream: true, 22 | messages: messages.map((message: any) => ({ 23 | content: message.content, 24 | role: message.role 25 | })) 26 | }) 27 | 28 | // Convert the response into a friendly text-stream 29 | const stream = OpenAIStream(response) 30 | // Respond with the stream 31 | return new StreamingTextResponse(stream) 32 | } 33 | -------------------------------------------------------------------------------- /app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | 6 | .chatdlg { 7 | right: -100%; 8 | } 9 | 10 | .chatdlg.active { 11 | right: 0; 12 | animation: slideIn 1s cubic-bezier(0.25, 1, 0.5, 1) 1 forwards; 13 | } 14 | 15 | .chatbtn { 16 | right: -100%; 17 | } 18 | 19 | .chatbtn.active { 20 | right: 0; 21 | /* animation: shrinkToRightSP 0.2s forwards; */ 22 | } 23 | 24 | .chatbtn.active.animation { 25 | animation: shrinkToRightSP 0.2s forwards; 26 | } 27 | 28 | @media(min-width: 640px) { 29 | .chatdlg { 30 | right: 0; 31 | opacity: 0; 32 | animation: slideOut 0s forwards; 33 | } 34 | 35 | .chatdlg.active { 36 | right: 0; 37 | animation: slideIn 1s cubic-bezier(0.25, 1, 0.5, 1) 1 forwards; 38 | } 39 | 40 | .chatbtn.active { 41 | right: 0; 42 | } 43 | 44 | .chatbtn.active.animation { 45 | animation: shrinkToRightPC 0.2s forwards; 46 | } 47 | } 48 | 49 | @keyframes slideIn { 50 | 0% { 51 | transform: translateX(250px); 52 | opacity: 0; 53 | } 54 | 55 | 100% { 56 | transform: translateX(0); 57 | } 58 | 59 | 80%, 60 | 100% { 61 | opacity: 1; 62 | } 63 | } 64 | 65 | @keyframes slideOut { 66 | 0% { 67 | opacity: 1; 68 | height: 750px; 69 | bottom: 20px; 70 | } 71 | 72 | 90% { 73 | height: 1px; 74 | width: 100%; 75 | } 76 | 77 | 100% { 78 | height: 0; 79 | width: 0; 80 | bottom: 20px; 81 | } 82 | } 83 | 84 | @keyframes shrinkToRightPC { 85 | 0% { 86 | width: 450px; 87 | padding-right: 270px; 88 | background-color: #2E63A5; 89 | border-radius: 35px; 90 | } 91 | 92 | 100% { 93 | width: 180px; 94 | padding-right: 0; 95 | background-color: #2E63A5; 96 | border-radius: 35px; 97 | } 98 | } 99 | 100 | @keyframes shrinkToRightSP { 101 | 0% { 102 | width: 96%; 103 | padding-right: calc(96% - 180PX); 104 | background-color: #2E63A5; 105 | border-radius: 35px; 106 | } 107 | 108 | 100% { 109 | width: 180px; 110 | padding-right: 0; 111 | background-color: #2E63A5; 112 | border-radius: 35px; 113 | } 114 | } -------------------------------------------------------------------------------- /app/function-calling/page.tsx: -------------------------------------------------------------------------------- 1 | 'use client' 2 | 3 | import { Message } from 'ai/react' 4 | import { useChat } from 'ai/react' 5 | import { ChatRequest, FunctionCallHandler, nanoid } from 'ai' 6 | 7 | export default function Chat() { 8 | const functionCallHandler: FunctionCallHandler = async ( 9 | chatMessages, 10 | functionCall 11 | ) => { 12 | if (functionCall.name === 'eval_code_in_browser') { 13 | if (functionCall.arguments) { 14 | // Parsing here does not always work since it seems that some characters in generated code aren't escaped properly. 15 | const parsedFunctionCallArguments: { code: string } = JSON.parse( 16 | functionCall.arguments 17 | ) 18 | // WARNING: Do NOT do this in real-world applications! 19 | eval(parsedFunctionCallArguments.code) 20 | const functionResponse = { 21 | messages: [ 22 | ...chatMessages, 23 | { 24 | id: nanoid(), 25 | name: 'eval_code_in_browser', 26 | role: 'function' as const, 27 | content: parsedFunctionCallArguments.code 28 | } 29 | ] 30 | } 31 | return functionResponse 32 | } 33 | } 34 | } 35 | 36 | const { messages, input, handleInputChange, handleSubmit } = useChat({ 37 | api: '/api/chat-with-functions', 38 | experimental_onFunctionCall: functionCallHandler 39 | }) 40 | 41 | // Generate a map of message role to text color 42 | const roleToColorMap: Record119 | 治療のことなど何でもお聞きください。 120 |
121 |個人情報不要です。
122 |123 | ※専門スタッフへの相談・カウンセリングもご利用ください。 124 |
125 |173 | 専門スタッフへの無料相談・無料カウンセリングはこちらから 174 |
175 |269 | 治療のことなど何でもお聞きください。 270 |
271 |個人情報不要です。
272 |273 | ※専門スタッフへの相談・カウンセリングもご利用ください。 274 |
275 |323 | 専門スタッフへの無料相談・無料カウンセリングはこちらから 324 |
325 | 357 |449 | 治療のことなど何でもお聞きください。 450 |
451 |個人情報不要です。
452 |453 | ※専門スタッフへの相談・カウンセリングもご利用ください。 454 |
455 |503 | 専門スタッフへの無料相談・無料カウンセリングはこちらから 504 |
505 | 537 |