Gdańsk AI 项目教程
1. 项目的目录结构及介绍
Gdańsk AI 项目的目录结构如下:
gdansk-ai/
├── ai-api/
│ ├── app/
│ ├── tests/
│ ├── Dockerfile
│ ├── requirements.txt
│ └── ...
├── web-api/
│ ├── src/
│ ├── public/
│ ├── package.json
│ ├── tsconfig.json
│ └── ...
├── web/
│ ├── components/
│ ├── pages/
│ ├── styles/
│ ├── next.config.js
│ ├── package.json
│ └── ...
├── .env.example
├── LICENSE
├── README.md
└── ...
目录介绍
ai-api/
: 包含 AI API 的后端代码,使用 Python 和 FastAPI。web-api/
: 包含 Web API 的后端代码,使用 Node.js 和 TypeScript。web/
: 包含前端代码,使用 Next.js 和 React。.env.example
: 配置文件示例。LICENSE
: 项目许可证。README.md
: 项目说明文档。
2. 项目的启动文件介绍
ai-api 启动文件
在 ai-api/
目录下,主要的启动文件是 app/main.py
。这个文件包含了 FastAPI 应用的入口点。
# app/main.py
from fastapi import FastAPI
from app.routes import router
app = FastAPI()
app.include_router(router)
web-api 启动文件
在 web-api/
目录下,主要的启动文件是 src/index.ts
。这个文件包含了 Node.js 应用的入口点。
// src/index.ts
import express from 'express';
import { router } from './routes';
const app = express();
app.use('/api', router);
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
web 启动文件
在 web/
目录下,主要的启动文件是 pages/_app.tsx
。这个文件是 Next.js 应用的入口点。
// pages/_app.tsx
import '../styles/globals.css'
import type { AppProps } from 'next/app'
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp
3. 项目的配置文件介绍
.env.example
.env.example
文件是一个配置文件示例,包含了项目所需的各种环境变量。
CHATBOT_API_KEY={whatever you decide this value is reused among ai-api web-api and web in this project}
OPEN_AI_API_KEY={go to platform.openai.com, generate and copy-paste API key here}
# Google Cloud API
type=service_account
project_id={project id}
private_key_id=
private_key={multiline private key with structure like this:-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----\n}
client_email={project name}@{project id}.iam.gserviceaccount.com
client_id=
auth_uri=https://accounts.google.com/o/oauth2/auth
ai-api 配置文件
在 ai-api/
目录下,配置文件主要是 app/config.py
。
# app/config.py
import os
from dotenv import load_dotenv
load_dotenv()
CHATBOT_API_KEY = os.getenv('CHATBOT_API_KEY')
OPEN_AI_API_KEY = os.getenv('OPEN_AI_API_KEY')
web-api 配置文件
在 web-api/
目录下,配置文件主要是 src/config.ts
。
// src/config.ts
import dotenv from 'dotenv';
dotenv.config();
export const CHATBOT_API_KEY = process.env.CHATBOT_API_