Travitia Cleverbot API的异步API包装器。(https://public-api.travitia.xyz/talk)
async-cleverbot的Python项目详细描述
异步克里夫波特
Travitia Cleverbot API的异步API包装器。(https://public-api.travitia.xyz/talk)
安装
pip3 install -U async_cleverbot
用法
importasync_cleverbotasaccleverbot=ac.Cleverbot("Your API key here")# Create the Cleverbot clientresponse=awaitcleverbot.ask("How are you today?")# Ask a question, returns async_cleverbot.cleverbot.Responseprint(response.text)# Text from the Response objectawaitcleverbot.close()
获取API密钥
加入Travitia API Discord server并使用> api
命令请求api密钥。
使用上下文
这个api支持一个用于后台上下文的上下文参数,所以让我们使用它吧!
importasync_cleverbotasaccleverbot=ac.Cleverbot("Your API key here")cleverbot.set_context(ac.DictContext(cleverbot))# Actually adds the context storageresponse=awaitcleverbot.ask("How are you today?",246938839720001536)# 2nd param is an identifier, this can be a user id!print(response.text)response=awaitcleverbot.ask("I'm doing good too.",246938839720001536)print(response.text)print(cleverbot.context._storage)# "How are you today?"awaitcleverbot.close()