pangukitsappdev.api package

Subpackages

Submodules

pangukitsappdev.api.common_config module

class pangukitsappdev.api.common_config.HttpConfig(env_prefix='sdk.proxy', *, proxy_default_enabled: Optional[bool] = False, proxy_enabled: Optional[bool] = None, proxy_url: Optional[str] = None, proxy_user: Optional[str] = None, proxy_passwd: Optional[str] = None)

基类:SdkBaseSettings

http相关配置 Attributes:

proxy_default_enabled:默认代理开关 proxy_enabled: 优先模块代理开关,模块未定义则使用默认代理开关 proxy_url: 代理host地址:代理端口 proxy_user: 认证用户 proxy_passwd: 认证密码

classmethod get_proxy_enabled(v, values)
get_proxy_url() str
proxy_default_enabled: Optional[bool]
proxy_enabled: Optional[bool]
proxy_passwd: Optional[str]
proxy_url: Optional[str]
proxy_user: Optional[str]
requests_proxies() dict

构造requests请求时用的代理配置 Returns:

dict

class pangukitsappdev.api.common_config.IAMConfig(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, iam_disabled: Optional[bool] = None, iam_ak: Optional[str] = None, iam_sk: Optional[str] = None, iam_url: Optional[str] = None, iam_domain: Optional[str] = None, iam_user: Optional[str] = None, iam_pwd: Optional[str] = None, project_name: Optional[str] = None, expire_duration_millis: int = 82800000, x_auth_token: Optional[str] = None, http_config: HttpConfig = None)

基类:SdkBaseSettings

IAM的配置参数

expire_duration_millis: int
http_config: HttpConfig
iam_ak: Optional[str]
iam_disabled: Optional[bool]
iam_domain: Optional[str]
iam_pwd: Optional[str]
iam_sk: Optional[str]
iam_url: Optional[str]
iam_user: Optional[str]
project_name: Optional[str]
x_auth_token: Optional[str]
class pangukitsappdev.api.common_config.IAMConfigWrapper(env_prefix: str = 'sdk.iam')

基类:object

get_iam_config()
class pangukitsappdev.api.common_config.OpenAIConfig(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, openai_base_url: Optional[str] = None, openai_key: Optional[str] = None, http_config: HttpConfig = None)

基类:SdkBaseSettings

http_config: HttpConfig
openai_base_url: Optional[str]
openai_key: Optional[str]
class pangukitsappdev.api.common_config.ServerInfo(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None, *, url: Optional[str] = None, user: Optional[str] = None, password: Optional[str] = None)

基类:SdkBaseSettings

存储服务器链接相关信息 Attributes:

url: 主机ip列表:访问端口 user: 用户 password: 密钥

get_http_urls() [<class 'str'>]
get_urls() [<class 'str'>]
has_auth() bool
password: Optional[str]
url: Optional[str]
user: Optional[str]

pangukitsappdev.api.config_loader module

class pangukitsappdev.api.config_loader.SdkBaseSettings(_env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]] = '<object object>', _env_file_encoding: Optional[str] = None, _env_nested_delimiter: Optional[str] = None, _secrets_dir: Optional[Union[str, PathLike]] = None)

基类:BaseSettings

Sdk的配置顶层类,覆盖了Pydantic的一些默认行为。通过在初始化的时候传递env_prefix参数来指定配置加载的key前缀, 传递env_prefix_ident_fields参数,用于指定env_prefix对指定field生效,默认None对全部field生效

class Config

基类:object

classmethod customise_sources(init_settings: Callable[[BaseSettings], Dict[str, Any]], env_settings: Callable[[BaseSettings], Dict[str, Any]], file_secret_settings: Callable[[BaseSettings], Dict[str, Any]]) Tuple[Callable[[BaseSettings], Dict[str, Any]], ...]
env_file = None
extra = 'ignore'
class pangukitsappdev.api.config_loader.SdkEnvSettingsSource(env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]], env_file_encoding: Optional[str], env_nested_delimiter: Optional[str] = None, env_prefix_len: int = 0, env_prefix: Optional[str] = None, env_name_joint: str = '.', env_prefix_ident_fields: Optional[list] = None)

基类:EnvSettingsSource

主干逻辑是__call__方法,结构上基本上和EnvSettingsSource保持一致。区别点:

  1. dotenv_vars配置文件的配置优先级高于环境变量.

  2. 增加env_prefix成员变量,用来实现匹配不同的前缀做配置加载

  3. 增加env_name_joint成员变量,默认使用”.”连接env_prefix和env_name

  4. 增加config_decryptor类变量用来做配置的的解密,使用者可以自行配置。

  5. 增加env_prefix_ident_fields对指定元素生效,默认None

config_decryptor: Callable[[str, str], str] = None
classmethod decrypt_if_need(config_value: str) str
env_file: Optional[Union[str, PathLike, List[Union[str, PathLike]], Tuple[Union[str, PathLike], ...]]]
env_file_encoding: Optional[str]
env_name_joint
env_nested_delimiter: Optional[str]
env_prefix
env_prefix_ident_fields
env_prefix_len: int
classmethod load_config_decryptor(import_path: str) Callable[[str, str], str]

从import_path加载config_decryptor 加载自定义的config_decryptor。比如自定义的config_decryptor使用如下:

from your.module import decrypt_func

plain_text = decrypt_func(key_id, cipher)

则等同使用如下方法加载:

decrypt_func = load_config_decryptor(“your.module.decrypt_func”)

plain_text = decrypt_func(key_id, cipher)

该方法用来初始化类变量:SdkEnvSettingsSource.config_decryptor。只会初始化一次 Args:

import_path: 自定义config_decryptor的路径,基本格式,{path.to.module}.{function_name}

Returns:

一个可调用的方法对象

pangukitsappdev.api.crypto_util module

SCC加解密工具类 Usage: from crypto_util import crypto_util

class pangukitsappdev.api.crypto_util.SccCryptoAPIWrapper(scc_conf_path=None)

基类:object

SCC加解密Api 需要在机器上安装华为云的scc安全组件后使用这个类。内部封装了CryptoAPI(scc组件安装后获的),在SccCryptoAPIWrapper新创建实例时会对 CryptoAPI做初始化。

Attributes:

scc_conf_path: scc的配置路径 _scc_api: 懒加载的CryptoAPI类实例,初始化的时候是None

decrypt(cipher: str) str

解密 :param cipher: 密文 :return: 解密后的明文

encrypt(plain_text: str) str

加密 :param plain_text: 明文敏感信息 :return: 加密后的密文

pangukitsappdev.api.crypto_util.decrypt(key_id: str, cipher: str) str

pangukitsappdev.api.schema module

class pangukitsappdev.api.schema.LLMResp(*, answer: str, is_from_cache: bool = False)

基类:BaseModel

answer: 回答 is_from_cache: 是否命中缓存

answer: str
is_from_cache: bool

Module contents