Skip to content

Commit d7e77c0

Browse files
feat(api): api update
1 parent 06ad2b1 commit d7e77c0

File tree

10 files changed

+66
-33
lines changed

10 files changed

+66
-33
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 9
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lemma%2Flemma-871ffb9ecbbea62ed720017145c0bae1900d5a75d426bc34a9e192d22c94c86d.yml
3-
openapi_spec_hash: c1108108d12010a663c600436bf0d24d
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/lemma%2Flemma-9229b0c13c7281e2bf2698cb517be411c7a19790066dd9b8f5fe2803b2b4c6c7.yml
3+
openapi_spec_hash: c5017ef051af46ea4b2d9817e54f6657
44
config_hash: 017a31b2ac0856f4d4152a5173e6fa18

src/lemma/resources/datasets/datasets.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
from __future__ import annotations
44

5-
from typing import Dict, Optional
5+
from typing import Dict, Mapping, Optional, cast
66

77
import httpx
88

99
from ...types import dataset_generate_schema_params, dataset_generate_dataset_params, dataset_generate_validators_params
1010
from ..._types import Body, Omit, Query, Headers, NotGiven, FileTypes, omit, not_given
11-
from ..._utils import maybe_transform, async_maybe_transform
11+
from ..._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
1212
from ..._compat import cached_property
1313
from ..._resource import SyncAPIResource, AsyncAPIResource
1414
from ..._response import (
@@ -137,10 +137,6 @@ def generate_schema(
137137
seed_description must be provided.
138138
139139
Args:
140-
seed_description: The seed description to generate a schema from
141-
142-
seed_file: The seed file to generate a schema from
143-
144140
extra_headers: Send extra headers
145141
146142
extra_query: Add additional query parameters to the request
@@ -149,15 +145,21 @@ def generate_schema(
149145
150146
timeout: Override the client-level default timeout for this request, in seconds
151147
"""
148+
body = deepcopy_minimal(
149+
{
150+
"seed_description": seed_description,
151+
"seed_file": seed_file,
152+
}
153+
)
154+
files = extract_files(cast(Mapping[str, object], body), paths=[["seed_file"]])
155+
# It should be noted that the actual Content-Type header that will be
156+
# sent to the server will contain a `boundary` parameter, e.g.
157+
# multipart/form-data; boundary=---abc--
158+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
152159
return self._post(
153160
"/datasets/generate-schema",
154-
body=maybe_transform(
155-
{
156-
"seed_description": seed_description,
157-
"seed_file": seed_file,
158-
},
159-
dataset_generate_schema_params.DatasetGenerateSchemaParams,
160-
),
161+
body=maybe_transform(body, dataset_generate_schema_params.DatasetGenerateSchemaParams),
162+
files=files,
161163
options=make_request_options(
162164
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
163165
),
@@ -316,10 +318,6 @@ async def generate_schema(
316318
seed_description must be provided.
317319
318320
Args:
319-
seed_description: The seed description to generate a schema from
320-
321-
seed_file: The seed file to generate a schema from
322-
323321
extra_headers: Send extra headers
324322
325323
extra_query: Add additional query parameters to the request
@@ -328,15 +326,21 @@ async def generate_schema(
328326
329327
timeout: Override the client-level default timeout for this request, in seconds
330328
"""
329+
body = deepcopy_minimal(
330+
{
331+
"seed_description": seed_description,
332+
"seed_file": seed_file,
333+
}
334+
)
335+
files = extract_files(cast(Mapping[str, object], body), paths=[["seed_file"]])
336+
# It should be noted that the actual Content-Type header that will be
337+
# sent to the server will contain a `boundary` parameter, e.g.
338+
# multipart/form-data; boundary=---abc--
339+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
331340
return await self._post(
332341
"/datasets/generate-schema",
333-
body=await async_maybe_transform(
334-
{
335-
"seed_description": seed_description,
336-
"seed_file": seed_file,
337-
},
338-
dataset_generate_schema_params.DatasetGenerateSchemaParams,
339-
),
342+
body=await async_maybe_transform(body, dataset_generate_schema_params.DatasetGenerateSchemaParams),
343+
files=files,
340344
options=make_request_options(
341345
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
342346
),

src/lemma/resources/logs.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def create(
5252
input_variables: Dict[str, object],
5353
model: str,
5454
output: str,
55+
project_id: str,
5556
prompt_id: str,
5657
prompt_template: str,
5758
prompt_tokens: int,
@@ -67,7 +68,9 @@ def create(
6768
Create a new log entry.
6869
6970
Creates a new log entry to track events, activities, or API usage. Logs are
70-
associated with the current tenant.
71+
associated with the current tenant and project. If the prompt referenced by the
72+
log doesn't exist, it will be automatically created using the prompt template as
73+
the seed content.
7174
7275
Args:
7376
completion_tokens: Number of tokens in the completion
@@ -78,6 +81,8 @@ def create(
7881
7982
output: Output generated by the model
8083
84+
project_id: ID of the project this log belongs to
85+
8186
prompt_id: ID of the prompt used
8287
8388
prompt_template: Template used for the prompt
@@ -102,6 +107,7 @@ def create(
102107
"input_variables": input_variables,
103108
"model": model,
104109
"output": output,
110+
"project_id": project_id,
105111
"prompt_id": prompt_id,
106112
"prompt_template": prompt_template,
107113
"prompt_tokens": prompt_tokens,
@@ -228,6 +234,7 @@ async def create(
228234
input_variables: Dict[str, object],
229235
model: str,
230236
output: str,
237+
project_id: str,
231238
prompt_id: str,
232239
prompt_template: str,
233240
prompt_tokens: int,
@@ -243,7 +250,9 @@ async def create(
243250
Create a new log entry.
244251
245252
Creates a new log entry to track events, activities, or API usage. Logs are
246-
associated with the current tenant.
253+
associated with the current tenant and project. If the prompt referenced by the
254+
log doesn't exist, it will be automatically created using the prompt template as
255+
the seed content.
247256
248257
Args:
249258
completion_tokens: Number of tokens in the completion
@@ -254,6 +263,8 @@ async def create(
254263
255264
output: Output generated by the model
256265
266+
project_id: ID of the project this log belongs to
267+
257268
prompt_id: ID of the prompt used
258269
259270
prompt_template: Template used for the prompt
@@ -278,6 +289,7 @@ async def create(
278289
"input_variables": input_variables,
279290
"model": model,
280291
"output": output,
292+
"project_id": project_id,
281293
"prompt_id": prompt_id,
282294
"prompt_template": prompt_template,
283295
"prompt_tokens": prompt_tokens,

src/lemma/types/dataset_generate_schema_params.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,5 @@
1212

1313
class DatasetGenerateSchemaParams(TypedDict, total=False):
1414
seed_description: Optional[str]
15-
"""The seed description to generate a schema from"""
1615

1716
seed_file: Optional[FileTypes]
18-
"""The seed file to generate a schema from"""
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
from typing import Optional
3+
from typing import Dict
44

55
from pydantic import Field as FieldInfo
66

@@ -10,4 +10,5 @@
1010

1111

1212
class DatasetGenerateSchemaResponse(BaseModel):
13-
schema_: Optional[str] = FieldInfo(alias="schema", default=None)
13+
schema_: Dict[str, object] = FieldInfo(alias="schema")
14+
"""A valid JSON Schema object that describes the structure of the data"""
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3+
from typing import List
4+
35
from .._models import BaseModel
46

57
__all__ = ["DatasetGenerateValidatorsResponse"]
68

79

810
class DatasetGenerateValidatorsResponse(BaseModel):
9-
validators: str
11+
validators: List[str]
12+
"""List of CEL validation expressions, one per item"""

src/lemma/types/log.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class Log(BaseModel):
2222
output: str
2323
"""Output generated by the model"""
2424

25+
project_id: str = FieldInfo(alias="projectId")
26+
"""ID of the project this log belongs to"""
27+
2528
prompt_id: str = FieldInfo(alias="promptId")
2629
"""ID of the prompt used"""
2730

src/lemma/types/log_create_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class LogCreateParams(TypedDict, total=False):
2323
output: Required[str]
2424
"""Output generated by the model"""
2525

26+
project_id: Required[Annotated[str, PropertyInfo(alias="projectId")]]
27+
"""ID of the project this log belongs to"""
28+
2629
prompt_id: Required[Annotated[str, PropertyInfo(alias="promptId")]]
2730
"""ID of the prompt used"""
2831

src/lemma/types/log_retrieve_response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class LogRetrieveResponse(BaseModel):
2323
output: str
2424
"""Output generated by the model"""
2525

26+
project_id: str = FieldInfo(alias="projectId")
27+
"""ID of the project this log belongs to"""
28+
2629
prompt_id: str = FieldInfo(alias="promptId")
2730
"""ID of the prompt used"""
2831

tests/api_resources/test_logs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_method_create(self, client: Lemma) -> None:
2525
input_variables={"foo": "bar"},
2626
model="model",
2727
output="output",
28+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
2829
prompt_id="promptId",
2930
prompt_template="promptTemplate",
3031
prompt_tokens=0,
@@ -40,6 +41,7 @@ def test_raw_response_create(self, client: Lemma) -> None:
4041
input_variables={"foo": "bar"},
4142
model="model",
4243
output="output",
44+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
4345
prompt_id="promptId",
4446
prompt_template="promptTemplate",
4547
prompt_tokens=0,
@@ -59,6 +61,7 @@ def test_streaming_response_create(self, client: Lemma) -> None:
5961
input_variables={"foo": "bar"},
6062
model="model",
6163
output="output",
64+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
6265
prompt_id="promptId",
6366
prompt_template="promptTemplate",
6467
prompt_tokens=0,
@@ -165,6 +168,7 @@ async def test_method_create(self, async_client: AsyncLemma) -> None:
165168
input_variables={"foo": "bar"},
166169
model="model",
167170
output="output",
171+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
168172
prompt_id="promptId",
169173
prompt_template="promptTemplate",
170174
prompt_tokens=0,
@@ -180,6 +184,7 @@ async def test_raw_response_create(self, async_client: AsyncLemma) -> None:
180184
input_variables={"foo": "bar"},
181185
model="model",
182186
output="output",
187+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
183188
prompt_id="promptId",
184189
prompt_template="promptTemplate",
185190
prompt_tokens=0,
@@ -199,6 +204,7 @@ async def test_streaming_response_create(self, async_client: AsyncLemma) -> None
199204
input_variables={"foo": "bar"},
200205
model="model",
201206
output="output",
207+
project_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
202208
prompt_id="promptId",
203209
prompt_template="promptTemplate",
204210
prompt_tokens=0,

0 commit comments

Comments
 (0)