本文整理汇总了Python中watson_developer_cloud.ConversationV1方法的典型用法代码示例。如果您正苦于以下问题:Python watson_developer_cloud.ConversationV1方法的具体用法?Python watson_developer_cloud.ConversationV1怎么用?Python watson_developer_cloud.ConversationV1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类watson_developer_cloud
的用法示例。
在下文中一共展示了watson_developer_cloud.ConversationV1方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import watson_developer_cloud [as 别名]
# 或者: from watson_developer_cloud import ConversationV1 [as 别名]
def __init__(self, sc, token):
Config = ConfigParser.ConfigParser()
Config.read("credentials.ini")
self.name = Config.get('Slack_Creds', 'name')
self.sc = sc
self.messages_processed = 0
self.slack_token = token
self.me = self.name
print slack.get_my_id(self.sc, self.me)
self.at_bot = "<@" + slack.get_my_id(self.sc, self.me) + ">"
print "AT " + self.name + ": " + self.at_bot
self.whitelist = [self.name + "-private"]
# set up conversation service
self.conversation = ConversationV1(
username= Config.get('Conversation_Creds', 'username'),
password= Config.get('Conversation_Creds', 'password'),
version= Config.get('Conversation_Creds', 'version'))
self.conversation_workspace_id = Config.get('Conversation_Creds', 'workspace_id')
示例2: run
# 需要导入模块: import watson_developer_cloud [as 别名]
# 或者: from watson_developer_cloud import ConversationV1 [as 别名]
def run(message=None, context=None):
conversation = ConversationV1(
username='28f2a25a-38d1-4f3e-9d02-391bb41edbde',
password='PEb7dCc2jGrB',
version='2016-09-20'
)
# Replace with the context obtained from the initial request
if context == None:
context = {}
else:
d = ast.literal_eval(json.dumps(context))
context = d
workspace_id = 'f663996e-4c77-4b64-b188-5f10ebbbb27b'
response = conversation.message(
workspace_id=workspace_id,
message_input={'text': message},
context=context
)
# return(json.dumps(response, indent=2))
return response
示例3: auto_add_comment_basedon_content
# 需要导入模块: import watson_developer_cloud [as 别名]
# 或者: from watson_developer_cloud import ConversationV1 [as 别名]
def auto_add_comment_basedon_content(input, postid):
# English version
conversation = ConversationV1(
username='69ff24f0-227c-4fbc-9609-5013aac22396',
password='k2G2ghPqYu4p',
version='2017-05-26')
# replace with your own workspace_id
workspace_id = 'd0841bcb-0861-482b-b87a-96f3f787bacc'
response = conversation.message(workspace_id=workspace_id, message_input={
'text': input})
if len(response['intents']) > 0 and response['intents'][0]['intent'] == 'how_about_this':
output = response['output']['text']
entity_list = ['']
if len(response['entities']) == 1:
entity_location = response['entities'][0]['location']
logging.info(entity_location)
logging.info(type(entity_location[0]))
entity = response['input']['text'][int(entity_location[0]):int(entity_location[1])]
entity_list.append(entity)
logging.info('***output of watson***: ' + output[0])
user_id = 'operator'
user_name = 'operator'
post_id = postid
post = Post.query.filter_by(id=post_id).first()
content = random.choice(entity_list) + " "
content += output[0] + " "
if random.randint(0, 1):
content += output[1]
reply_to = ''
comment = Comment(user_id, user_name, post_id, reply_to, content)
post.comments.append(comment)
db.session.add(comment)
db.session.commit()
else:
logging.info("no intent found from watson")