You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

variables.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. from collections.abc import Sequence
  2. from typing import cast
  3. from uuid import uuid4
  4. from pydantic import BaseModel, Field
  5. from core.helper import encrypter
  6. from .segments import (
  7. ArrayAnySegment,
  8. ArrayFileSegment,
  9. ArrayNumberSegment,
  10. ArrayObjectSegment,
  11. ArraySegment,
  12. ArrayStringSegment,
  13. FileSegment,
  14. FloatSegment,
  15. IntegerSegment,
  16. NoneSegment,
  17. ObjectSegment,
  18. Segment,
  19. StringSegment,
  20. )
  21. from .types import SegmentType
  22. class Variable(Segment):
  23. """
  24. A variable is a segment that has a name.
  25. """
  26. id: str = Field(
  27. default_factory=lambda: str(uuid4()),
  28. description="Unique identity for variable.",
  29. )
  30. name: str
  31. description: str = Field(default="", description="Description of the variable.")
  32. selector: Sequence[str] = Field(default_factory=list)
  33. class StringVariable(StringSegment, Variable):
  34. pass
  35. class FloatVariable(FloatSegment, Variable):
  36. pass
  37. class IntegerVariable(IntegerSegment, Variable):
  38. pass
  39. class ObjectVariable(ObjectSegment, Variable):
  40. pass
  41. class ArrayVariable(ArraySegment, Variable):
  42. pass
  43. class ArrayAnyVariable(ArrayAnySegment, ArrayVariable):
  44. pass
  45. class ArrayStringVariable(ArrayStringSegment, ArrayVariable):
  46. pass
  47. class ArrayNumberVariable(ArrayNumberSegment, ArrayVariable):
  48. pass
  49. class ArrayObjectVariable(ArrayObjectSegment, ArrayVariable):
  50. pass
  51. class SecretVariable(StringVariable):
  52. value_type: SegmentType = SegmentType.SECRET
  53. @property
  54. def log(self) -> str:
  55. return cast(str, encrypter.obfuscated_token(self.value))
  56. class NoneVariable(NoneSegment, Variable):
  57. value_type: SegmentType = SegmentType.NONE
  58. value: None = None
  59. class FileVariable(FileSegment, Variable):
  60. pass
  61. class ArrayFileVariable(ArrayFileSegment, ArrayVariable):
  62. pass
  63. class RAGPipelineVariable(BaseModel):
  64. belong_to_node_id: str = Field(description="belong to which node id, shared means public")
  65. type: str = Field(description="variable type, text-input, paragraph, select, number, file, file-list")
  66. label: str = Field(description="label")
  67. description: str | None = Field(description="description", default="")
  68. variable: str = Field(description="variable key", default="")
  69. max_length: int | None = Field(
  70. description="max length, applicable to text-input, paragraph, and file-list", default=0
  71. )
  72. default_value: str | None = Field(description="default value", default="")
  73. placeholder: str | None = Field(description="placeholder", default="")
  74. unit: str | None = Field(description="unit, applicable to Number", default="")
  75. tooltips: str | None = Field(description="helpful text", default="")
  76. allowed_file_types: list[str] | None = Field(
  77. description="image, document, audio, video, custom.", default_factory=list
  78. )
  79. allowed_file_extensions: list[str] | None = Field(description="e.g. ['.jpg', '.mp3']", default_factory=list)
  80. allowed_file_upload_methods: list[str] | None = Field(
  81. description="remote_url, local_file, tool_file.", default_factory=list
  82. )
  83. required: bool = Field(description="optional, default false", default=False)
  84. options: list[str] | None = Field(default_factory=list)