You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
import os
|
|
from dotenv import load_dotenv
|
|
from typing import Optional
|
|
|
|
# 加载环境变量
|
|
load_dotenv()
|
|
|
|
class Settings:
|
|
# 应用配置
|
|
APP_NAME: str = "LangChain Ollama API"
|
|
APP_VERSION: str = "1.0.0"
|
|
APP_DESCRIPTION: str = "基于 Ollama 本地大模型和 LangChain 的 AI 服务 API"
|
|
API_PREFIX: str = os.getenv("API_PREFIX", "/api/v1")
|
|
|
|
# 服务器配置
|
|
HOST: str = os.getenv("HOST", "0.0.0.0")
|
|
PORT: int = int(os.getenv("PORT", "5000"))
|
|
DEBUG: bool = os.getenv("DEBUG", "False").lower() == "true"
|
|
|
|
# Ollama 配置
|
|
OLLAMA_BASE_URL: str = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
|
|
DEFAULT_MODEL: str = os.getenv("DEFAULT_MODEL", "qwen2.5:latest")
|
|
TEMPERATURE: float = float(os.getenv("TEMPERATURE", "0.7"))
|
|
MAX_TOKENS: int = int(os.getenv("MAX_TOKENS", "2048"))
|
|
|
|
# 安全配置
|
|
CORS_ORIGINS: list = ["*"]
|
|
CORS_CREDENTIALS: bool = True
|
|
CORS_METHODS: list = ["*"]
|
|
CORS_HEADERS: list = ["*"]
|
|
|
|
# 日志配置
|
|
LOG_LEVEL: str = "INFO" if DEBUG else "WARNING"
|
|
LOG_FORMAT: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
|
|
# 创建全局配置实例
|
|
settings = Settings()
|