MCPcopy Create free account
hub / github.com/HisMax/RedInk / _get_client

Method _get_client

backend/services/content.py:61–94  ·  view source on GitHub ↗

根据配置获取客户端

(self)

Source from the content-addressed store, hash-verified

59 }
60
61 def _get_client(self):
62 """根据配置获取客户端"""
63 active_provider = self.text_config.get('active_provider', 'google_gemini')
64 providers = self.text_config.get('providers', {})
65
66 if not providers:
67 logger.error("未找到任何文本生成服务商配置")
68 raise ValueError(
69 "未找到任何文本生成服务商配置。\n"
70 "解决方案:\n"
71 "1. 在系统设置页面添加文本生成服务商\n"
72 "2. 或手动编辑 text_providers.yaml 文件"
73 )
74
75 if active_provider not in providers:
76 available = ', '.join(providers.keys())
77 logger.error(f"文本服务商 [{active_provider}] 不存在,可用: {available}")
78 raise ValueError(
79 f"未找到文本生成服务商配置: {active_provider}\n"
80 f"可用的服务商: {available}\n"
81 "解决方案:在系统设置中选择一个可用的服务商"
82 )
83
84 provider_config = providers.get(active_provider, {})
85
86 if not provider_config.get('api_key'):
87 logger.error(f"文本服务商 [{active_provider}] 未配置 API Key")
88 raise ValueError(
89 f"文本服务商 {active_provider} 未配置 API Key\n"
90 "解决方案:在系统设置页面编辑该服务商,填写 API Key"
91 )
92
93 logger.info(f"使用文本服务商: {active_provider} (type={provider_config.get('type')})")
94 return get_text_chat_client(provider_config)
95
96 def _load_prompt_template(self) -> str:
97 """加载提示词模板"""

Callers 1

__init__Method · 0.95

Calls 2

get_text_chat_clientFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected