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.

config_entity.py 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. from enum import Enum
  2. from pydantic import BaseModel, ValidationInfo, field_validator
  3. class TracingProviderEnum(Enum):
  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. @field_validator("endpoint")
  76. @classmethod
  77. def set_value(cls, v, info: ValidationInfo):
  78. if v is None or v == "":
  79. v = "https://trace.wandb.ai"
  80. if not v.startswith("https://"):
  81. raise ValueError("endpoint must start with https://")
  82. return v
  83. OPS_FILE_PATH = "ops_trace/"
  84. OPS_TRACE_FAILED_KEY = "FAILED_OPS_TRACE"