| 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														    if not prompt_config["system"]: | 
														 | 
														 | 
														    if not prompt_config["system"]: | 
													
													
												
													
														 | 
														 | 
														        prompt_config["system"] = default_prompt["system"] | 
														 | 
														 | 
														        prompt_config["system"] = default_prompt["system"] | 
													
													
												
													
														 | 
														 | 
														    # if len(prompt_config["parameters"]) < 1: | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														    #     prompt_config["parameters"] = default_prompt["parameters"] | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														    # for p in prompt_config["parameters"]: | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														    #     if p["key"] == "knowledge":break | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														    # else: prompt_config["parameters"].append(default_prompt["parameters"][0]) | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														    for p in prompt_config["parameters"]: | 
														 | 
														 | 
														    for p in prompt_config["parameters"]: | 
													
													
												
													
														 | 
														 | 
														        if p["optional"]: | 
														 | 
														 | 
														        if p["optional"]: | 
													
													
												
											
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														        e, tenant = TenantService.get_by_id(current_user.id) | 
														 | 
														 | 
														        e, tenant = TenantService.get_by_id(current_user.id) | 
													
													
												
													
														 | 
														 | 
														        if not e: | 
														 | 
														 | 
														        if not e: | 
													
													
												
													
														 | 
														 | 
														            return get_data_error_result(message="Tenant not found!") | 
														 | 
														 | 
														            return get_data_error_result(message="Tenant not found!") | 
													
													
												
													
														 | 
														 | 
														        kbs = KnowledgebaseService.get_by_ids(req.get("kb_ids")) | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        kbs = KnowledgebaseService.get_by_ids(req.get("kb_ids", [])) | 
													
													
												
													
														 | 
														 | 
														        embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs]  # remove vendor suffix for comparison | 
														 | 
														 | 
														        embd_ids = [TenantLLMService.split_model_name_and_factory(kb.embd_id)[0] for kb in kbs]  # remove vendor suffix for comparison | 
													
													
												
													
														 | 
														 | 
														        embd_count = len(set(embd_ids)) | 
														 | 
														 | 
														        embd_count = len(set(embd_ids)) | 
													
													
												
													
														 | 
														 | 
														        if embd_count != 1: | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														        if embd_count > 1: | 
													
													
												
													
														 | 
														 | 
														            return get_data_error_result(message=f'Datasets use different embedding models: {[kb.embd_id for kb in kbs]}"') | 
														 | 
														 | 
														            return get_data_error_result(message=f'Datasets use different embedding models: {[kb.embd_id for kb in kbs]}"') | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														
  | 
													
													
												
													
														 | 
														 | 
														        llm_id = req.get("llm_id", tenant.llm_id) | 
														 | 
														 | 
														        llm_id = req.get("llm_id", tenant.llm_id) | 
													
													
												
													
														 | 
														 | 
														        if not dialog_id: | 
														 | 
														 | 
														        if not dialog_id: | 
													
													
												
													
														 | 
														 | 
														            if not req.get("kb_ids"): | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                return get_data_error_result( | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														                    message="Fail! Please select knowledgebase!") | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														
  | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														            dia = { | 
														 | 
														 | 
														            dia = { | 
													
													
												
													
														 | 
														 | 
														                "id": get_uuid(), | 
														 | 
														 | 
														                "id": get_uuid(), | 
													
													
												
													
														 | 
														 | 
														                "tenant_id": current_user.id, | 
														 | 
														 | 
														                "tenant_id": current_user.id, | 
													
													
												
													
														 | 
														 | 
														                "name": name, | 
														 | 
														 | 
														                "name": name, | 
													
													
												
													
														 | 
														 | 
														                "kb_ids": req["kb_ids"], | 
														 | 
														 | 
														 | 
													
													
												
													
														 | 
														 | 
														 | 
														 | 
														 | 
														                "kb_ids": req.get("kb_ids", []), | 
													
													
												
													
														 | 
														 | 
														                "description": description, | 
														 | 
														 | 
														                "description": description, | 
													
													
												
													
														 | 
														 | 
														                "llm_id": llm_id, | 
														 | 
														 | 
														                "llm_id": llm_id, | 
													
													
												
													
														 | 
														 | 
														                "llm_setting": llm_setting, | 
														 | 
														 | 
														                "llm_setting": llm_setting, |