config_entity.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. class BaseTracingConfig(BaseModel):
  8. """
  9. Base model class for tracing
  10. """
  11. ...
  12. class LangfuseConfig(BaseTracingConfig):
  13. """
  14. Model class for Langfuse tracing config.
  15. """
  16. public_key: str
  17. secret_key: str
  18. host: str = "https://api.langfuse.com"
  19. @field_validator("host")
  20. @classmethod
  21. def set_value(cls, v, info: ValidationInfo):
  22. if v is None or v == "":
  23. v = "https://api.langfuse.com"
  24. if not v.startswith("https://") and not v.startswith("http://"):
  25. raise ValueError("host must start with https:// or http://")
  26. return v
  27. class LangSmithConfig(BaseTracingConfig):
  28. """
  29. Model class for Langsmith tracing config.
  30. """
  31. api_key: str
  32. project: str
  33. endpoint: str = "https://api.smith.langchain.com"
  34. @field_validator("endpoint")
  35. @classmethod
  36. def set_value(cls, v, info: ValidationInfo):
  37. if v is None or v == "":
  38. v = "https://api.smith.langchain.com"
  39. if not v.startswith("https://"):
  40. raise ValueError("endpoint must start with https://")
  41. return v
  42. class OpikConfig(BaseTracingConfig):
  43. """
  44. Model class for Opik tracing config.
  45. """
  46. api_key: str | None = None
  47. project: str | None = None
  48. workspace: str | None = None
  49. url: str = "https://www.comet.com/opik/api/"
  50. @field_validator("project")
  51. @classmethod
  52. def project_validator(cls, v, info: ValidationInfo):
  53. if v is None or v == "":
  54. v = "Default Project"
  55. return v
  56. @field_validator("url")
  57. @classmethod
  58. def url_validator(cls, v, info: ValidationInfo):
  59. if v is None or v == "":
  60. v = "https://www.comet.com/opik/api/"
  61. if not v.startswith(("https://", "http://")):
  62. raise ValueError("url must start with https:// or http://")
  63. if not v.endswith("/api/"):
  64. raise ValueError("url should ends with /api/")
  65. return v
  66. OPS_FILE_PATH = "ops_trace/"
  67. OPS_TRACE_FAILED_KEY = "FAILED_OPS_TRACE"