33from datetime import datetime , date
44from uuid import UUID
55import requests
6+ from requests .adapters import HTTPAdapter
67import json
8+ import os
79
8- from ..models .llm_shield_sign import request_sign , Version
10+ from ..models .llm_shield_sign import request_sign , Version , SetServiceDev , GetServiceCode
911
1012LLM_STREAM_SEND_BASE_WINDOW_V2 = 10
1113LLM_STREAM_SEND_EXPONENT_V2 = 2
@@ -17,7 +19,7 @@ class ContentTypeV2:
1719 AUDIO = 2
1820 IMAGE = 3
1921 VIDEO = 4
20-
22+ FILE = 5
2123
2224# 定义决策类型常量
2325class DecisionTypeV2 :
@@ -44,11 +46,21 @@ class MatchSource:
4446 USER_CONTENTLIB = 3
4547
4648
49+ # 定义消息结构体
50+ class MultiPart (BaseModel ):
51+ content : str = Field ("" , alias = "Content" )
52+ content_type : int = Field (ContentTypeV2 .TEXT , alias = "ContentType" )
53+
54+ class Config :
55+ populate_by_name = True
56+
57+
4758# 定义消息结构体
4859class MessageV2 (BaseModel ):
4960 role : str = Field ("" , alias = "Role" )
5061 content : str = Field ("" , alias = "Content" )
5162 content_type : int = Field (ContentTypeV2 .TEXT , alias = "ContentType" )
63+ multi_part : Optional [List [MultiPart ]] = Field (None , alias = "MultiPart" )
5264
5365 class Config :
5466 populate_by_name = True
@@ -198,6 +210,7 @@ class ModerateV2Result(BaseModel):
198210 risk_info : RiskInfoV2 = Field (default_factory = RiskInfoV2 , alias = "RiskInfo" )
199211 decision : DecisionV2 = Field (default_factory = DecisionV2 , alias = "Decision" )
200212 permit_info : PermitInfoV2 = Field (default_factory = PermitInfoV2 , alias = "PermitInfo" )
213+ content_info : str = Field ("" , alias = "ContentInfo" )
201214 degraded : bool = Field (False , alias = "Degraded" )
202215 degrade_reason : str = Field ("" , alias = "DegradeReason" )
203216
@@ -295,7 +308,6 @@ class GenerateStreamV2ResponseData(BaseModel):
295308 class Config :
296309 populate_by_name = True
297310
298-
299311# 定义客户端类
300312class ClientV2 :
301313 def __init__ (self , url : str , ak : str , sk : str , region : str , timeout : float ):
@@ -306,6 +318,23 @@ def __init__(self, url: str, ak: str, sk: str, region: str, timeout: float):
306318 self .http_client = requests .Session ()
307319 self .http_client .timeout = timeout
308320
321+ def SetProxy (self , proxy : dict ):
322+ if proxy :
323+ self .http_client .proxies = proxy
324+ else :
325+ self .http_client .proxies .clear ()
326+
327+ def SetConnMax (self , connMax ):
328+ if connMax > 0 :
329+ adapter = HTTPAdapter (
330+ pool_connections = connMax , # 全局连接池数量:最多维护多少个 Host 的连接池
331+ pool_maxsize = connMax , # 单 Host 最大连接数:控制并发的核心(= 目标并发数)
332+ pool_block = False # 连接池满时是否阻塞:False=非阻塞(超时抛异常),True=阻塞等待
333+ )
334+ # 将适配器挂载到 Session:所有 HTTP/HTTPS 请求都使用该连接池
335+ self .http_client .mount ("http://" , adapter )
336+ self .http_client .mount ("https://" , adapter )
337+
309338 def Moderate (self , request : Optional [ModerateV2Request ] = None ) -> ModerateV2Response :
310339 path = "/v2/moderate"
311340 action = "Moderate"
0 commit comments