Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

6 місяці тому
5 місяці тому
5 місяці тому
6 місяці тому
6 місяці тому
5 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
5 місяці тому
6 місяці тому
6 місяці тому
5 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
6 місяці тому
4 місяці тому
4 місяці тому
6 місяці тому
5 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
4 місяці тому
6 місяці тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from typing import Optional
  2. import yaml
  3. from flask_login import current_user
  4. from extensions.ext_database import db
  5. from models.dataset import PipelineCustomizedTemplate
  6. from services.rag_pipeline.pipeline_template.pipeline_template_base import PipelineTemplateRetrievalBase
  7. from services.rag_pipeline.pipeline_template.pipeline_template_type import PipelineTemplateType
  8. class CustomizedPipelineTemplateRetrieval(PipelineTemplateRetrievalBase):
  9. """
  10. Retrieval recommended app from database
  11. """
  12. def get_pipeline_templates(self, language: str) -> dict:
  13. result = self.fetch_pipeline_templates_from_customized(
  14. tenant_id=current_user.current_tenant_id, language=language
  15. )
  16. return result
  17. def get_pipeline_template_detail(self, template_id: str):
  18. result = self.fetch_pipeline_template_detail_from_db(template_id)
  19. return result
  20. def get_type(self) -> str:
  21. return PipelineTemplateType.CUSTOMIZED
  22. @classmethod
  23. def fetch_pipeline_templates_from_customized(cls, tenant_id: str, language: str) -> dict:
  24. """
  25. Fetch pipeline templates from db.
  26. :param tenant_id: tenant id
  27. :param language: language
  28. :return:
  29. """
  30. pipeline_customized_templates = (
  31. db.session.query(PipelineCustomizedTemplate)
  32. .filter(PipelineCustomizedTemplate.tenant_id == tenant_id, PipelineCustomizedTemplate.language == language)
  33. .all()
  34. )
  35. recommended_pipelines_results = []
  36. for pipeline_customized_template in pipeline_customized_templates:
  37. recommended_pipeline_result = {
  38. "id": pipeline_customized_template.id,
  39. "name": pipeline_customized_template.name,
  40. "description": pipeline_customized_template.description,
  41. "icon": pipeline_customized_template.icon,
  42. "position": pipeline_customized_template.position,
  43. "chunk_structure": pipeline_customized_template.chunk_structure,
  44. }
  45. recommended_pipelines_results.append(recommended_pipeline_result)
  46. return {"pipeline_templates": recommended_pipelines_results}
  47. @classmethod
  48. def fetch_pipeline_template_detail_from_db(cls, template_id: str) -> Optional[dict]:
  49. """
  50. Fetch pipeline template detail from db.
  51. :param template_id: Template ID
  52. :return:
  53. """
  54. pipeline_template = (
  55. db.session.query(PipelineCustomizedTemplate).filter(PipelineCustomizedTemplate.id == template_id).first()
  56. )
  57. if not pipeline_template:
  58. return None
  59. dsl_data = yaml.safe_load(pipeline_template.yaml_content)
  60. graph_data = dsl_data.get("workflow", {}).get("graph", {})
  61. return {
  62. "id": pipeline_template.id,
  63. "name": pipeline_template.name,
  64. "icon_info": pipeline_template.icon,
  65. "description": pipeline_template.description,
  66. "chunk_structure": pipeline_template.chunk_structure,
  67. "export_data": pipeline_template.yaml_content,
  68. "graph": graph_data,
  69. "created_by": pipeline_template.created_user_name,
  70. }