完成和大模型的通信

This commit is contained in:
wandering
2026-06-04 09:58:45 +08:00
parent 37199970c9
commit 580fe4ad6e
13 changed files with 2117 additions and 1820 deletions

View File

@@ -5,20 +5,26 @@ from pathlib import Path
CONFIG_PATH = Path(__file__).parent.parent / "config.json"
DEFAULT_CONFIG: dict[str, str] = {
DEFAULT_CONFIG: dict = {
"language": "Chinese",
"raw_dir": "raw",
"wiki_dir": "wiki",
}
DEFAULT_LLM_CONFIG: dict = {
"model": "qwen/qwen3.6-27b",
"api_base": "http://100.123.83.113:1234/v1",
"api_key": "123456",
}
def load_config() -> dict[str, str]:
def load_config() -> dict:
"""
加载项目配置。
返回
-------
dict[str, str]
dict
配置字典,包含 language、raw_dir、wiki_dir 等键。
"""
if CONFIG_PATH.is_file():
@@ -38,3 +44,19 @@ def get_language() -> str | None:
if language.lower() == "auto":
return None
return language
def get_llm_config() -> dict[str, str]:
"""
获取 LLM 配置。
返回
-------
dict[str, str]
包含 model, api_base, api_key 的字典。
"""
config = load_config()
llm_raw = config.get("llm", {})
# 过滤空值,避免空字符串覆盖默认配置
llm_filtered = {k: v for k, v in llm_raw.items() if v}
return {**DEFAULT_LLM_CONFIG, **llm_filtered}