Skip to content

Commit 7f0d529

Browse files
committed
add back enums
1 parent 0cf5f26 commit 7f0d529

30 files changed

Lines changed: 775 additions & 150 deletions

langfuse/_client/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
from langfuse._utils.prompt_cache import PromptCache
8181
from langfuse.api import (
8282
CreateChatPromptRequest,
83+
CreateChatPromptType,
8384
CreateTextPromptRequest,
8485
Dataset,
8586
DatasetItem,
@@ -3710,7 +3711,7 @@ def create_prompt(
37103711
tags=tags,
37113712
config=config or {},
37123713
commit_message=commit_message,
3713-
type="chat",
3714+
type=CreateChatPromptType.CHAT,
37143715
)
37153716
)
37163717
server_prompt = self.api.prompts.create(request=request)

langfuse/api/.fern/metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"generatorName": "fernapi/fern-python-sdk",
44
"generatorVersion": "4.46.2",
55
"generatorConfig": {
6+
"pydantic_config": {
7+
"enum_type": "python_enums"
8+
},
69
"client": {
710
"class_name": "LangfuseAPI"
811
}

langfuse/api/annotation_queues/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def create_queue_item(
313313
Examples
314314
--------
315315
from langfuse import LangfuseAPI
316+
from langfuse.annotation_queues import AnnotationQueueObjectType
316317
317318
client = LangfuseAPI(
318319
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -325,7 +326,7 @@ def create_queue_item(
325326
client.annotation_queues.create_queue_item(
326327
queue_id="queueId",
327328
object_id="objectId",
328-
object_type="TRACE",
329+
object_type=AnnotationQueueObjectType.TRACE,
329330
)
330331
"""
331332
_response = self._raw_client.create_queue_item(
@@ -857,6 +858,7 @@ async def create_queue_item(
857858
import asyncio
858859
859860
from langfuse import AsyncLangfuseAPI
861+
from langfuse.annotation_queues import AnnotationQueueObjectType
860862
861863
client = AsyncLangfuseAPI(
862864
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -872,7 +874,7 @@ async def main() -> None:
872874
await client.annotation_queues.create_queue_item(
873875
queue_id="queueId",
874876
object_id="objectId",
875-
object_type="TRACE",
877+
object_type=AnnotationQueueObjectType.TRACE,
876878
)
877879
878880

langfuse/api/annotation_queues/types/annotation_queue_object_type.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
import typing
44

5-
AnnotationQueueObjectType = typing.Union[
6-
typing.Literal["TRACE", "OBSERVATION", "SESSION"], typing.Any
7-
]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class AnnotationQueueObjectType(enum.StrEnum):
11+
TRACE = "TRACE"
12+
OBSERVATION = "OBSERVATION"
13+
SESSION = "SESSION"
14+
15+
def visit(
16+
self,
17+
trace: typing.Callable[[], T_Result],
18+
observation: typing.Callable[[], T_Result],
19+
session: typing.Callable[[], T_Result],
20+
) -> T_Result:
21+
if self is AnnotationQueueObjectType.TRACE:
22+
return trace()
23+
if self is AnnotationQueueObjectType.OBSERVATION:
24+
return observation()
25+
if self is AnnotationQueueObjectType.SESSION:
26+
return session()

langfuse/api/annotation_queues/types/annotation_queue_status.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,21 @@
22

33
import typing
44

5-
AnnotationQueueStatus = typing.Union[typing.Literal["PENDING", "COMPLETED"], typing.Any]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class AnnotationQueueStatus(enum.StrEnum):
11+
PENDING = "PENDING"
12+
COMPLETED = "COMPLETED"
13+
14+
def visit(
15+
self,
16+
pending: typing.Callable[[], T_Result],
17+
completed: typing.Callable[[], T_Result],
18+
) -> T_Result:
19+
if self is AnnotationQueueStatus.PENDING:
20+
return pending()
21+
if self is AnnotationQueueStatus.COMPLETED:
22+
return completed()

langfuse/api/blob_storage_integrations/client.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ def upsert_blob_storage_integration(
146146
Examples
147147
--------
148148
from langfuse import LangfuseAPI
149+
from langfuse.blob_storage_integrations import (
150+
BlobStorageExportFrequency,
151+
BlobStorageExportMode,
152+
BlobStorageIntegrationFileType,
153+
BlobStorageIntegrationType,
154+
)
149155
150156
client = LangfuseAPI(
151157
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -157,14 +163,14 @@ def upsert_blob_storage_integration(
157163
)
158164
client.blob_storage_integrations.upsert_blob_storage_integration(
159165
project_id="projectId",
160-
type="S3",
166+
type=BlobStorageIntegrationType.S3,
161167
bucket_name="bucketName",
162168
region="region",
163-
export_frequency="hourly",
169+
export_frequency=BlobStorageExportFrequency.HOURLY,
164170
enabled=True,
165171
force_path_style=True,
166-
file_type="JSON",
167-
export_mode="FULL_HISTORY",
172+
file_type=BlobStorageIntegrationFileType.JSON,
173+
export_mode=BlobStorageExportMode.FULL_HISTORY,
168174
)
169175
"""
170176
_response = self._raw_client.upsert_blob_storage_integration(
@@ -358,6 +364,12 @@ async def upsert_blob_storage_integration(
358364
import asyncio
359365
360366
from langfuse import AsyncLangfuseAPI
367+
from langfuse.blob_storage_integrations import (
368+
BlobStorageExportFrequency,
369+
BlobStorageExportMode,
370+
BlobStorageIntegrationFileType,
371+
BlobStorageIntegrationType,
372+
)
361373
362374
client = AsyncLangfuseAPI(
363375
x_langfuse_sdk_name="YOUR_X_LANGFUSE_SDK_NAME",
@@ -372,14 +384,14 @@ async def upsert_blob_storage_integration(
372384
async def main() -> None:
373385
await client.blob_storage_integrations.upsert_blob_storage_integration(
374386
project_id="projectId",
375-
type="S3",
387+
type=BlobStorageIntegrationType.S3,
376388
bucket_name="bucketName",
377389
region="region",
378-
export_frequency="hourly",
390+
export_frequency=BlobStorageExportFrequency.HOURLY,
379391
enabled=True,
380392
force_path_style=True,
381-
file_type="JSON",
382-
export_mode="FULL_HISTORY",
393+
file_type=BlobStorageIntegrationFileType.JSON,
394+
export_mode=BlobStorageExportMode.FULL_HISTORY,
383395
)
384396
385397

langfuse/api/blob_storage_integrations/types/blob_storage_export_frequency.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
import typing
44

5-
BlobStorageExportFrequency = typing.Union[
6-
typing.Literal["hourly", "daily", "weekly"], typing.Any
7-
]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class BlobStorageExportFrequency(enum.StrEnum):
11+
HOURLY = "hourly"
12+
DAILY = "daily"
13+
WEEKLY = "weekly"
14+
15+
def visit(
16+
self,
17+
hourly: typing.Callable[[], T_Result],
18+
daily: typing.Callable[[], T_Result],
19+
weekly: typing.Callable[[], T_Result],
20+
) -> T_Result:
21+
if self is BlobStorageExportFrequency.HOURLY:
22+
return hourly()
23+
if self is BlobStorageExportFrequency.DAILY:
24+
return daily()
25+
if self is BlobStorageExportFrequency.WEEKLY:
26+
return weekly()

langfuse/api/blob_storage_integrations/types/blob_storage_export_mode.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
import typing
44

5-
BlobStorageExportMode = typing.Union[
6-
typing.Literal["FULL_HISTORY", "FROM_TODAY", "FROM_CUSTOM_DATE"], typing.Any
7-
]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class BlobStorageExportMode(enum.StrEnum):
11+
FULL_HISTORY = "FULL_HISTORY"
12+
FROM_TODAY = "FROM_TODAY"
13+
FROM_CUSTOM_DATE = "FROM_CUSTOM_DATE"
14+
15+
def visit(
16+
self,
17+
full_history: typing.Callable[[], T_Result],
18+
from_today: typing.Callable[[], T_Result],
19+
from_custom_date: typing.Callable[[], T_Result],
20+
) -> T_Result:
21+
if self is BlobStorageExportMode.FULL_HISTORY:
22+
return full_history()
23+
if self is BlobStorageExportMode.FROM_TODAY:
24+
return from_today()
25+
if self is BlobStorageExportMode.FROM_CUSTOM_DATE:
26+
return from_custom_date()

langfuse/api/blob_storage_integrations/types/blob_storage_integration_file_type.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
import typing
44

5-
BlobStorageIntegrationFileType = typing.Union[
6-
typing.Literal["JSON", "CSV", "JSONL"], typing.Any
7-
]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class BlobStorageIntegrationFileType(enum.StrEnum):
11+
JSON = "JSON"
12+
CSV = "CSV"
13+
JSONL = "JSONL"
14+
15+
def visit(
16+
self,
17+
json: typing.Callable[[], T_Result],
18+
csv: typing.Callable[[], T_Result],
19+
jsonl: typing.Callable[[], T_Result],
20+
) -> T_Result:
21+
if self is BlobStorageIntegrationFileType.JSON:
22+
return json()
23+
if self is BlobStorageIntegrationFileType.CSV:
24+
return csv()
25+
if self is BlobStorageIntegrationFileType.JSONL:
26+
return jsonl()

langfuse/api/blob_storage_integrations/types/blob_storage_integration_type.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
import typing
44

5-
BlobStorageIntegrationType = typing.Union[
6-
typing.Literal["S3", "S3_COMPATIBLE", "AZURE_BLOB_STORAGE"], typing.Any
7-
]
5+
from ...core import enum
6+
7+
T_Result = typing.TypeVar("T_Result")
8+
9+
10+
class BlobStorageIntegrationType(enum.StrEnum):
11+
S3 = "S3"
12+
S3COMPATIBLE = "S3_COMPATIBLE"
13+
AZURE_BLOB_STORAGE = "AZURE_BLOB_STORAGE"
14+
15+
def visit(
16+
self,
17+
s3: typing.Callable[[], T_Result],
18+
s3compatible: typing.Callable[[], T_Result],
19+
azure_blob_storage: typing.Callable[[], T_Result],
20+
) -> T_Result:
21+
if self is BlobStorageIntegrationType.S3:
22+
return s3()
23+
if self is BlobStorageIntegrationType.S3COMPATIBLE:
24+
return s3compatible()
25+
if self is BlobStorageIntegrationType.AZURE_BLOB_STORAGE:
26+
return azure_blob_storage()

0 commit comments

Comments
 (0)