更新时间:2024-08-29 GMT+08:00
分享

配置SDK

基础配置项

SDK依赖的配置项主要通过加载llm.properties配置文件。

  1. 在项目路径下,创建llm.properties文件,并根据实际需要配置相应的值。
  2. 在环境变量中配置“SDK_CONF_PATH”指向该配置文件:
    # 建议在业务项目入口处配置
    import os
    os.environ["SDK_CONFIG_PATH"] = "./llm.properties"
  3. 完整配置项如下:

    配置项中的密码等字段建议在配置文件或者环境变量中密文存放,使用时解密,确保安全,详见配置文件敏感信息加密配置

    ################################ GENERIC CONFIG ###############################
    
    ## User-defined Prompt.
    #
    sdk.prompt.path=
    
    ## Proxy.
    # Examples: http://127.0.0.1:8000 ;
    #
    # sdk.proxy.enabled=
    # sdk.proxy.url=
    # sdk.proxy.user=
    # sdk.proxy.password=
    
    ## Generic IAM info. This config is used when the specified IAM is not configured.
    ## Either user password authentication or AK/SK authentication.
    #
    sdk.iam.url=
    sdk.iam.domain=
    sdk.iam.user=
    sdk.iam.password=
    sdk.iam.project=
    sdk.iam.ak=
    sdk.iam.sk=
    sdk.iam.disabled=
    
    
    ################################ LLM ###############################
    
    ## Pangu
    # Examples: https://{endPoint}/v1/{projectId}/deployments/{deploymentId} ;
    #
    sdk.llm.pangu.url=
    ## If necessary, you can specify the IAM configuration.
    # sdk.llm.pangu.iam.url=
    # sdk.llm.pangu.iam.domain=
    # sdk.llm.pangu.iam.user=
    # sdk.llm.pangu.iam.password=
    # sdk.llm.pangu.iam.project=
    # sdk.llm.pangu.iam.disabled=
    ## If necessary, you can specify the proxy status.
    # sdk.llm.pangu.proxy.enabled=
    # sdk.llm.pangu.model-version=
    
    ## Gallery
    # Examples: https://{endPoint}/v1/infers/{deploymentId} ;
    #
    sdk.llm.gallery.url=
    ## If necessary, you can specify the IAM configuration.
    # sdk.llm.gallery.iam.url=
    # sdk.llm.gallery.iam.domain=
    # sdk.llm.gallery.iam.user=
    # sdk.llm.gallery.iam.password=
    # sdk.llm.gallery.iam.project=
    # sdk.llm.gallery.iam.disabled=
    ## If necessary, you can specify the proxy status.
    # sdk.llm.gallery.proxy.enabled=
    
    
    ################################ EMBEDDINGS ###############################
    
    ## CSS
    # Examples: https://{endPoint}/v1/{projectId}/applications/{appId}/{modelVersion} ;
    #
    sdk.embedding.css.url=
    ## If necessary, you can specify the IAM configuration.
    # sdk.embedding.css.iam.url=
    # sdk.embedding.css.iam.domain=
    # sdk.embedding.css.iam.user=
    # sdk.embedding.css.iam.password=
    # sdk.embedding.css.iam.project=
    # sdk.embedding.css.iam.disabled=
    ## If necessary, you can specify the proxy status.
    # sdk.embedding.css.proxy.enabled=
    
    
    ################################ MEMORY ###############################
    
    ## CSS or ES
    # Examples: http://127.0.0.1:9200,http://127.0.0.2:9200 ;
    #
    sdk.memory.css.url=
    sdk.memory.css.user=
    sdk.memory.css.password=
    
    ## DCS or Redis
    # Examples: 127.0.0.1:6379 ;
    #
    # sdk.memory.dcs.url=
    # sdk.memory.dcs.user=
    # sdk.memory.dcs.password=
    
    ## RDS or Mysql
    # Examples: jdbc:mariadb://127.0.0.1:3306/sdk?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai ; 
    #
    # sdk.memory.rds.url=
    # sdk.memory.rds.user=
    # sdk.memory.rds.password=
    # sdk.memory.rds.poolSize=
    
    
    ################################ DOC SPLIT ###############################
    
    ## CSS
    # Examples: https://{endPoint}/v1/{projectId}/applications/{appId} ;
    #
    # sdk.doc.split.css.url=
    # sdk.doc.split.css.filepath=
    # sdk.doc.split.css.mode=
    ## If necessary, you can specify the IAM configuration.
    # sdk.doc.split.css.iam.url=
    # sdk.doc.split.css.iam.domain=
    # sdk.doc.split.css.iam.user=
    # sdk.doc.split.css.iam.password=
    # sdk.doc.split.css.iam.project=
    # sdk.doc.split.css.iam.disabled=
    ## If necessary, you can specify the proxy status.
    # sdk.doc.split.css.proxy.enabled=

日志打印配置

SDK日志采用logging模块,参考以下代码开启相应日志打印信息:
import logging
# 打印在命令行(与打印在文件不同时生效)
logging.basicConfig(level=logging.DEBUG)

# 打印在日志文件(与打印在命令行不同时生效)
logging.basicConfig(level=logging.DEBUG,  # 控制台打印的日志级别
                    filename='new.log',
                    filemode='a',
                    format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s')

配置文件敏感信息加密配置

配置项中的认证凭据等信息不建议明文配置在配置文件中,可以通过以下方式扩展自定义的加解密组件:

  1. 在一个module(yourmodule)中自定义一个解密方法decrypt_func(key_id, cipher),要求可以通过`from yourmodule import decrypt_func`这样的方式使用该方法。
  2. 在配置文件中配置`sdk.crypto.implementation.path=yourmodule.decrypt_func`指向自定义的解密方法的引用。程序加载时会通过import_lib加载该方法。
  3. 配置文件中配置密文的格式:`sdk.llm.iam.iamPwd={Crypto.key_id}cipher`,其中key_id和cipher会在配置项读取时被解析传递进decrypt_func方法中,进行解密。

相关文档