forked from XuJiachengZust/codeAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_env.py
More file actions
47 lines (39 loc) · 1.25 KB
/
Copy pathsetup_env.py
File metadata and controls
47 lines (39 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
"""
设置环境变量脚本
用于创建 .env 文件
"""
import os
from pathlib import Path
# 项目根目录
project_root = Path(__file__).parent
env_file = project_root / ".env"
# 环境变量内容
env_content = """# OpenAI API配置
OPENAI_API_KEY=sk-TCH20bb662104e289722814524e1fb03958b2afe952YvGEP
OPENAI_BASE=https://api.gptsapi.net
OPENAI_MODEL_CHAT=gpt-4o-mini
OPENAI_MODEL_EMB=text-embedding-ada-002
"""
def main():
"""创建 .env 文件"""
try:
# 写入 .env 文件
with open(env_file, 'w', encoding='utf-8') as f:
f.write(env_content)
print(f"[OK] .env 文件已创建: {env_file}")
print("\n环境变量内容:")
print(env_content)
print("[WARNING] 注意: .env 文件包含敏感信息,请确保不要提交到版本控制系统")
# 验证文件内容
if env_file.exists():
print(f"\n[OK] 文件验证成功,文件大小: {env_file.stat().st_size} 字节")
else:
print("[ERROR] 文件创建失败")
return False
return True
except Exception as e:
print(f"[ERROR] 创建 .env 文件时出错: {e}")
return False
if __name__ == "__main__":
main()