ExerciseOCR/config.py
heshunme 1ed9822f2f 1.最小化import
2.重构代码结构,独立config类与ConnectionManager类
3.引入toml来管理配置文件
4.引入pydantic的basemodel来简化config类的建构
5.新增信号响应系统,linux上可以响应systemctl reload了
6.修改了部分注释
2024-10-26 15:56:38 +08:00

25 lines
613 B
Python

# -*- coding: utf-8 -*-
# @Time : 2024/10/26 下午3:25
# @Author : 河瞬
# @FileName: config.py
# @Software: PyCharm
import toml
from pydantic import BaseModel
class Config(BaseModel):
key: str = ""
prompt: str = ""
model: str = "chatgpt-4o-latest"
base_url: str = ""
def save(self, config_file):
with open(config_file, "w", encoding='utf-8') as f:
toml.dump(self.model_dump(), f)
@classmethod
def load(cls, config_file):
with open(config_file, "r", encoding='utf-8') as f:
config_data = toml.load(f)
return cls(**config_data)