Azure OpenAI Embeddings QnA 项目教程
1. 项目的目录结构及介绍
azure-open-ai-embeddings-qna/
├── README.md
├── app/
│ ├── __init__.py
│ ├── main.py
│ ├── config.py
│ ├── utils.py
│ └── templates/
│ └── index.html
├── requirements.txt
└── tests/
└── test_main.py
README.md
: 项目说明文档。app/
: 包含项目的主要代码文件。__init__.py
: 初始化文件。main.py
: 项目的启动文件。config.py
: 项目的配置文件。utils.py
: 工具函数文件。templates/
: 包含HTML模板文件。index.html
: 主页模板。
requirements.txt
: 项目依赖文件。tests/
: 包含测试文件。test_main.py
: 主程序的测试文件。
2. 项目的启动文件介绍
app/main.py
是项目的启动文件,负责初始化应用并启动服务器。以下是该文件的主要内容:
from flask import Flask, render_template
from config import Config
app = Flask(__name__)
app.config.from_object(Config)
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
Flask
是用于创建Web应用的框架。Config
是从config.py
中导入的配置类。index
函数定义了主页的路由和渲染的模板。app.run(debug=True)
启动Flask应用,并开启调试模式。
3. 项目的配置文件介绍
app/config.py
是项目的配置文件,包含应用的配置信息。以下是该文件的主要内容:
import os
class Config:
SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess'
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY')
DATABASE_URI = os.environ.get('DATABASE_URI') or 'sqlite:///app.db'
SECRET_KEY
: 应用的密钥,用于加密。OPENAI_API_KEY
: OpenAI API的密钥。DATABASE_URI
: 数据库的连接URI。
这些配置信息可以通过环境变量设置,也可以使用默认值。