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

Method __init__

backend/utils/text_client.py:43–60  ·  view source on GitHub ↗
(self, api_key: str = None, base_url: str = None, endpoint_type: str = None)

Source from the content-addressed store, hash-verified

41 """Text API 客户端封装类"""
42
43 def __init__(self, api_key: str = None, base_url: str = None, endpoint_type: str = None):
44 self.api_key = api_key
45 if not self.api_key:
46 raise ValueError(
47 "Text API Key 未配置。\n"
48 "解决方案:在系统设置页面编辑文本生成服务商,填写 API Key"
49 )
50
51 self.base_url = (base_url or "https://api.openai.com").rstrip('/')
52 if self.base_url.endswith('/v1'):
53 self.base_url = self.base_url[:-3]
54
55 # 支持自定义端点路径
56 endpoint = endpoint_type or '/v1/chat/completions'
57 # 确保端点以 / 开头
58 if not endpoint.startswith('/'):
59 endpoint = '/' + endpoint
60 self.chat_endpoint = f"{self.base_url}{endpoint}"
61
62 def _encode_image_to_base64(self, image_data: bytes) -> str:
63 """将图片数据编码为 base64"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected