def test_create_qa_satisfaction(user_id, satisfaction): client = WulaiClient(pubkey, secret, debug=True) # 获取机器人回复 msg_body = {"text": {"content": "你好"}} resp_bot_response = client.get_bot_response(user_id, msg_body) bot = resp_bot_response.suggested_response[0].bot msg_body_response = resp_bot_response.suggested_response[0].response[ 0].msg_body.to_dict() # 同步发给用户的消息(机器人回复) msg_ts = str(int(time.time() * 1000)) resp_sync = client.sync_message(user_id, msg_body_response, msg_ts, bot=bot.to_dict()) # msg_id msg_id = resp_sync.msg_id # knowledge_id knowledge_id = bot.qa.knowledge_id resp = client.create_qa_satisfaction(msg_id, user_id, {"knowledge_id": str(knowledge_id)}, satisfaction) assert resp == {}
def test_get_qa_bot_response_normal(user_id, msg_body, extra, expected): client = WulaiClient(pubkey, secret, debug=True) resp = client.get_qa_bot_response(user_id, msg_body, extra) assert resp.to_dict()["qa_suggested_response"][0]["response"][0][ "msg_body"]["text"]["content"] == expected assert resp.qa_suggested_response[0].response[ 0].msg_body.text.content == expected
def test_get_task_bot_response_normal(user_id, msg_body, extra): client = WulaiClient(pubkey, secret, debug=True) resp = client.get_task_bot_response(user_id, msg_body, extra) assert "text" in resp.to_dict( )["task_suggested_response"][0]["response"][0]["msg_body"].keys() assert isinstance( resp.task_suggested_response[0].response[0].msg_body.text.content, str)
def test_intent_trigger(intent_trigger_create, intent_trigger_update): client = WulaiClient(pubkey, secret, debug=True) # 创建触发器 resp_create = client.create_intent_trigger(intent_trigger_create) intent_trigger_id = resp_create.intent_trigger.id # 更新触发器 intent_trigger_update["id"] = intent_trigger_id resp_update = client.update_intent_trigger(intent_trigger_update) assert intent_trigger_id == resp_update.intent_trigger.id # 查询触发器列表 resp_list = client.intent_triggers(intent_trigger_create["intent_id"], 1, 50) intent_trigger_ids = [ intent_trigger.id for intent_trigger in resp_list.intent_triggers ] assert intent_trigger_id in intent_trigger_ids # 删除触发器 client.delete_intent_trigger(intent_trigger_id) # 查询触发器列表 resp_list = client.intent_triggers(intent_trigger_create["intent_id"], 1, 50) intent_trigger_ids = [ intent_trigger.id for intent_trigger in resp_list.intent_triggers ] assert intent_trigger_id not in intent_trigger_ids
def test_intents(intent_create, intent_update): client = WulaiClient(pubkey, secret, debug=True) # 创建意图 resp_create = client.create_intent(intent_create) intent_id = resp_create.intent.id # 更新意图 intent_update["id"] = intent_id resp_update = client.update_intent(intent_update) assert intent_id == resp_update.intent.id # 查询意图列表 resp_list = client.intents(intent_create["scene_id"]) intent_ids = [intent.id for intent in resp_list.intents] assert intent_id in intent_ids # 删除意图 client.delete_intent(intent_id) # 查询意图列表 resp_list = client.intents(test_scene_id) intent_ids = [intent.id for intent in resp_list.intents] assert intent_id not in intent_ids
def test_dictionary_entities_enum(enum_entity, entity_value, entity_value_part, entity_value_total): client = WulaiClient(pubkey, secret, debug=True) # 创建枚举实体 resp_entity_enum = client.create_dictionary_entity_enumeration(enum_entity) entity_enum_id = resp_entity_enum.enum_entity.id # 创建枚举实体值 resp_create = client.create_dictionary_entity_enumeration_value( entity_enum_id, entity_value) assert resp_create.enum_entity.id # 删除枚举实体部分值 client.delete_dictionary_entity_enumeration_value(entity_enum_id, entity_value_part) # 删除枚举实体标准值 client.delete_dictionary_entity_enumeration_value(entity_enum_id, entity_value_total) resp_entity = client.dictionary_entity(entity_enum_id) assert resp_entity.entity.name == enum_entity["name"] # 删除枚举实体 client.delete_dictionary_entity(entity_enum_id) with pytest.raises(ClientException) as excinfo: client.dictionary_entity(entity_enum_id) assert excinfo.error_code == "SDK_INVALID_PARAMS"
def test_request_block(request_block_create, request_block_update, response_create): client = WulaiClient(pubkey, secret, debug=True) # 创建询问填槽单元 resp_create = client.create_request_block(request_block_create) block_id = resp_create.block.id # 更新询问填槽单元 request_block_update["id"] = block_id resp_update = client.update_request_block(request_block_update) assert block_id == resp_update.block.id # 查询询问填槽单元 resp = client.request_block(block_id) assert resp.block.name # 创建单元内回复 response_create["block_id"] = block_id resp_resp_create = client.create_block_response(response_create) assert resp_resp_create.response.response.to_dict() key = list(resp_resp_create.response.response.__dict__.keys())[0] assert getattr(resp_resp_create.response.response, key).to_dict() resp_id = resp_resp_create.response.id # 删除单元内回复 client.delete_block_response(resp_id) # 删除单元 client.delete_block(block_id)
def test_create_user_user_attribute_normal(user_id, user_attribute_user_attribute_value, expected): client = WulaiClient(pubkey, secret, debug=True) resp = client.create_user_user_attribute( user_id, user_attribute_user_attribute_value) assert resp == expected
def test_end_block(end_block_create, end_block_update_1, end_block_update_2): client = WulaiClient(pubkey, secret, debug=True) # 创建意图 intent = {"scene_id": test_scene_id, "name": "测试意图3", "lifespan_mins": 5} resp_create_intent = client.create_intent(intent) intent_id = resp_create_intent.intent.id end_block_create["intent_id"] = intent_id # 创建意图终点单元 resp_create = client.create_end_block(end_block_create) block_id = resp_create.block.id # 更新意图终点单元 end_block_update_1["id"] = block_id end_block_update_2["id"] = block_id resp_update_1 = client.update_end_block(end_block_update_1) resp_update_2 = client.update_end_block(end_block_update_2) assert block_id == resp_update_1.block.id assert block_id == resp_update_2.block.id # 查询询问填槽单元 resp = client.end_block(block_id) assert resp.block.name # 删除单元 client.delete_block(block_id) # 删除意图 client.delete_intent(intent_id)
def test_credential(debug, user_id, avatar_url, nickname): client = WulaiClient("asEGUJtCyLkHvTmm8vE0bXLe5ebGs2PP00df19808441f2cfff", secret, debug=debug) with pytest.raises(ClientException) as excinfo: client.create_user(user_id, avatar_url, nickname) assert excinfo.error_code == "SDK_INVALID_CREDENTIAL"
def test_scenes(scene_create, scene_update): client = WulaiClient(pubkey, secret, debug=True) # 创建场景 resp_create = client.create_scene(scene_create) scene_id = resp_create.scene.id # 更新场景 scene_update["id"] = scene_id resp_update = client.update_scene(scene_update) assert scene_id == resp_update.scene.id # 查询场景列表 resp_list = client.scenes() scene_ids = [scene.id for scene in resp_list.scenes] assert scene_id in scene_ids # 删除场景 client.delete_scene(scene_id) # 查询场景列表 resp_list = client.scenes() scene_ids = [scene.id for scene in resp_list.scenes] assert scene_id not in scene_ids
def test_knowledge_tags(page, page_size, knowledge_c, knowledge_u): client = WulaiClient(pubkey, secret, debug=True) # tags # -- without parent_k_tag_id resp_parent_tags = client.knowledge_tags(page, page_size) parent_k_tag_id = resp_parent_tags.knowledge_tags[0].id # -- with parent_k_tag_id resp_second_tags = client.knowledge_tags(page, page_size, parent_k_tag_id) knowledge_tags = resp_second_tags.knowledge_tags knowledge_tags_di = [r.to_dict() for r in knowledge_tags] target_id = find_value_from_dict_array(knowledge_tags_di, "name", "id", "测试_yt") # create knowledge_c["knowledge_tag_id"] = target_id resp_knowledge_c = client.create_knowledge(knowledge_c) knowledge_id = resp_knowledge_c.knowledge_tag_knowledge.knowledge.id # update knowledge_u["id"] = knowledge_id resp_knowledge_u = client.update_knowledge(knowledge_u) # items # 过滤查询 resp_knowledges = client.knowledge_items(page, page_size=50, knowledge_filter={"knowledge_tag_id": target_id}) assert resp_knowledges.to_dict() # 无条件查询 resp = client.knowledge_items(page, page_size=10) assert resp_knowledge_u.knowledge.id == knowledge_id assert resp.page_count # similar-question # create similar_question_c = { "knowledge_id": knowledge_id, "question": "我能在你左边画条龙嘛?" } resp_similar_c = client.create_similar_question(similar_question_c) # update similar_question_id = resp_similar_c.similar_question.id similar_question_u = { "knowledge_id": knowledge_id, "question": "我能在你左边画条龙嘛?-改", "id": similar_question_id } resp_similar_u = client.update_similar_question(similar_question_u) # list resp_similar_list = client.similar_questions(page, page_size, knowledge_id, timeout=10) assert resp_similar_u.similar_question.to_dict() in [r.to_dict() for r in resp_similar_list.similar_questions] # delete resp = client.delete_similar_question(similar_question_id) assert isinstance(resp, dict) # delete knowledge resp = client.delete_knowledge(knowledge_id) assert isinstance(resp, dict)
def test_stats_qa_satisfaction_daily_knowledges_error(start_date, end_date, page, page_size): client = WulaiClient(pubkey, secret, debug=True) with pytest.raises(ClientException) as excinfo: client.stats_qa_satisfaction_daily_knowledges(start_date, end_date, page, page_size) assert excinfo.error_code == "SDK_INVALID_PARAMS"
def test_update_user(user_id, avatar_url, nickname): client = WulaiClient(pubkey, secret, debug=True) client.update_user(user_id, avatar_url, nickname) resp = client.get_user(user_id) if avatar_url: assert resp.avatar_url == avatar_url assert resp.nickname == nickname else: assert resp.avatar_url assert resp.nickname
def test_common_request(debug, action, params, expected): opts = { "method": "POST", "timeout": 3, "retry": 0, } client = WulaiClient(pubkey, secret, debug=debug) request = CommonRequest(action, params, opts) resp = client.process_common_request(request) assert resp == expected
def test_knowledge_tags(knowledge_items): client = WulaiClient(pubkey, secret, debug=True) resp = client.batch_create_knowledge(knowledge_items) assert resp.to_dict() knowledge_id = resp.knowledge_related_items[0].knowledge.id knowledge_tag_id = resp.knowledge_related_items[0].knowledge_tag.id assert knowledge_tag_id client.delete_knowledge(knowledge_id)
def test_message_history(user_id, num): client = WulaiClient(pubkey, secret, debug=True) resp = client.get_message_history(user_id, num) assert resp.to_dict() assert isinstance(resp.msg[0].user_info.nickname, str) assert isinstance(resp.msg[0].msg_body.to_dict(), dict) msg_body = resp.msg[0].msg_body if hasattr(msg_body, "text"): assert isinstance(msg_body.text.content, str) elif hasattr(msg_body, "image"): assert isinstance(msg_body.image.resource_url, str)
def test_intent_trigger_learning(): client = WulaiClient(pubkey, secret, debug=True) # 查询任务待审核消息列表 resp_list = client.intent_trigger_learning(1, 50) assert resp_list.to_dict() if resp_list.query_items: query_item = resp_list.query_items[0] assert query_item.recommend_intent.intent_name intent_trigger_learning_id = query_item.id # 删除任务待审核消息 client.delete_intent_trigger_learning(intent_trigger_learning_id)
def test_slot(slot_create, slot_update, data_source): client = WulaiClient(pubkey, secret, debug=False) # 创建词槽 resp_create = client.create_slot(slot_create) slot_id = resp_create.slot.id # 创建词槽数据来源 data_source["slot_id"] = slot_id resp_data_source_create = client.create_slot_data_source(data_source) data_source_id = resp_data_source_create.data_source.id assert resp_data_source_create.data_source.entity_id == 2 assert data_source_id # 查询词槽数据来源 resp_data_source = client.slot_data_source(slot_id) slot_ids_ds = [ one_data_source.slot_id for one_data_source in resp_data_source.data_sources ] assert slot_id in slot_ids_ds # 删除词槽数据来源 client.delete_slot_data_source(data_source_id) # 更新词槽 slot_update["id"] = slot_id time.sleep(1) resp_update = client.update_slot(slot_update) assert slot_id == resp_update.slot.id # 查询词槽 slot = client.get_slot(slot_id) assert slot.slot.name # 查询词槽列表 resp_list = client.slots(slot_create["scene_id"], 1, 50) slot_ids = [slot.id for slot in resp_list.slots] assert slot_id in slot_ids # 删除词槽 client.delete_slot(slot_id) # 查询词槽列表 resp_list = client.slots(slot_create["scene_id"], 1, 50) slot_ids = [slot.id for slot in resp_list.slots] assert slot_id not in slot_ids
async def post(self, *args, **kwargs): pubkey = "asEGUJtCyLkHvTmm8vE0bXLe5ebGs2PP00df19808441f2ceac" secret = "Ac6ogAAgaTXojvX2LFBS" client = WulaiClient(pubkey, secret) data = json.loads(self.request.body) msg = data["msg"] msg_body = {"text": {"content": msg}} user_id = data["user_id"] client.create_user(user_id) resp = client.receive_message(user_id, msg_body) return self.write(resp.to_dict())
def test_entities_extract(query): client = WulaiClient(pubkey, secret, debug=True) resp = client.entities_extract(query) assert resp.to_dict() for entity in resp.entities: if hasattr(entity.entity, "system_entity"): assert entity.entity.system_entity.standard_value elif hasattr(entity.entity, "enumeration_entity"): assert entity.entity.enumeration_entity.standard_value elif hasattr(entity.entity, "regex_entity"): assert entity.entity.regex_entity.name else: # error assert False
def test_dictionary_entities(page, page_size): client = WulaiClient(pubkey, secret, debug=True) resp = client.dictionary_entities(page, page_size) if not resp.entities: assert resp.to_dict() assert not resp.entities else: entity = resp.entities[-1] entity_id = entity.id resp_entity = client.dictionary_entity(entity_id) assert resp.to_dict() assert resp_entity.to_dict()
def test_mining_result(): client = WulaiClient(pubkey, secret, debug=True) resp = client.mining_result(1, 50) # 聚类中 if resp.status == "MINING_STATUS_IN_PROGRESS": assert 1 # 聚类结束 else: if resp.page_count: sentence_ids = [] for cluster in resp.clusters: for sentence in cluster.sentences: sentence_ids.append(sentence.id) del_id = random.choice(sentence_ids) # 删除聚类结果 client.delete_mining_sentence(del_id)
def test_user_attribute(user_attribute_group_item, user_attribute_group_item_update, user_attribute_group_answer, user_attribute_group_answer_update, page, page_size): # 属性组测试知识点分类id:125537,知识点id: 1048247 client = WulaiClient(pubkey, secret, debug=True) # 创建属性组 # todo:每一次测试后需要去项目里手动删除这个属性组 resp_cuagi = client.create_user_attribute_group_items(user_attribute_group_item) # 更新属性组 # 属性组id user_attribute_group_id = resp_cuagi.user_attribute_group_item.user_attribute_group.id user_attribute_group_item_update["user_attribute_group"]["id"] = user_attribute_group_id resp_uuagi = client.update_user_attribute_group_items(user_attribute_group_item_update) # 属性组名称 user_attribute_group_name = resp_uuagi.user_attribute_group_item.user_attribute_group.name # 查询属性组及属性列表 resp_uagi = client.user_attribute_group_items(page, page_size, timeout=10) user_attribute_group_ids = [uagi.user_attribute_group.id for uagi in resp_uagi.user_attribute_group_items] user_attribute_group_names = [uagi.user_attribute_group.name for uagi in resp_uagi.user_attribute_group_items] assert user_attribute_group_id in user_attribute_group_ids assert user_attribute_group_name in user_attribute_group_names # 创建属性组回复 user_attribute_group_answer["user_attribute_group_id"] = user_attribute_group_id resp_cuaga = client.create_user_attribute_group_answer(user_attribute_group_answer) # 属性组答案id user_attribute_group_answer_id = resp_cuaga.user_attribute_group_answer.answer.id # 更新属性组回复 user_attribute_group_answer_update["answer"]["id"] = user_attribute_group_answer_id user_attribute_group_answer_update["user_attribute_group_id"] = user_attribute_group_id resp_uuaga = client.update_user_attribute_group_answer(user_attribute_group_answer_update) assert resp_uuaga.user_attribute_group_answer.answer.id == user_attribute_group_answer_id # 查询属性组回复列表 resp_answers = client.user_attribute_group_answers(page, page_size, timeout=10) resp_answers_2 = client.user_attribute_group_answers(page, page_size, {"knowledge_id": "1048247"}, timeout=10) assert isinstance(resp_answers.user_attribute_group_answers, list) assert isinstance(resp_answers_2.user_attribute_group_answers, list) # 删除属性组回复 resp = client.delete_user_attribute_group_answer(user_attribute_group_answer_id)
def test_inform_block(inform_block_create, inform_block_update, response_create, response_update): client = WulaiClient(pubkey, secret, debug=True) # 创建消息发送单元 resp_create = client.create_inform_block(inform_block_create) inform_block_id = resp_create.block.id # 更新消息发送单元 inform_block_update["id"] = inform_block_id resp_update = client.update_inform_block(inform_block_update) assert inform_block_id == resp_update.block.id # 查询消息发送单元 resp = client.inform_block(inform_block_id) assert resp.block.name # 创建单元内回复 response_create["block_id"] = inform_block_id resp_resp_create = client.create_block_response(response_create) assert resp_resp_create.response.response.to_dict() key = list(resp_resp_create.response.response.__dict__.keys())[0] assert getattr(resp_resp_create.response.response, key).to_dict() resp_id = resp_resp_create.response.id # 更新单元内回复 response_update["id"] = resp_id resp_resp_update = client.update_block_response(response_update) assert resp_resp_update.response.response.to_dict() key = list(resp_resp_update.response.response.__dict__.keys())[0] assert getattr(resp_resp_update.response.response, key).to_dict() # 删除单元内回复 client.delete_block_response(resp_id) # 删除单元 client.delete_block(inform_block_id)
def test_knowledge_tags_new(knowledge_tag_create, knowledge_tag_update, knowledge_tag_child): client = WulaiClient(pubkey, secret, debug=True) knowledge_tag_c = client.create_knowledge_tag(knowledge_tag_create) knowledge_tag_id = knowledge_tag_c.knowledge_tag.id assert knowledge_tag_id assert knowledge_tag_c.knowledge_tag.name assert knowledge_tag_c.knowledge_tag.parent_knowledge_tag_id # 创建子分类 knowledge_tag_child["parent_knowledge_tag_id"] = knowledge_tag_id client.create_knowledge_tag(knowledge_tag_child) knowledge_tag_update["id"] = knowledge_tag_id knowledge_tag_u = client.update_knowledge_tag(knowledge_tag_update) assert knowledge_tag_u.knowledge_tag.id assert knowledge_tag_u.knowledge_tag.name assert knowledge_tag_u.knowledge_tag.parent_knowledge_tag_id client.delete_knowledge_tag(knowledge_tag_id)
def test_dictionary_term(term_item_create, term_item_update, page, page_size): client = WulaiClient(pubkey, secret, debug=True) # 创建专有词汇 resp_create = client.create_dictionary_term(term_item_create) term_id = resp_create.term_item.term.id assert term_id # 更新专有词汇 term_item_update["term"]["id"] = term_id resp_update = client.update_dictionary_term(term_item_update) term_id_2 = resp_update.term_item.term.id assert term_id == term_id_2 # 专有词汇列表 resp_list = client.dictionary_terms(page, page_size) term_ids = [term_item.term.id for term_item in resp_list.term_item] assert term_id in term_ids # 删除专有词汇 client.delete_dictionary_term(term_id)
def test_dictionary_entities_intent(intent_entity, entity_value_update, entity_value_delete): client = WulaiClient(pubkey, secret, debug=True) # 创建意图实体 resp_entity_intent = client.create_dictionary_entity_intent(intent_entity) entity_intent_id = resp_entity_intent.intent_entity.id # 创建意图实体值相似说法 resp_create = client.create_dictionary_entity_intent_value( entity_intent_id, entity_value_update) assert entity_intent_id == resp_create.intent_entity.id # 删除意图实体值相似说法 client.delete_dictionary_entity_intent_value(entity_intent_id, entity_value_delete) # 删除实体 client.delete_dictionary_entity(entity_intent_id) with pytest.raises(ClientException) as excinfo: client.dictionary_entity(entity_intent_id) assert excinfo.error_code == "SDK_INVALID_PARAMS"
实现效果:发送消息给机器人,得到相应回复。 对接前提: 1. 调用方提供接入机器人的渠道。 2. 已经在吾来机器人平台搭建并训练了机器人。 对接步骤: 1. 调用 user/create 接口,传入 user_id,创建用户; 2. 调用 msg/bot-response 接口,传入用户消息和 user_id; 3. 机器人会返回1~10条可能的回复,按照置信度从高到低排序。 调用方可根据自己业务需要,依据置信度参数 score 的高低或者 is_send 的值,选择一条或多条回复。 """ import os from wulaisdk.client import WulaiClient pubkey = os.getenv("PUBKEY", "") secret = os.getenv("SECRET", "") client = WulaiClient(pubkey, secret, debug=False) # 创建用户 resp_cu = client.create_user("test_user", nickname="测试用户") # 获取回复 msg_body = { "text": {"content": "你好"} } resp_gbr = client.get_bot_response("test_user", msg_body)
def test_whole(): client = WulaiClient(pubkey, secret, debug=True) # 创建意图 intent = {"scene_id": test_scene_id, "name": "全流程测试意图", "lifespan_mins": 5} resp_create_intent = client.create_intent(intent) intent_id = resp_create_intent.intent.id # 创建消息发送单元 inform_block_1 = { "intent_id": intent_id, "name": "消息发送1", "mode": "RESPONSE_ALL" } inform_block_2 = { "intent_id": intent_id, "name": "消息发送2", "mode": "RESPONSE_ALL" } resp_inform_block_id1 = client.create_inform_block(inform_block_1) resp_inform_block_id2 = client.create_inform_block(inform_block_2) inform_block_1_id = resp_inform_block_id1.block.id inform_block_2_id = resp_inform_block_id2.block.id # 创建单元内回复 response_1_1 = { "block_id": inform_block_1_id, "response": { "text": { "content": "回复1_1" } } } response_1_2 = { "block_id": inform_block_1_id, "response": { "text": { "content": "回复1_2" } } } response_2_1 = { "block_id": inform_block_2_id, "response": { "text": { "content": "回复2_1" } } } client.create_block_response(response_1_1) client.create_block_response(response_1_2) client.create_block_response(response_2_1) # 创建询问单元 request_block = { "intent_id": intent_id, "name": "询问单元1", "mode": "RESPONSE_ALL", "default_slot_value": "_default", "slot_filling_when_asked": False, "request_count": 2, "slot_id": test_slot_id } resp_request_block = client.create_request_block(request_block) request_block_id = resp_request_block.block.id # 创建单元内回复 response_1_1 = { "block_id": request_block_id, "response": { "text": { "content": "询问1:" } } } client.create_block_response(response_1_1) # 创建意图终点单元 end_block = { "intent_id": intent_id, "name": "终点单元1", "slot_memorizing": False, "action": { "end": {} } } resp_end_block = client.create_end_block(end_block) end_block_id = resp_end_block.block.id # 创建单元关系 # 1.消息单元1->询问单元 relation_1 = { "connection": { "from_block_id": inform_block_1_id, "to_block_id": request_block_id }, "intent_id": intent_id } resp_relation_1 = client.create_block_relation(relation_1) assert resp_relation_1.relation.id # 2. 询问单元->消息单元2 relation_2 = { "connection": { "from_block_id": request_block_id, "to_block_id": inform_block_2_id, "condition": { "less_than_or_equal_to": { "value": 50 } } }, "intent_id": intent_id } resp_relation_2 = client.create_block_relation(relation_2) assert resp_relation_2.relation.intent_id # 3. 询问单元->意图终点单元 relation_3 = { "connection": { "from_block_id": request_block_id, "to_block_id": end_block_id, "condition": { "greater_than": { "value": 50 } } }, "intent_id": intent_id } resp_relation_3 = client.create_block_relation(relation_3) assert resp_relation_3.relation.connection.condition.greater_than.value # 4. 询问单元->消息单元2 relation_4 = { "connection": { "from_block_id": request_block_id, "to_block_id": inform_block_2_id, "condition": { "default": {} } }, "intent_id": intent_id } resp_relation_4 = client.create_block_relation(relation_4) relation_4_id = resp_relation_4.relation.id # 5. 消息单元2->意图终点单元 relation_5 = { "connection": { "from_block_id": inform_block_2_id, "to_block_id": end_block_id }, "intent_id": intent_id } resp_relation_5 = client.create_block_relation(relation_5) assert resp_relation_5.relation.connection.from_block_id # 更新意图状态 status = True first_block_id = inform_block_1_id client.update_intent_status(status, first_block_id, intent_id) # 删除单元关系 client.delete_block_relation(relation_4_id) # 查询单元列表 resp_list = client.blocks(intent_id, 1, 50) assert resp_list.blocks block_ids = [block.id for block in resp_list.blocks] assert inform_block_1_id in block_ids assert inform_block_2_id in block_ids assert request_block_id in block_ids assert end_block_id in block_ids # 删除意图 client.delete_intent(intent_id)