您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

config_entity.py 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. from enum import StrEnum
  2. from pydantic import BaseModel, ValidationInfo, field_validator
  3. class TracingProviderEnum(StrEnum):
  4. LANGFUSE = "langfuse"
  5. LANGSMITH = "langsmith"
  6. OPIK = "opik"
  7. WEAVE = "weave"
  8. class BaseTracingConfig(BaseModel):
  9. """
  10. Base model class for tracing
  11. """
  12. ...
  13. class LangfuseConfig(BaseTracingConfig):
  14. """
  15. Model class for Langfuse tracing config.
  16. """
  17. public_key: str
  18. secret_key: str
  19. host: str = "https://api.langfuse.com"
  20. @field_validator("host")
  21. @classmethod
  22. def set_value(cls, v, info: ValidationInfo):
  23. if v is None or v == "":
  24. v = "https://api.langfuse.com"
  25. if not v.startswith("https://") and not v.startswith("http://"):
  26. raise ValueError("host must start with https:// or http://")
  27. return v
  28. class LangSmithConfig(BaseTracingConfig):
  29. """
  30. Model class for Langsmith tracing config.
  31. """
  32. api_key: str
  33. project: str
  34. endpoint: str = "https://api.smith.langchain.com"
  35. @field_validator("endpoint")
  36. @classmethod
  37. def set_value(cls, v, info: ValidationInfo):
  38. if v is None or v == "":
  39. v = "https://api.smith.langchain.com"
  40. if not v.startswith("https://"):
  41. raise ValueError("endpoint must start with https://")
  42. return v
  43. class OpikConfig(BaseTracingConfig):
  44. """
  45. Model class for Opik tracing config.
  46. """
  47. api_key: str | None = None
  48. project: str | None = None
  49. workspace: str | None = None
  50. url: str = "https://www.comet.com/opik/api/"
  51. @field_validator("project")
  52. @classmethod
  53. def project_validator(cls, v, info: ValidationInfo):
  54. if v is None or v == "":
  55. v = "Default Project"
  56. return v
  57. @field_validator("url")
  58. @classmethod
  59. def url_validator(cls, v, info: ValidationInfo):
  60. if v is None or v == "":
  61. v = "https://www.comet.com/opik/api/"
  62. if not v.startswith(("https://", "http://")):
  63. raise ValueError("url must start with https:// or http://")
  64. if not v.endswith("/api/"):
  65. raise ValueError("url should ends with /api/")
  66. return v
  67. class WeaveConfig(BaseTracingConfig):
  68. """
  69. Model class for Weave tracing config.
  70. """
  71. api_key: str
  72. entity: str | None = None
  73. project: str
  74. endpoint: str = "https://trace.wandb.ai"
  75. host: str | None = None
  76. @field_validator("endpoint")
  77. @classmethod
  78. def set_value(cls, v, info: ValidationInfo):
  79. if v is None or v == "":
  80. v = "https://trace.wandb.ai"
  81. if not v.startswith("https://"):
  82. raise ValueError("endpoint must start with https://")
  83. return v
  84. @field_validator("host")
  85. @classmethod
  86. def validate_host(cls, v, info: ValidationInfo):
  87. if v is not None and v != "":
  88. if not v.startswith(("https://", "http://")):
  89. raise ValueError("host must start with https:// or http://")
  90. return v
  91. OPS_FILE_PATH = "ops_trace/"
  92. OPS_TRACE_FAILED_KEY = "FAILED_OPS_TRACE"