25 lines
613 B
Python
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)
|