This repository was archived by the owner on Jun 27, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
55 lines (50 loc) · 2.47 KB
/
Copy path__init__.py
File metadata and controls
55 lines (50 loc) · 2.47 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
47
48
49
50
51
52
53
54
55
import configparser
import json
import os
class Config:
_config = configparser.ConfigParser()
api_keys: list = [] # api key
model: str = "gpt-3.5-turbo" # 模型
record: bool = True # 是否记录对话
conversations: dict = {} # 会话列表
groups: dict = {} # 群组列表
interval: int = 5 # 存档间隔
max_tokens: int = 1000 # 最大字符数
proxy: str = "" # 代理
api_base : str = ""
api_type : str = "open_ai"
api_version : str = ""
def __init__(self):
self._config.read(os.path.join(os.path.dirname(__file__), 'config.ini'), encoding='utf-8')
self.load_conversations()
api_keys = self._config.get("OPTION", "api_key", fallback="")
self.api_keys = api_keys.split(",")
self.model = self._config.get("OPTION", "model", fallback="gpt-3.5-turbo")
self.record = self._config.getboolean("OPTION", "record", fallback=True)
self.interval = self._config.getint("OPTION", "interval", fallback=5)
self.max_tokens = self._config.getint("OPTION", "max_tokens", fallback=1000)
self.proxy = self._config.get("OPTION", "proxy", fallback="")
self.api_base = self._config.get("OPTION", "api_base", fallback="")
self.api_type = self._config.get("OPTION", "api_type", fallback="open_ai")
self.api_version = self._config.get("OPTION", "api_version", fallback="")
items = self._config.items("GROUP")
for item in items:
if item[1] in self.conversations:
self.groups[item[0]] = item[1]
else:
self.groups[item[0]] = "default"
def save_conversations(self):
with open(os.path.join(os.path.dirname(__file__), 'conversations.json'), 'w', encoding='utf-8') as f:
json.dump(self.conversations, f, ensure_ascii=False, indent=4)
def load_conversations(self):
with open(os.path.join(os.path.dirname(__file__), 'conversations.json'), 'r', encoding='utf-8') as f:
self.conversations = json.load(f)
def save_config(self):
for group in self.groups:
if self.groups[group] not in self.conversations:
self._config.set("GROUP", group, "default")
else:
self._config.set("GROUP", group, self.groups[group])
self._config.set("OPTION", "record", str(self.record).lower())
with open(os.path.join(os.path.dirname(__file__), 'config.ini'), 'w', encoding='utf-8') as f:
self._config.write(f)