增加代码知识库;修复文档处理内容;增加API设置
This commit is contained in:
@@ -10,7 +10,7 @@ llm:
|
||||
# 模型名称
|
||||
model: "glm-5"
|
||||
# API密钥(建议使用环境变量 DASHSCOPE_API_KEY)
|
||||
api_key: "sk-7097f7842f724f0c9e70c4bf3b16dacb"
|
||||
api_key: ""
|
||||
# 可选参数
|
||||
temperature: 0.3
|
||||
max_tokens: 1024
|
||||
|
||||
@@ -56,11 +56,11 @@ class SRSTool:
|
||||
def __init__(self) -> None:
|
||||
ToolRegistry.register(self.DEFINITION)
|
||||
|
||||
def run(self, file_path: str, enable_llm: bool = True) -> Dict[str, Any]:
|
||||
def run(self, file_path: str, enable_llm: bool = True, model_profile: Any = None) -> Dict[str, Any]:
|
||||
if not enable_llm:
|
||||
raise ValueError("当前版本仅支持LLM模式,请将 enable_llm 设为 true")
|
||||
|
||||
config = self._load_config()
|
||||
config = self._load_config(model_profile=model_profile)
|
||||
llm = self._build_llm(config, enable_llm=enable_llm)
|
||||
|
||||
parser = create_parser(file_path)
|
||||
@@ -164,7 +164,7 @@ class SRSTool:
|
||||
return text
|
||||
return f"{text[:20].rstrip()}"
|
||||
|
||||
def _load_config(self) -> Dict[str, Any]:
|
||||
def _load_config(self, model_profile: Any = None) -> Dict[str, Any]:
|
||||
config_path = Path(__file__).with_name("default_config.yaml")
|
||||
if config_path.exists():
|
||||
with config_path.open("r", encoding="utf-8") as handle:
|
||||
@@ -173,9 +173,14 @@ class SRSTool:
|
||||
config = {}
|
||||
|
||||
config.setdefault("llm", {})
|
||||
config["llm"]["model"] = settings.DASH_SCOPE_CHAT_MODEL or settings.OPENAI_MODEL
|
||||
config["llm"]["api_key"] = settings.DASH_SCOPE_API_KEY or os.getenv("DASHSCOPE_API_KEY", "")
|
||||
config["llm"]["api_base"] = settings.DASH_SCOPE_API_BASE
|
||||
if model_profile is not None:
|
||||
config["llm"]["model"] = getattr(model_profile, "chat_model", None) or settings.DASH_SCOPE_CHAT_MODEL
|
||||
config["llm"]["api_key"] = getattr(model_profile, "api_key", "") or ""
|
||||
config["llm"]["api_base"] = getattr(model_profile, "api_base", None) or settings.DASH_SCOPE_API_BASE
|
||||
else:
|
||||
config["llm"]["model"] = settings.DASH_SCOPE_CHAT_MODEL or settings.OPENAI_MODEL
|
||||
config["llm"]["api_key"] = settings.DASH_SCOPE_API_KEY or os.getenv("DASHSCOPE_API_KEY", "")
|
||||
config["llm"]["api_base"] = settings.DASH_SCOPE_API_BASE
|
||||
config["llm"]["enabled"] = bool(config["llm"].get("api_key"))
|
||||
return config
|
||||
|
||||
@@ -186,7 +191,7 @@ class SRSTool:
|
||||
llm_cfg = config.get("llm", {})
|
||||
api_key = llm_cfg.get("api_key")
|
||||
if not api_key:
|
||||
raise ValueError("未配置API密钥:请设置 DASH_SCOPE_API_KEY 或 DASHSCOPE_API_KEY")
|
||||
raise ValueError("未配置模型 API 密钥,请先在 API 密钥页面新增并启用模型配置。")
|
||||
|
||||
return QwenLLM(
|
||||
api_key=api_key,
|
||||
|
||||
Reference in New Issue
Block a user