V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Zeeland4v
V2EX  ›  Python

我参考 VSCode 设计了一个多层级配置框架,专为框架开发者设计

  •  
  •   Zeeland4v ·
    Undertone0809 · 6 天前 · 1159 次点击

    作为框架开发者,最近我在开发 promptulate 和 gcop 的遇到过以下问题:

    1. 用户需要在多个项目中使用你的框架,但每个项目的配置都不一样(比如不同的 API Key 、模型参数等)
    2. 手写配置合并逻辑,要考虑默认值、用户全局配置、项目配置的覆盖关系
    3. 配置值类型不安全,需要手动转换/验证

    我参考了 VSCode 的配置系统设计了 Conftier ,让框架开发者可以像 VSCode 一样优雅地处理配置。

    实际场景举例

    假设你在开发一个 AI 框架:

    # 框架开发者:定义配置结构
    class OpenAIConfig(BaseModel):
        api_key: str = ""
        model: str = "gpt-4"
        temperature: float = 0.7
    
    # 用户:设置全局 API Key (~/.zeeland/myai/config.yaml)
    api_key: "sk-xxx"
    
    # 用户:项目特定配置 (./.myai/config.yaml)
    model: "gpt-3.5-turbo"  # 这个项目用不同的模型
    temperature: 0.5  # 调整参数
    

    Conftier 会自动处理配置的加载、合并、类型转换,框架开发者只需要专注业务逻辑。

    主要特性

    • 像 VSCode 一样的多层级配置:默认值 -> 用户配置 -> 项目配置
    • 支持 Pydantic ,配置类型安全 + IDE 自动补全
    • 内置 CLI 工具,用户可以方便地管理配置
    • 自动合并配置,不用手写合并逻辑

    文档: https://conftier.zeeland.top GitHub: https://github.com/Undertone0809/conftier

    如果你正在开发框架,欢迎试用和提建议,欢迎 star ⭐️

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   962 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 19:50 · PVG 03:50 · LAX 12:50 · JFK 15:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.