Skip to content

Commit 66f02cb

Browse files
authored
fix(cost-tracking): handle none values in OpenAI schema (#1152)
1 parent 842acc9 commit 66f02cb

19 files changed

+2250
-19
lines changed

langfuse/api/README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pip install langfuse
1616
Instantiate and use the client with the following:
1717

1818
```python
19-
from langfuse import CreateCommentRequest
19+
from langfuse import AnnotationQueueObjectType, CreateAnnotationQueueItemRequest
2020
from langfuse.client import FernLangfuse
2121

2222
client = FernLangfuse(
@@ -27,12 +27,11 @@ client = FernLangfuse(
2727
password="YOUR_PASSWORD",
2828
base_url="https://yourhost.com/path/to/api",
2929
)
30-
client.comments.create(
31-
request=CreateCommentRequest(
32-
project_id="projectId",
33-
object_type="objectType",
30+
client.annotation_queues.create_queue_item(
31+
queue_id="queueId",
32+
request=CreateAnnotationQueueItemRequest(
3433
object_id="objectId",
35-
content="content",
34+
object_type=AnnotationQueueObjectType.TRACE,
3635
),
3736
)
3837
```
@@ -44,7 +43,7 @@ The SDK also exports an `async` client so that you can make non-blocking calls t
4443
```python
4544
import asyncio
4645

47-
from langfuse import CreateCommentRequest
46+
from langfuse import AnnotationQueueObjectType, CreateAnnotationQueueItemRequest
4847
from langfuse.client import AsyncFernLangfuse
4948

5049
client = AsyncFernLangfuse(
@@ -58,12 +57,11 @@ client = AsyncFernLangfuse(
5857

5958

6059
async def main() -> None:
61-
await client.comments.create(
62-
request=CreateCommentRequest(
63-
project_id="projectId",
64-
object_type="objectType",
60+
await client.annotation_queues.create_queue_item(
61+
queue_id="queueId",
62+
request=CreateAnnotationQueueItemRequest(
6563
object_id="objectId",
66-
content="content",
64+
object_type=AnnotationQueueObjectType.TRACE,
6765
),
6866
)
6967

@@ -80,7 +78,7 @@ will be thrown.
8078
from .api_error import ApiError
8179

8280
try:
83-
client.comments.create(...)
81+
client.annotation_queues.create_queue_item(...)
8482
except ApiError as e:
8583
print(e.status_code)
8684
print(e.body)
@@ -103,7 +101,7 @@ A request is deemed retriable when any of the following HTTP status codes is ret
103101
Use the `max_retries` request option to configure this behavior.
104102

105103
```python
106-
client.comments.create(...,{
104+
client.annotation_queues.create_queue_item(...,{
107105
max_retries=1
108106
})
109107
```
@@ -120,7 +118,7 @@ client = FernLangfuse(..., { timeout=20.0 }, )
120118

121119

122120
# Override timeout for a specific method
123-
client.comments.create(...,{
121+
client.annotation_queues.create_queue_item(...,{
124122
timeout_in_seconds=1
125123
})
126124
```

langfuse/api/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
from .resources import (
44
AccessDeniedError,
5+
AnnotationQueue,
6+
AnnotationQueueItem,
7+
AnnotationQueueObjectType,
8+
AnnotationQueueStatus,
59
BaseEvent,
610
BasePrompt,
711
BaseScore,
@@ -12,6 +16,7 @@
1216
Comment,
1317
CommentObjectType,
1418
ConfigCategory,
19+
CreateAnnotationQueueItemRequest,
1520
CreateChatPromptRequest,
1621
CreateCommentRequest,
1722
CreateCommentResponse,
@@ -42,6 +47,7 @@
4247
DatasetRunItem,
4348
DatasetRunWithItems,
4449
DatasetStatus,
50+
DeleteAnnotationQueueItemResponse,
4551
DeleteDatasetItemResponse,
4652
DeleteDatasetRunResponse,
4753
DeleteTraceResponse,
@@ -93,6 +99,8 @@
9399
OpenAiResponseUsageSchema,
94100
OpenAiUsage,
95101
OptionalObservationBody,
102+
PaginatedAnnotationQueueItems,
103+
PaginatedAnnotationQueues,
96104
PaginatedDatasetItems,
97105
PaginatedDatasetRuns,
98106
PaginatedDatasets,
@@ -130,6 +138,7 @@
130138
TraceWithFullDetails,
131139
Traces,
132140
UnauthorizedError,
141+
UpdateAnnotationQueueItemRequest,
133142
UpdateEventBody,
134143
UpdateGenerationBody,
135144
UpdateGenerationEvent,
@@ -139,6 +148,7 @@
139148
Usage,
140149
UsageByModel,
141150
UsageDetails,
151+
annotation_queues,
142152
comments,
143153
commons,
144154
dataset_items,
@@ -162,6 +172,10 @@
162172

163173
__all__ = [
164174
"AccessDeniedError",
175+
"AnnotationQueue",
176+
"AnnotationQueueItem",
177+
"AnnotationQueueObjectType",
178+
"AnnotationQueueStatus",
165179
"BaseEvent",
166180
"BasePrompt",
167181
"BaseScore",
@@ -172,6 +186,7 @@
172186
"Comment",
173187
"CommentObjectType",
174188
"ConfigCategory",
189+
"CreateAnnotationQueueItemRequest",
175190
"CreateChatPromptRequest",
176191
"CreateCommentRequest",
177192
"CreateCommentResponse",
@@ -202,6 +217,7 @@
202217
"DatasetRunItem",
203218
"DatasetRunWithItems",
204219
"DatasetStatus",
220+
"DeleteAnnotationQueueItemResponse",
205221
"DeleteDatasetItemResponse",
206222
"DeleteDatasetRunResponse",
207223
"DeleteTraceResponse",
@@ -253,6 +269,8 @@
253269
"OpenAiResponseUsageSchema",
254270
"OpenAiUsage",
255271
"OptionalObservationBody",
272+
"PaginatedAnnotationQueueItems",
273+
"PaginatedAnnotationQueues",
256274
"PaginatedDatasetItems",
257275
"PaginatedDatasetRuns",
258276
"PaginatedDatasets",
@@ -290,6 +308,7 @@
290308
"TraceWithFullDetails",
291309
"Traces",
292310
"UnauthorizedError",
311+
"UpdateAnnotationQueueItemRequest",
293312
"UpdateEventBody",
294313
"UpdateGenerationBody",
295314
"UpdateGenerationEvent",
@@ -299,6 +318,7 @@
299318
"Usage",
300319
"UsageByModel",
301320
"UsageDetails",
321+
"annotation_queues",
302322
"comments",
303323
"commons",
304324
"dataset_items",

langfuse/api/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import httpx
66

77
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
8+
from .resources.annotation_queues.client import (
9+
AnnotationQueuesClient,
10+
AsyncAnnotationQueuesClient,
11+
)
812
from .resources.comments.client import AsyncCommentsClient, CommentsClient
913
from .resources.dataset_items.client import AsyncDatasetItemsClient, DatasetItemsClient
1014
from .resources.dataset_run_items.client import (
@@ -99,6 +103,9 @@ def __init__(
99103
else httpx.Client(timeout=_defaulted_timeout),
100104
timeout=_defaulted_timeout,
101105
)
106+
self.annotation_queues = AnnotationQueuesClient(
107+
client_wrapper=self._client_wrapper
108+
)
102109
self.comments = CommentsClient(client_wrapper=self._client_wrapper)
103110
self.dataset_items = DatasetItemsClient(client_wrapper=self._client_wrapper)
104111
self.dataset_run_items = DatasetRunItemsClient(
@@ -189,6 +196,9 @@ def __init__(
189196
else httpx.AsyncClient(timeout=_defaulted_timeout),
190197
timeout=_defaulted_timeout,
191198
)
199+
self.annotation_queues = AsyncAnnotationQueuesClient(
200+
client_wrapper=self._client_wrapper
201+
)
192202
self.comments = AsyncCommentsClient(client_wrapper=self._client_wrapper)
193203
self.dataset_items = AsyncDatasetItemsClient(
194204
client_wrapper=self._client_wrapper

0 commit comments

Comments
 (0)