logo

千帆sdk安全认证AK/SK内置函数报警解决

报警:setting config via specific function is deprecated, please get config with get_config() and set attributes directly
qianfan
1、官方的说明
通过内置函数初始化
  
  
# 通过内置函数传递(作用于全局,优先级大于环境变量)
import qianfan
qianfan.AccessKey("你的AccessKey") //我使用文件导入Conf.AccessKey ,这句引起报警
qianfan.SecretKey("你的SecretKey") //我使用文件导入Conf.SecretKey,这句引起报警
chat_comp = qianfan.ChatCompletion()
resp = chat_comp.do(messages=[{
"role": "user",
"content": "你好"
}])
print(resp)
执行后报警:
DeprecationWarning: setting config via specific function is deprecated, please get config with get_config() and set attributes directly
qianfan.AccessKey(Conf.AccessKey)
DeprecationWarning: setting config via specific function is deprecated, please get config with get_config() and set attributes directly
qianfan.SecretKey(Conf.SecretKey)
解决方法:
  
  
import qianfan
from conf import Conf
# qianfan.AccessKey(Conf.AccessKey)
# qianfan.SecretKey(Conf.SecretKey)
qianfan.config.get_config().ACCESS_KEY = Conf.AccessKey //get_config()解决方法
qianfan.config.get_config().SECRET_KEY = Conf.SecretKey //get_config()解决方法
chat_comp = qianfan.ChatCompletion()
resp = chat_comp.do(messages=[{
"role": "user",
"content": "你好"
}])
print(resp)
执行:

#千帆sdk #安全认证AK/SK

评论
用户头像