|
1 | 1 | """Configuration models for storage backends. |
2 | 2 |
|
3 | | -Defines Pydantic models for file and database storage configuration. |
| 3 | +Defines Pydantic models for file, database, and Langfuse storage configuration. |
4 | 4 | """ |
5 | 5 |
|
6 | 6 | from typing import Annotated, Literal, Optional |
@@ -126,8 +126,39 @@ def validate_connection_fields(self) -> "DatabaseBackendConfig": |
126 | 126 | return self |
127 | 127 |
|
128 | 128 |
|
| 129 | +class LangfuseBackendConfig(BaseModel): |
| 130 | + """Configuration for Langfuse observability storage backend. |
| 131 | +
|
| 132 | + Exports evaluation scores to Langfuse as a trace with per-metric scores. |
| 133 | + Requires the ``langfuse`` optional extra: ``pip install 'lightspeed-evaluation[langfuse]'`` |
| 134 | +
|
| 135 | + Credentials are resolved from config fields first, then ``LANGFUSE_PUBLIC_KEY``, |
| 136 | + ``LANGFUSE_SECRET_KEY``, and ``LANGFUSE_HOST`` environment variables as fallback. |
| 137 | +
|
| 138 | + Example: |
| 139 | + - type: "langfuse" |
| 140 | + host: "https://cloud.langfuse.com" |
| 141 | + """ |
| 142 | + |
| 143 | + model_config = ConfigDict(extra="forbid") |
| 144 | + |
| 145 | + type: Literal["langfuse"] = "langfuse" |
| 146 | + host: Optional[str] = Field( |
| 147 | + default=None, |
| 148 | + description="Langfuse API host URL (falls back to LANGFUSE_HOST env var)", |
| 149 | + ) |
| 150 | + public_key: Optional[str] = Field( |
| 151 | + default=None, |
| 152 | + description="Langfuse public key (falls back to LANGFUSE_PUBLIC_KEY env var)", |
| 153 | + ) |
| 154 | + secret_key: Optional[str] = Field( |
| 155 | + default=None, |
| 156 | + description="Langfuse secret key (falls back to LANGFUSE_SECRET_KEY env var)", |
| 157 | + ) |
| 158 | + |
| 159 | + |
129 | 160 | # Discriminated union for polymorphic storage configuration |
130 | 161 | StorageBackendConfig = Annotated[ |
131 | | - FileBackendConfig | DatabaseBackendConfig, |
| 162 | + FileBackendConfig | DatabaseBackendConfig | LangfuseBackendConfig, |
132 | 163 | Field(discriminator="type"), |
133 | 164 | ] |
0 commit comments