mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-19 19:06:07 +00:00
feat: 运行时原动态引入config的地方现在均使用初始化时导入的config对象
This commit is contained in:
@@ -5,7 +5,6 @@ import logging
|
||||
import pkg.database.manager
|
||||
import pkg.qqbot.manager
|
||||
import pkg.utils.context
|
||||
import config
|
||||
|
||||
|
||||
class KeysManager:
|
||||
@@ -34,6 +33,8 @@ class KeysManager:
|
||||
def __init__(self, api_key):
|
||||
# if hasattr(config, 'api_key_usage_threshold'):
|
||||
# self.api_key_usage_threshold = config.api_key_usage_threshold
|
||||
|
||||
config = pkg.utils.context.get_config()
|
||||
if hasattr(config, 'api_key_fee_threshold'):
|
||||
self.api_key_fee_threshold = config.api_key_fee_threshold
|
||||
self.load_fee()
|
||||
@@ -108,6 +109,7 @@ class KeysManager:
|
||||
|
||||
self.fee[md5] += fee
|
||||
|
||||
config = pkg.utils.context.get_config()
|
||||
if self.fee[md5] >= self.api_key_fee_threshold and \
|
||||
hasattr(config, 'auto_switch_api_key') and config.auto_switch_api_key:
|
||||
switch_result, key_name = self.auto_switch()
|
||||
|
||||
@@ -2,8 +2,6 @@ import logging
|
||||
|
||||
import openai
|
||||
|
||||
import config
|
||||
|
||||
import pkg.openai.keymgr
|
||||
import pkg.openai.pricing as pricing
|
||||
import pkg.utils.context
|
||||
@@ -34,6 +32,7 @@ class OpenAIInteract:
|
||||
|
||||
# 请求OpenAI Completion
|
||||
def request_completion(self, prompt, stop):
|
||||
config = pkg.utils.context.get_config()
|
||||
response = openai.Completion.create(
|
||||
prompt=prompt,
|
||||
stop=stop,
|
||||
@@ -53,6 +52,7 @@ class OpenAIInteract:
|
||||
|
||||
def request_image(self, prompt):
|
||||
|
||||
config = pkg.utils.context.get_config()
|
||||
params = config.image_api_params if hasattr(config, "image_api_params") else self.default_image_api_params
|
||||
|
||||
response = openai.Image.create(
|
||||
|
||||
@@ -2,7 +2,6 @@ import logging
|
||||
import threading
|
||||
import time
|
||||
|
||||
import config
|
||||
import pkg.openai.manager
|
||||
import pkg.database.manager
|
||||
import pkg.utils.context
|
||||
@@ -54,6 +53,7 @@ def dump_session(session_name: str):
|
||||
|
||||
# 从配置文件获取会话预设信息
|
||||
def get_default_prompt():
|
||||
import config
|
||||
user_name = config.user_name if hasattr(config, 'user_name') and config.user_name != '' else 'You'
|
||||
bot_name = config.bot_name if hasattr(config, 'bot_name') and config.bot_name != '' else 'Bot'
|
||||
return user_name + ":{}\n".format(config.default_prompt if hasattr(config, 'default_prompt') \
|
||||
@@ -85,6 +85,8 @@ class Session:
|
||||
|
||||
prompt = get_default_prompt()
|
||||
|
||||
import config
|
||||
|
||||
user_name = config.user_name if hasattr(config, 'user_name') and config.user_name != '' else 'You'
|
||||
bot_name = config.bot_name if hasattr(config, 'bot_name') and config.bot_name != '' else 'Bot'
|
||||
|
||||
@@ -130,6 +132,8 @@ class Session:
|
||||
# 不是此session已更换,退出
|
||||
if self.create_timestamp != create_timestamp or self not in sessions.values():
|
||||
return
|
||||
|
||||
config = pkg.utils.context.get_config()
|
||||
if int(time.time()) - self.last_interact_timestamp > config.session_expire_time:
|
||||
logging.info('session {} 已过期'.format(self.name))
|
||||
self.reset(expired=True, schedule_new=False)
|
||||
@@ -144,6 +148,7 @@ class Session:
|
||||
self.last_interact_timestamp = int(time.time())
|
||||
|
||||
# max_rounds = config.prompt_submit_round_amount if hasattr(config, 'prompt_submit_round_amount') else 7
|
||||
config = pkg.utils.context.get_config()
|
||||
max_rounds = 1000 # 不再限制回合数
|
||||
max_length = config.prompt_submit_length if hasattr(config, "prompt_submit_length") else 1024
|
||||
|
||||
|
||||
Reference in New Issue
Block a user